Mocking a Span in Unit Test case - Zipkin/brave
up vote
0
down vote
favorite
I am using Brave as part of Spring Slueth (Spring Cloud - Edgware.RELEASE). I have written a Filter that intercept every request and create a Span (tag/name) in Zipkin. For example:
//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();
Now, I would like to write test cases, but I am not sure how to mock Span or tracer within a Servlet Filter?
POM Snippet:
<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>
spring spring-boot zipkin
add a comment |
up vote
0
down vote
favorite
I am using Brave as part of Spring Slueth (Spring Cloud - Edgware.RELEASE). I have written a Filter that intercept every request and create a Span (tag/name) in Zipkin. For example:
//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();
Now, I would like to write test cases, but I am not sure how to mock Span or tracer within a Servlet Filter?
POM Snippet:
<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>
spring spring-boot zipkin
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am using Brave as part of Spring Slueth (Spring Cloud - Edgware.RELEASE). I have written a Filter that intercept every request and create a Span (tag/name) in Zipkin. For example:
//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();
Now, I would like to write test cases, but I am not sure how to mock Span or tracer within a Servlet Filter?
POM Snippet:
<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>
spring spring-boot zipkin
I am using Brave as part of Spring Slueth (Spring Cloud - Edgware.RELEASE). I have written a Filter that intercept every request and create a Span (tag/name) in Zipkin. For example:
//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();
Now, I would like to write test cases, but I am not sure how to mock Span or tracer within a Servlet Filter?
POM Snippet:
<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>
spring spring-boot zipkin
spring spring-boot zipkin
edited Nov 9 at 11:15
asked Nov 9 at 10:45
user8479984
64
64
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224216%2fmocking-a-span-in-unit-test-case-zipkin-brave%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown