Trying to fix the flickering build

This commit is contained in:
Marcin Grzejszczak
2017-10-17 08:29:03 +02:00
parent 0673dc1eef
commit 558c7e2423

View File

@@ -15,6 +15,10 @@
*/ */
package integration; package integration;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.BDDAssertions.then;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -40,9 +44,6 @@ import tools.AbstractIntegrationTest;
import zipkin.Constants; import zipkin.Constants;
import zipkin.Span; import zipkin.Span;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = { IntegrationSpanCollectorConfig.class, SampleMessagingApplication.class }, @SpringBootTest(classes = { IntegrationSpanCollectorConfig.class, SampleMessagingApplication.class },
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@@ -102,14 +103,14 @@ public class MessagingApplicationTests extends AbstractIntegrationTest {
} }
private void thenThereIsAtLeastOneBinaryAnnotationWithKey(String binaryAnnotationKey) { private void thenThereIsAtLeastOneBinaryAnnotationWithKey(String binaryAnnotationKey) {
then(this.integrationTestSpanCollector.hashedSpans.stream() then(new ArrayList<>(this.integrationTestSpanCollector.hashedSpans).stream()
.map(s -> s.binaryAnnotations) .map(s -> s.binaryAnnotations)
.flatMap(Collection::stream) .flatMap(Collection::stream)
.anyMatch(b -> b.key.equals(binaryAnnotationKey))).isTrue(); .anyMatch(b -> b.key.equals(binaryAnnotationKey))).isTrue();
} }
private void thenAllSpansHaveTraceIdEqualTo(long traceId) { private void thenAllSpansHaveTraceIdEqualTo(long traceId) {
then(this.integrationTestSpanCollector.hashedSpans.stream() then(new ArrayList<>(this.integrationTestSpanCollector.hashedSpans).stream()
.allMatch(span -> span.traceId == traceId)).describedAs("All spans have same trace id").isTrue(); .allMatch(span -> span.traceId == traceId)).describedAs("All spans have same trace id").isTrue();
} }
@@ -120,53 +121,56 @@ public class MessagingApplicationTests extends AbstractIntegrationTest {
Optional<Span> eventReceivedSpan = findSpanWithAnnotation(Constants.CLIENT_RECV); Optional<Span> eventReceivedSpan = findSpanWithAnnotation(Constants.CLIENT_RECV);
Optional<Span> lastHttpSpansParent = findLastHttpSpansParent(); Optional<Span> lastHttpSpansParent = findLastHttpSpansParent();
// "http:/parent/" -> "message:messages" -> "http:/foo" (CS + CR) -> "http:/foo" (SS) // "http:/parent/" -> "message:messages" -> "http:/foo" (CS + CR) -> "http:/foo" (SS)
Collections.sort(this.integrationTestSpanCollector.hashedSpans); ArrayList<Span> spans = new ArrayList<>(
thenAllSpansArePresent(firstHttpSpan, eventSpans, lastHttpSpansParent, eventSentSpan, eventReceivedSpan); this.integrationTestSpanCollector.hashedSpans);
then(this.integrationTestSpanCollector.hashedSpans).as("There were 4 spans").hasSize(4); Collections.sort(spans);
thenAllSpansArePresent(spans, firstHttpSpan, eventSpans, lastHttpSpansParent, eventSentSpan, eventReceivedSpan);
then(spans).as("There were 4 spans").hasSize(4);
log.info("Checking the parent child structure"); log.info("Checking the parent child structure");
List<Optional<Span>> parentChild = this.integrationTestSpanCollector.hashedSpans.stream() List<Optional<Span>> parentChild = spans.stream()
.filter(span -> span.parentId != null) .filter(span -> span.parentId != null)
.map(span -> this.integrationTestSpanCollector.hashedSpans.stream().filter(span1 -> span1.id == span.parentId).findAny() .map(span -> spans.stream().filter(span1 -> span1.id == span.parentId).findAny()
).collect(Collectors.toList()); ).collect(Collectors.toList());
log.info("List of parents and children " + parentChild); log.info("List of parents and children " + parentChild);
then(parentChild.stream().allMatch(Optional::isPresent)).isTrue(); then(parentChild.stream().allMatch(Optional::isPresent)).isTrue();
} }
private Optional<Span> findLastHttpSpansParent() { private Optional<Span> findLastHttpSpansParent() {
return this.integrationTestSpanCollector.hashedSpans.stream() return new ArrayList<>(this.integrationTestSpanCollector.hashedSpans).stream()
.filter(span -> "http:/foo".equals(span.name) && !span.annotations.isEmpty()).findFirst(); .filter(span -> "http:/foo".equals(span.name) && !span.annotations.isEmpty()).findFirst();
} }
private Optional<Span> findSpanWithAnnotation(String annotationName) { private Optional<Span> findSpanWithAnnotation(String annotationName) {
return this.integrationTestSpanCollector.hashedSpans.stream() return new ArrayList<>(this.integrationTestSpanCollector.hashedSpans).stream()
.filter(span -> span.annotations.stream().filter(annotation -> annotationName .filter(span -> span.annotations.stream()
.filter(annotation -> annotationName
.equals(annotation.value)).findFirst().isPresent()) .equals(annotation.value)).findFirst().isPresent())
.findFirst(); .findFirst();
} }
private List<Span> findAllEventRelatedSpans() { private List<Span> findAllEventRelatedSpans() {
return this.integrationTestSpanCollector.hashedSpans.stream() return new ArrayList<>(this.integrationTestSpanCollector.hashedSpans).stream()
.filter(span -> "message:messages".equals(span.name) && span.parentId != null).collect( .filter(span -> "message:messages".equals(span.name) && span.parentId != null).collect(
Collectors.toList()); Collectors.toList());
} }
private Optional<Span> findFirstHttpRequestSpan() { private Optional<Span> findFirstHttpRequestSpan() {
return this.integrationTestSpanCollector.hashedSpans.stream() return new ArrayList<>(this.integrationTestSpanCollector.hashedSpans).stream()
// home is the name of the method // home is the name of the method
.filter(span -> span.binaryAnnotations.stream() .filter(span -> span.binaryAnnotations.stream()
.anyMatch(binaryAnnotation -> new String(binaryAnnotation.value).equals("home"))).findFirst(); .anyMatch(binaryAnnotation -> new String(binaryAnnotation.value).equals("home"))).findFirst();
} }
private void thenAllSpansArePresent(Optional<Span> firstHttpSpan, private void thenAllSpansArePresent(ArrayList<Span> spans, Optional<Span> firstHttpSpan,
List<Span> eventSpans, Optional<Span> lastHttpSpan, List<Span> eventSpans, Optional<Span> lastHttpSpan, Optional<Span> eventSentSpan,
Optional<Span> eventSentSpan, Optional<Span> eventReceivedSpan) { Optional<Span> eventReceivedSpan) {
log.info("Found following spans"); log.info("Found following spans");
log.info("First http span " + firstHttpSpan); log.info("First http span " + firstHttpSpan);
log.info("Event spans " + eventSpans); log.info("Event spans " + eventSpans);
log.info("Event sent span " + eventSentSpan); log.info("Event sent span " + eventSentSpan);
log.info("Event received span " + eventReceivedSpan); log.info("Event received span " + eventReceivedSpan);
log.info("Last http span " + lastHttpSpan); log.info("Last http span " + lastHttpSpan);
log.info("All found spans \n" + this.integrationTestSpanCollector.hashedSpans log.info("All found spans \n" + spans
.stream().map(Span::toString).collect(Collectors.joining("\n"))); .stream().map(Span::toString).collect(Collectors.joining("\n")));
then(firstHttpSpan.isPresent()).isTrue(); then(firstHttpSpan.isPresent()).isTrue();
then(eventSpans).isNotEmpty(); then(eventSpans).isNotEmpty();