Skip to content

Commit 044bc96

Browse files
committed
add test client error
1 parent 8035fb3 commit 044bc96

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/JaxRsClientTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class JaxRsClientTest extends AbstractHttpClientTest<Invocation.Builder
3333

3434
protected static final List<String> BODY_METHODS = asList("POST", "PUT");
3535
protected static final int CONNECT_TIMEOUT_MS = 5000;
36-
protected static final int READ_TIMEOUT_MS = 2000;
36+
protected static final int READ_TIMEOUT_MS = 3000;
3737

3838
@Override
3939
public Invocation.Builder buildRequest(String method, URI uri, Map<String, String> headers) {
@@ -52,6 +52,7 @@ public Invocation.Builder buildRequest(String method, URI uri, Map<String, Strin
5252
protected void configure(HttpClientTestOptions.Builder optionsBuilder) {
5353
super.configure(optionsBuilder);
5454
optionsBuilder.setTestRedirects(false);
55+
optionsBuilder.setTestClientError(true);
5556
optionsBuilder.setTestNonStandardHttpMethod(false);
5657
}
5758

testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,26 @@ void spanEndsAfterHeadersReceived() throws Exception {
10301030
});
10311031
}
10321032

1033+
@Test
1034+
void requestClientError() throws Exception {
1035+
assumeTrue(options.getTestClientError());
1036+
1037+
URI uri = resolveAddress("/client-error");
1038+
String method = "GET";
1039+
int responseCode = doRequest(method, uri);
1040+
1041+
assertThat(responseCode).isEqualTo(400);
1042+
1043+
testing.waitAndAssertTraces(
1044+
trace ->
1045+
trace.hasSpansSatisfyingExactly(
1046+
span ->
1047+
assertClientSpan(span, uri, method, 400, null)
1048+
.hasNoParent()
1049+
.hasStatus(StatusData.error()),
1050+
span -> assertServerSpan(span).hasParent(trace.getSpan(0))));
1051+
}
1052+
10331053
// Visible for spock bridge.
10341054
SpanDataAssert assertClientSpan(
10351055
SpanDataAssert span,

testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientTestOptions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public boolean isLowLevelInstrumentation() {
8989

9090
public abstract boolean getTestNonStandardHttpMethod();
9191

92+
public abstract boolean getTestClientError();
93+
9294
public abstract boolean getTestCaptureHttpHeaders();
9395

9496
public abstract Function<URI, String> getHttpProtocolVersion();
@@ -134,6 +136,7 @@ default Builder withDefaults() {
134136
.setTestErrorWithCallback(true)
135137
.setTestNonStandardHttpMethod(true)
136138
.setTestCaptureHttpHeaders(true)
139+
.setTestClientError(false)
137140
.setHttpProtocolVersion(uri -> "1.1");
138141
}
139142

@@ -179,6 +182,8 @@ default Builder withDefaults() {
179182

180183
Builder setTestNonStandardHttpMethod(boolean value);
181184

185+
Builder setTestClientError(boolean value);
186+
182187
Builder setHttpProtocolVersion(Function<URI, String> value);
183188

184189
@CanIgnoreReturnValue

0 commit comments

Comments
 (0)