|
5 | 5 |
|
6 | 6 | package io.opentelemetry.instrumentation.jetty.httpclient.v12_0;
|
7 | 7 |
|
| 8 | +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; |
| 9 | + |
| 10 | +import io.opentelemetry.api.trace.SpanKind; |
8 | 11 | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
|
9 | 12 | import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
|
10 | 13 | import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
|
|
15 | 18 | import java.util.concurrent.TimeUnit;
|
16 | 19 | import java.util.concurrent.TimeoutException;
|
17 | 20 | import org.eclipse.jetty.client.ContentResponse;
|
| 21 | +import org.eclipse.jetty.client.FutureResponseListener; |
18 | 22 | import org.eclipse.jetty.client.HttpClient;
|
19 | 23 | import org.eclipse.jetty.client.Request;
|
20 | 24 | import org.eclipse.jetty.client.Response;
|
| 25 | +import org.eclipse.jetty.client.Result; |
21 | 26 | import org.eclipse.jetty.http.HttpField;
|
22 | 27 | import org.eclipse.jetty.util.ssl.SslContextFactory;
|
23 | 28 | import org.junit.jupiter.api.AfterEach;
|
24 | 29 | import org.junit.jupiter.api.BeforeEach;
|
| 30 | +import org.junit.jupiter.api.Test; |
25 | 31 |
|
26 | 32 | public abstract class AbstractJettyClient12Test extends AbstractHttpClientTest<Request> {
|
27 | 33 |
|
@@ -108,6 +114,54 @@ public void sendRequestWithCallback(
|
108 | 114 | });
|
109 | 115 | }
|
110 | 116 |
|
| 117 | + @Test |
| 118 | + void callbacksCalled() throws InterruptedException, ExecutionException { |
| 119 | + URI uri = resolveAddress("/success"); |
| 120 | + Request request = client.newRequest(uri).method("GET"); |
| 121 | + FutureResponseListener responseListener = |
| 122 | + new FutureResponseListener(request) { |
| 123 | + @Override |
| 124 | + public void onHeaders(Response response) { |
| 125 | + testing.runWithSpan("onHeaders", () -> super.onHeaders(response)); |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public void onSuccess(Response response) { |
| 130 | + testing.runWithSpan("onSuccess", () -> super.onSuccess(response)); |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public void onComplete(Result result) { |
| 135 | + testing.runWithSpan("onComplete", () -> super.onComplete(result)); |
| 136 | + } |
| 137 | + }; |
| 138 | + testing.runWithSpan("parent", () -> request.send(responseListener)); |
| 139 | + Response response = responseListener.get(); |
| 140 | + |
| 141 | + assertThat(response.getStatus()).isEqualTo(200); |
| 142 | + testing.waitAndAssertTraces( |
| 143 | + trace -> |
| 144 | + trace.hasSpansSatisfyingExactly( |
| 145 | + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), |
| 146 | + span -> span.hasName("GET").hasKind(SpanKind.CLIENT).hasParent(trace.getSpan(0)), |
| 147 | + span -> |
| 148 | + span.hasName("test-http-server") |
| 149 | + .hasKind(SpanKind.SERVER) |
| 150 | + .hasParent(trace.getSpan(1)), |
| 151 | + span -> |
| 152 | + span.hasName("onHeaders") |
| 153 | + .hasKind(SpanKind.INTERNAL) |
| 154 | + .hasParent(trace.getSpan(0)), |
| 155 | + span -> |
| 156 | + span.hasName("onSuccess") |
| 157 | + .hasKind(SpanKind.INTERNAL) |
| 158 | + .hasParent(trace.getSpan(0)), |
| 159 | + span -> |
| 160 | + span.hasName("onComplete") |
| 161 | + .hasKind(SpanKind.INTERNAL) |
| 162 | + .hasParent(trace.getSpan(0)))); |
| 163 | + } |
| 164 | + |
111 | 165 | private static class JettyClientListener
|
112 | 166 | implements Request.FailureListener, Response.FailureListener {
|
113 | 167 | volatile Throwable failure;
|
|
0 commit comments