From c3ac8f570ff667fc93b44f674aa51737fbbcd7ee Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 31 Dec 2015 15:26:35 +0000 Subject: [PATCH] Test for null in StreamSpanListener A span can have a null name so we need to guard against it explicitly. --- .../cloud/sleuth/stream/StreamSpanListener.java | 2 +- .../sleuth/stream/StreamSpanListenerTests.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spring-cloud-sleuth-stream/src/main/java/org/springframework/cloud/sleuth/stream/StreamSpanListener.java b/spring-cloud-sleuth-stream/src/main/java/org/springframework/cloud/sleuth/stream/StreamSpanListener.java index 58feeba3c..85987b56b 100644 --- a/spring-cloud-sleuth-stream/src/main/java/org/springframework/cloud/sleuth/stream/StreamSpanListener.java +++ b/spring-cloud-sleuth-stream/src/main/java/org/springframework/cloud/sleuth/stream/StreamSpanListener.java @@ -106,7 +106,7 @@ public class StreamSpanListener { this.queue.clear(); for (Iterator iterator = result.iterator(); iterator.hasNext();) { Span span = iterator.next(); - if (span.getName().equals("message/zipkin")) { + if (span.getName() != null && span.getName().equals("message/zipkin")) { iterator.remove(); } } 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 5066f22d2..08280bfcf 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 @@ -68,6 +68,9 @@ public class StreamSpanListenerTests { @Autowired private ZipkinTestConfiguration test; + @Autowired + StreamSpanListener listener; + @PostConstruct public void init() { this.test.spans.clear(); @@ -95,6 +98,16 @@ public class StreamSpanListenerTests { assertEquals(2, this.test.spans.size()); } + @Test + public void nullSpanName() { + Trace context = this.traceManager.startSpan(null, null); + this.application.publishEvent(new ClientSentEvent(this, context.getSpan())); + this.traceManager.close(context); + assertEquals(1, this.test.spans.size()); + this.listener.poll(); + assertEquals(0, this.test.spans.size()); + } + @Configuration @Import({ ZipkinTestConfiguration.class, SleuthStreamAutoConfiguration.class, TestSupportBinderAutoConfiguration.class, ChannelBindingAutoConfiguration.class, @@ -110,7 +123,7 @@ public class StreamSpanListenerTests { @Autowired StreamSpanListener listener; - + @ServiceActivator(inputChannel=SleuthSource.OUTPUT) public void handle(Message msg) { }