From 34dfb68a827a8f2e039a184847b09e88ab1dd37f Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Tue, 28 Feb 2017 10:28:00 +0100 Subject: [PATCH] Yet another try with flickering tests --- .../sleuth/stream/StreamSpanReporter.java | 3 ++ .../stream/StreamSpanListenerTests.java | 35 ++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/spring-cloud-sleuth-stream/src/main/java/org/springframework/cloud/sleuth/stream/StreamSpanReporter.java b/spring-cloud-sleuth-stream/src/main/java/org/springframework/cloud/sleuth/stream/StreamSpanReporter.java index 82199b541..49cb847f8 100644 --- a/spring-cloud-sleuth-stream/src/main/java/org/springframework/cloud/sleuth/stream/StreamSpanReporter.java +++ b/spring-cloud-sleuth-stream/src/main/java/org/springframework/cloud/sleuth/stream/StreamSpanReporter.java @@ -92,6 +92,9 @@ public class StreamSpanReporter implements SpanReporter { if (result.isEmpty()) { return null; } + if (log.isDebugEnabled()) { + log.debug("Processed [" + result.size() + "] spans"); + } this.spanMetricReporter.incrementAcceptedSpans(result.size()); return new Spans(this.endpointLocator.locate(result.get(0)), result); } diff --git a/spring-cloud-sleuth-stream/src/test/java/org/springframework/cloud/sleuth/stream/StreamSpanListenerTests.java b/spring-cloud-sleuth-stream/src/test/java/org/springframework/cloud/sleuth/stream/StreamSpanListenerTests.java index f5cea7364..60afa4341 100644 --- a/spring-cloud-sleuth-stream/src/test/java/org/springframework/cloud/sleuth/stream/StreamSpanListenerTests.java +++ b/spring-cloud-sleuth-stream/src/test/java/org/springframework/cloud/sleuth/stream/StreamSpanListenerTests.java @@ -22,11 +22,13 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.verify; +import java.util.Collection; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import javax.annotation.PostConstruct; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @@ -80,9 +82,18 @@ public class StreamSpanListenerTests { @Autowired SpanReporter spanReporter; - @PostConstruct + @Before public void init() { - this.test.spans.clear(); + this.test.clear(); + } + + @Test + public void acquireAndRelease() { + Span context = this.tracer.createSpan("http:foo"); + + this.tracer.close(context); + + Awaitility.await().until(() -> assertThat(StreamSpanListenerTests.this.test.spans()).hasSize(1)); } @Test @@ -96,7 +107,7 @@ public class StreamSpanListenerTests { this.tracer.close(context); - Awaitility.await().until(() -> assertThat(StreamSpanListenerTests.this.test.spans).hasSize(2)); + Awaitility.await().until(() -> assertThat(StreamSpanListenerTests.this.test.spans()).hasSize(2)); } void logServerReceived(Span parent) { @@ -161,7 +172,23 @@ public class StreamSpanListenerTests { @MessageEndpoint protected static class ZipkinTestConfiguration { - private BlockingQueue spans = new LinkedBlockingQueue<>(); + private BlockingQueue copyOfSpans = new LinkedBlockingQueue<>(); + + private BlockingQueue spans = new LinkedBlockingQueue() { + @Override public int drainTo(Collection c) { + ZipkinTestConfiguration.this.copyOfSpans.addAll(this); + return super.drainTo(c); + } + }; + + void clear() { + this.spans.clear(); + this.copyOfSpans.clear(); + } + + BlockingQueue spans() { + return this.copyOfSpans; + } @Autowired StreamSpanReporter listener;