我将Brave用作Spring Slueth(Spring Cloud-Edgware.RELEASE)的一部分。我编写了一个过滤器,该过滤器可拦截每个请求并在Zipkin中创建一个Span(标记/名称)。例如:
//Imports
import brave.Span;
import brave.Tracer;
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
Span someSpan = tracer.nextSpan();
someSpan.kind(Span.Kind.SERVER);
someSpan.name("my-test-span");
someSpan.tag("Env", "Dev");
//Do some Filter specific operation ......
someSpan.finish();
}
现在,我想编写测试用例,但是我不确定如何在Servlet过滤器中模拟Span或tracer?
POM片段:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth</artifactId>
<version>2.0.3.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>