Repository: cxf Updated Branches: refs/heads/master 101e9a0a4 -> 3f259221f
Stabilizing flaky Brave test cases by relaxing the spans order matches Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/3f259221 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3f259221 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3f259221 Branch: refs/heads/master Commit: 3f259221fa1dd9227397400ed9653374cb4fdc39 Parents: 101e9a0 Author: reta <[email protected]> Authored: Sat Dec 31 11:45:40 2016 -0500 Committer: reta <[email protected]> Committed: Sat Dec 31 11:45:40 2016 -0500 ---------------------------------------------------------------------- .../jaxrs/tracing/brave/BraveTracingTest.java | 6 +- .../systest/jaxrs/tracing/brave/HasSpan.java | 71 ++++++++++++++++++++ .../tracing/brave/IsAnnotationContaining.java | 4 +- 3 files changed, 77 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/3f259221/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java ---------------------------------------------------------------------- diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java index 1b40bad..e43dae8 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java @@ -49,6 +49,7 @@ import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import static org.apache.cxf.systest.jaxrs.tracing.brave.HasSpan.hasSpan; import static org.apache.cxf.systest.jaxrs.tracing.brave.IsAnnotationContaining.hasItem; import static org.apache.cxf.systest.jaxrs.tracing.brave.IsBinaryAnnotationContaining.hasItem; import static org.hamcrest.CoreMatchers.equalTo; @@ -146,9 +147,8 @@ public class BraveTracingTest extends AbstractBusClientServerTestBase { assertEquals(Status.OK.getStatusCode(), r.getStatus()); assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().get(0).name, equalTo("processing books")); - assertThat(TestSpanReporter.getAllSpans().get(0).annotations, hasItem("Processing started")); - assertThat(TestSpanReporter.getAllSpans().get(1).name, equalTo("put /bookstore/process")); + assertThat(TestSpanReporter.getAllSpans(), hasSpan("processing books", hasItem("Processing started"))); + assertThat(TestSpanReporter.getAllSpans(), hasSpan("put /bookstore/process")); assertThatTraceIsPresent(r, spanId); } http://git-wip-us.apache.org/repos/asf/cxf/blob/3f259221/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/HasSpan.java ---------------------------------------------------------------------- diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/HasSpan.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/HasSpan.java new file mode 100644 index 0000000..0881226 --- /dev/null +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/HasSpan.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.systest.jaxrs.tracing.brave; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; +import org.hamcrest.core.IsCollectionContaining; + +import zipkin.Annotation; +import zipkin.Span; + +public class HasSpan extends IsCollectionContaining<Span> { + public HasSpan(final String name) { + this(name, null); + } + + public HasSpan(final String name, final Matcher<Iterable<? super Annotation>> matcher) { + super(new TypeSafeMatcher<Span>() { + @Override + public void describeTo(Description description) { + description + .appendText("span with name ") + .appendValue(name) + .appendText(" "); + + if (matcher != null) { + description.appendText(" and "); + matcher.describeTo(description); + } + } + + @Override + protected boolean matchesSafely(Span item) { + if (!name.equals(item.name)) { + return false; + } + + if (matcher != null) { + return matcher.matches(item.annotations); + } + + return true; + } + }); + } + + public static HasSpan hasSpan(final String name) { + return new HasSpan(name); + } + + public static HasSpan hasSpan(final String name, final Matcher<Iterable<? super Annotation>> matcher) { + return new HasSpan(name, matcher); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf/blob/3f259221/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/IsAnnotationContaining.java ---------------------------------------------------------------------- diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/IsAnnotationContaining.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/IsAnnotationContaining.java index 54d877b..32621bf 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/IsAnnotationContaining.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/IsAnnotationContaining.java @@ -29,7 +29,9 @@ public class IsAnnotationContaining extends IsCollectionContaining<Annotation> { super(new TypeSafeMatcher<Annotation>() { @Override public void describeTo(Description description) { - description.appendValue(value); + description + .appendText("annotation with name") + .appendValue(value); } @Override
