Repository: cxf
Updated Branches:
  refs/heads/master 69826a090 -> 1ae4d6dee


Stabilizing flaky HTrace 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/1ae4d6de
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1ae4d6de
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1ae4d6de

Branch: refs/heads/master
Commit: 1ae4d6dee70587b048c0dcded9cd0b2855c2e225
Parents: 69826a0
Author: reta <[email protected]>
Authored: Thu Jan 5 12:13:58 2017 -0500
Committer: reta <[email protected]>
Committed: Thu Jan 5 12:13:58 2017 -0500

----------------------------------------------------------------------
 .../tracing/brave/IsAnnotationContaining.java   |  2 +-
 .../jaxrs/tracing/htrace/HTraceTracingTest.java |  9 +--
 .../systest/jaxrs/tracing/htrace/HasSpan.java   | 70 ++++++++++++++++++++
 .../tracing/htrace/IsTimelineContaining.java    | 47 +++++++++++++
 .../jaxrs/tracing/htrace/IsTimelineEmpty.java   | 39 +++++++++++
 5 files changed, 162 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/1ae4d6de/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 32621bf..ee00543 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
@@ -30,7 +30,7 @@ public class IsAnnotationContaining extends 
IsCollectionContaining<Annotation> {
             @Override
             public void describeTo(Description description) {
                 description
-                    .appendText("annotation with name")
+                    .appendText("annotation with name ")
                     .appendValue(value);
             }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/1ae4d6de/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingTest.java
----------------------------------------------------------------------
diff --git 
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingTest.java
 
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingTest.java
index b46b422..3322bfb 100644
--- 
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingTest.java
+++ 
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingTest.java
@@ -53,6 +53,9 @@ import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 
+import static org.apache.cxf.systest.jaxrs.tracing.htrace.HasSpan.hasSpan;
+import static 
org.apache.cxf.systest.jaxrs.tracing.htrace.IsTimelineContaining.hasItem;
+import static 
org.apache.cxf.systest.jaxrs.tracing.htrace.IsTimelineEmpty.empty;
 import static org.hamcrest.CoreMatchers.equalTo;
 
 public class HTraceTracingTest extends AbstractBusClientServerTestBase {
@@ -155,10 +158,8 @@ public class HTraceTracingTest extends 
AbstractBusClientServerTestBase {
         assertEquals(Status.OK.getStatusCode(), r.getStatus());
         
         assertThat(TestSpanReceiver.getAllSpans().size(), equalTo(2));
-        assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), 
equalTo("PUT bookstore/process"));
-        
assertThat(TestSpanReceiver.getAllSpans().get(0).getTimelineAnnotations().size(),
 equalTo(0));
-        assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), 
equalTo("Processing books"));
-        
assertThat(TestSpanReceiver.getAllSpans().get(1).getTimelineAnnotations().size(),
 equalTo(1));
+        assertThat(TestSpanReceiver.getAllSpans(), hasSpan("Processing books", 
hasItem("Processing started")));
+        assertThat(TestSpanReceiver.getAllSpans(), hasSpan("PUT 
bookstore/process", empty()));
         
         
assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_SPAN_ID),
 equalTo(spanId.toString()));
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/1ae4d6de/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HasSpan.java
----------------------------------------------------------------------
diff --git 
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HasSpan.java
 
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HasSpan.java
new file mode 100644
index 0000000..e7ad965
--- /dev/null
+++ 
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HasSpan.java
@@ -0,0 +1,70 @@
+/**
+ * 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.htrace;
+
+import org.apache.htrace.core.Span;
+import org.apache.htrace.core.TimelineAnnotation;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+import org.hamcrest.core.IsCollectionContaining;
+
+public class HasSpan extends IsCollectionContaining<Span> {
+    public HasSpan(final String name) {
+        this(name, null);
+    }
+    
+    public HasSpan(final String name, final Matcher<Iterable<? super 
TimelineAnnotation>> 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.getDescription())) {
+                    return false;
+                }
+                
+                if (matcher != null) {
+                    return matcher.matches(item.getTimelineAnnotations());
+                }
+                
+                return true;
+            }
+        });
+    }
+    
+    public static HasSpan hasSpan(final String name) {
+        return new HasSpan(name);
+    }
+    
+    public static HasSpan hasSpan(final String name, final Matcher<Iterable<? 
super TimelineAnnotation>> matcher) {
+        return new HasSpan(name, matcher);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/1ae4d6de/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/IsTimelineContaining.java
----------------------------------------------------------------------
diff --git 
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/IsTimelineContaining.java
 
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/IsTimelineContaining.java
new file mode 100644
index 0000000..05179dc
--- /dev/null
+++ 
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/IsTimelineContaining.java
@@ -0,0 +1,47 @@
+/**
+ * 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.htrace;
+
+import org.apache.htrace.core.TimelineAnnotation;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeMatcher;
+import org.hamcrest.core.IsCollectionContaining;
+
+
+public class IsTimelineContaining extends 
IsCollectionContaining<TimelineAnnotation> {
+    public IsTimelineContaining(final String value) {
+        super(new TypeSafeMatcher<TimelineAnnotation>() {
+            @Override
+            public void describeTo(Description description) {
+                description
+                    .appendText("timeline with name ")
+                    .appendValue(value);
+            }
+
+            @Override
+            protected boolean matchesSafely(TimelineAnnotation item) {
+                return value.equals(item.getMessage());
+            }
+        });
+    }
+    
+    public static IsTimelineContaining hasItem(final String value) {
+        return new IsTimelineContaining(value);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/1ae4d6de/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/IsTimelineEmpty.java
----------------------------------------------------------------------
diff --git 
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/IsTimelineEmpty.java
 
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/IsTimelineEmpty.java
new file mode 100644
index 0000000..b32e01b
--- /dev/null
+++ 
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/IsTimelineEmpty.java
@@ -0,0 +1,39 @@
+/**
+ * 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.htrace;
+
+import org.apache.htrace.core.TimelineAnnotation;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeMatcher;
+
+public class IsTimelineEmpty extends TypeSafeMatcher<Iterable<? super 
TimelineAnnotation>> {
+    @Override
+    public void describeTo(Description description) {
+        description.appendText("timeline is empty");
+    }
+
+    @Override
+    protected boolean matchesSafely(Iterable<? super TimelineAnnotation> 
annotations) {
+        return annotations == null|| !annotations.iterator().hasNext();
+    }
+    
+    public static IsTimelineEmpty empty() {
+        return new IsTimelineEmpty();
+    }
+}
\ No newline at end of file

Reply via email to