This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/main by this push:
new 4a540e5e1a Revert "CXF-9142 Change async tracing tests to be
order-agnostic (#2427)"
4a540e5e1a is described below
commit 4a540e5e1afeab52a35a02c75979d47d850829a1
Author: Andriy Redko <[email protected]>
AuthorDate: Sun Jun 1 10:26:57 2025 -0400
Revert "CXF-9142 Change async tracing tests to be order-agnostic (#2427)"
This reverts commit c57a4b69f44311b2aae75310db01d1ef5732afc7.
---
.../opentelemetry/OpenTelemetryTracingTest.java | 49 ++++++++--------
.../opentracing/OpenTracingTracingTest.java | 65 +++++++++-------------
2 files changed, 48 insertions(+), 66 deletions(-)
diff --git
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentelemetry/OpenTelemetryTracingTest.java
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentelemetry/OpenTelemetryTracingTest.java
index afc8530389..dde899d4e2 100644
---
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentelemetry/OpenTelemetryTracingTest.java
+++
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentelemetry/OpenTelemetryTracingTest.java
@@ -20,8 +20,11 @@ package org.apache.cxf.systest.jaxrs.tracing.opentelemetry;
import java.net.MalformedURLException;
import java.time.Duration;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -255,31 +258,15 @@ public class OpenTelemetryTracingTest extends
AbstractClientServerTestBase {
final Response r =
withTrace(createWebClient("/bookstore/books/async")).get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
- int spanSize = 2;
- await().atMost(Duration.ofSeconds(1L)).until(() ->
otelRule.getSpans().size() == spanSize);
-
- assertThat(otelRule.getSpans().size(), equalTo(spanSize));
+ await().atMost(Duration.ofSeconds(1L)).until(() ->
otelRule.getSpans().size() == 2);
- boolean foundProcessing = false;
- for (int i = 0; i < spanSize; i++) {
- if ("Processing
books".equals(otelRule.getSpans().get(i).getName())) {
- foundProcessing = true;
- }
- }
- assertTrue("Could not find Processing books in span
getOperationName()", foundProcessing);
-
- boolean foundAsync = false;
- int getIndex = -1;
- for (int i = 0; i < spanSize; i++) {
- if ("GET
/bookstore/books/async".equals(otelRule.getSpans().get(i).getName())) {
- foundAsync = true;
- getIndex = i;
- }
- }
+ final List<SpanData> spans = getSpansSorted();
+ assertThat(spans.size(), equalTo(2));
-
assertThat(otelRule.getSpans().get(getIndex).getParentSpanContext().isValid(),
equalTo(true));
- assertThat(otelRule.getSpans().get(getIndex).getParentSpanId(),
- equalTo(Span.current().getSpanContext().getSpanId()));
+ assertEquals("Processing books", spans.get(0).getName());
+ assertEquals("GET /bookstore/books/async", spans.get(1).getName());
+ assertThat(spans.get(1).getParentSpanContext().isValid(),
equalTo(true));
+ assertThat(spans.get(1).getParentSpanId(),
equalTo(Span.current().getSpanContext().getSpanId()));
}
}
@@ -303,9 +290,10 @@ public class OpenTelemetryTracingTest extends
AbstractClientServerTestBase {
await().atMost(Duration.ofSeconds(1L)).until(() ->
otelRule.getSpans().size() == 2);
- assertThat(otelRule.getSpans().size(), equalTo(2));
- assertThat(otelRule.getSpans().get(0).getName(), equalTo("Processing
books"));
- assertThat(otelRule.getSpans().get(1).getName(), equalTo("GET
/bookstore/books/async"));
+ final List<SpanData> spans = getSpansSorted();
+ assertThat(spans.size(), equalTo(2));
+ assertThat(spans.get(0).getName(), equalTo("Processing books"));
+ assertThat(spans.get(1).getName(), equalTo("GET
/bookstore/books/async"));
}
@Test
@@ -545,6 +533,15 @@ public class OpenTelemetryTracingTest extends
AbstractClientServerTestBase {
}
}
+ private List<SpanData> getSpansSorted() {
+ final List<SpanData> spans = new ArrayList<>(otelRule.getSpans());
+ spans.sort(Comparator
+ .comparingLong(SpanData::getStartEpochNanos)
+ .thenComparingLong(SpanData::getEndEpochNanos)
+ .reversed());
+ return spans;
+ }
+
public static class OpenTelemetryServer extends AbstractTestServerBase {
private org.apache.cxf.endpoint.Server server;
diff --git
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentracing/OpenTracingTracingTest.java
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentracing/OpenTracingTracingTest.java
index 53899e9b69..d8be95bbd6 100644
---
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentracing/OpenTracingTracingTest.java
+++
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentracing/OpenTracingTracingTest.java
@@ -20,9 +20,12 @@ package org.apache.cxf.systest.jaxrs.tracing.opentracing;
import java.net.MalformedURLException;
import java.time.Duration;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
import java.util.Iterator;
+import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -50,6 +53,7 @@ import
org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider;
import org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingFeature;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import io.jaegertracing.internal.JaegerSpan;
import io.jaegertracing.internal.JaegerSpanContext;
import io.jaegertracing.internal.JaegerTracer;
import io.jaegertracing.internal.reporters.InMemoryReporter;
@@ -196,30 +200,14 @@ public class OpenTracingTracingTest extends
AbstractClientServerTestBase {
final Response r =
withTrace(createWebClient("/bookstore/books/async"), spanId).get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
- int spanSize = 2;
- await().atMost(Duration.ofSeconds(1L)).until(()->
REPORTER.getSpans().size() == spanSize);
+ await().atMost(Duration.ofSeconds(1L)).until(()->
REPORTER.getSpans().size() == 2);
- assertThat(REPORTER.getSpans().size(), equalTo(spanSize));
- boolean foundProcessing = false;
- for (int i = 0; i < spanSize; i++) {
- if ("Processing
books".equals(REPORTER.getSpans().get(i).getOperationName())) {
- foundProcessing = true;
- }
- }
- assertTrue("Could not find Processing books in span
getOperationName()", foundProcessing);
-
- boolean foundAsync = false;
- int getIndex = -1;
- for (int i = 0; i < spanSize; i++) {
- if ("GET
/bookstore/books/async".equals(REPORTER.getSpans().get(i).getOperationName())) {
- foundAsync = true;
- getIndex = 1;
- }
- }
- assertTrue("Could not find GET /bookstore/books/async in span
getOperationName()", foundAsync);
-
- assertThat(REPORTER.getSpans().get(getIndex).getReferences(),
not(empty()));
-
assertThat(REPORTER.getSpans().get(getIndex).getReferences().get(0).getSpanContext().getSpanId(),
+ final List<JaegerSpan> spans = getSpansSorted();
+ assertThat(spans.size(), equalTo(2));
+ assertEquals("Processing books", spans.get(0).getOperationName());
+ assertEquals("GET /bookstore/books/async",
spans.get(1).getOperationName());
+ assertThat(spans.get(1).getReferences(), not(empty()));
+
assertThat(spans.get(1).getReferences().get(0).getSpanContext().getSpanId(),
equalTo(spanId.getSpanId()));
}
@@ -239,24 +227,12 @@ public class OpenTracingTracingTest extends
AbstractClientServerTestBase {
final Response r = createWebClient("/bookstore/books/async").get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
- int spanSize = 2;
- await().atMost(Duration.ofSeconds(1L)).until(()->
REPORTER.getSpans().size() == spanSize);
-
- assertThat(REPORTER.getSpans().size(), equalTo(spanSize));
- boolean foundProcessing = false;
- for (int i = 0; i < spanSize; i++) {
- if ("Processing
books".equals(REPORTER.getSpans().get(i).getOperationName())) {
- foundProcessing = true;
- }
- }
- assertTrue("Could not find Processing books in span
getOperationName()", foundProcessing);
+ await().atMost(Duration.ofSeconds(1L)).until(()->
REPORTER.getSpans().size() == 2);
- boolean foundAsync = false;
- for (int i = 0; i < spanSize; i++) {
- if ("GET
/bookstore/books/async".equals(REPORTER.getSpans().get(i).getOperationName())) {
- foundAsync = true;
- }
- }
+ final List<JaegerSpan> spans = getSpansSorted();
+ assertThat(spans.size(), equalTo(2));
+ assertThat(spans.get(0).getOperationName(), equalTo("Processing
books"));
+ assertThat(spans.get(1).getOperationName(), equalTo("GET
/bookstore/books/async"));
}
@Test
@@ -490,4 +466,13 @@ public class OpenTracingTracingTest extends
AbstractClientServerTestBase {
RANDOM.getAndIncrement() /* traceId lo */,
RANDOM.getAndIncrement() /* spanId */,
RANDOM.getAndIncrement() /* parentId */, (byte) 1 /* sampled */);
}
+
+ private List<JaegerSpan> getSpansSorted() {
+ final List<JaegerSpan> spans = new ArrayList<>(REPORTER.getSpans());
+ spans.sort(Comparator
+ .comparingLong(JaegerSpan::getStart)
+ .thenComparing((s1, s2) -> Long.compare(s1.getStart() +
s1.getDuration(), s2.getStart() + s2.getDuration()))
+ .reversed());
+ return spans;
+ }
}