-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds decorate option to wrap existing spring rabbit components (#636)
- Loading branch information
1 parent
539422e
commit dcdfa1c
Showing
4 changed files
with
240 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
instrumentation/spring-rabbit/src/test/java/brave/spring/rabbit/SpringRabbitTracingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package brave.spring.rabbit; | ||
|
||
import brave.Tracing; | ||
import brave.sampler.Sampler; | ||
import org.junit.After; | ||
import org.junit.Test; | ||
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.amqp.support.postprocessor.UnzipPostProcessor; | ||
import org.springframework.cache.interceptor.CacheInterceptor; | ||
import zipkin2.reporter.Reporter; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.assertj.core.api.Java6Assertions.assertThat; | ||
|
||
public class SpringRabbitTracingTest { | ||
SpringRabbitTracing tracing = SpringRabbitTracing.create(Tracing.newBuilder() | ||
.sampler(Sampler.ALWAYS_SAMPLE) | ||
.spanReporter(Reporter.NOOP) | ||
.build()); | ||
|
||
@After public void close() { | ||
Tracing.current().close(); | ||
} | ||
|
||
@Test public void decorateRabbitTemplate_adds_by_default() { | ||
RabbitTemplate template = new RabbitTemplate(); | ||
assertThat(tracing.decorateRabbitTemplate(template)) | ||
.extracting("beforePublishPostProcessors") | ||
.containsExactly(asList(tracing.tracingMessagePostProcessor)); | ||
} | ||
|
||
@Test public void decorateRabbitTemplate_skips_when_present() { | ||
RabbitTemplate template = new RabbitTemplate(); | ||
template.setBeforePublishPostProcessors(tracing.tracingMessagePostProcessor); | ||
|
||
assertThat(tracing.decorateRabbitTemplate(template)) | ||
.extracting("beforePublishPostProcessors") | ||
.containsExactly(asList(tracing.tracingMessagePostProcessor)); | ||
} | ||
|
||
@Test public void decorateRabbitTemplate_appends_when_absent() { | ||
RabbitTemplate template = new RabbitTemplate(); | ||
UnzipPostProcessor postProcessor = new UnzipPostProcessor(); | ||
template.setBeforePublishPostProcessors(postProcessor); | ||
|
||
assertThat(tracing.decorateRabbitTemplate(template)) | ||
.extracting("beforePublishPostProcessors") | ||
.containsExactly(asList(postProcessor, tracing.tracingMessagePostProcessor)); | ||
} | ||
|
||
@Test public void decorateSimpleRabbitListenerContainerFactory_adds_by_default() { | ||
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | ||
|
||
assertThat(tracing.decorateSimpleRabbitListenerContainerFactory(factory).getAdviceChain()) | ||
.containsExactly(tracing.tracingRabbitListenerAdvice); | ||
} | ||
|
||
@Test public void decorateSimpleRabbitListenerContainerFactory_skips_when_present() { | ||
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | ||
factory.setAdviceChain(tracing.tracingRabbitListenerAdvice); | ||
|
||
assertThat(tracing.decorateSimpleRabbitListenerContainerFactory(factory).getAdviceChain()) | ||
.containsExactly(tracing.tracingRabbitListenerAdvice); | ||
} | ||
|
||
@Test public void decorateSimpleRabbitListenerContainerFactory_appends_when_absent() { | ||
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | ||
CacheInterceptor advice = new CacheInterceptor(); | ||
factory.setAdviceChain(advice); | ||
|
||
assertThat(tracing.decorateSimpleRabbitListenerContainerFactory(factory).getAdviceChain()) | ||
.containsExactly(advice, tracing.tracingRabbitListenerAdvice); | ||
} | ||
} |