Skip to content

Commit

Permalink
add test client error
Browse files Browse the repository at this point in the history
  • Loading branch information
shalk committed Dec 18, 2024
1 parent 8035fb3 commit 044bc96
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class JaxRsClientTest extends AbstractHttpClientTest<Invocation.Builder

protected static final List<String> BODY_METHODS = asList("POST", "PUT");
protected static final int CONNECT_TIMEOUT_MS = 5000;
protected static final int READ_TIMEOUT_MS = 2000;
protected static final int READ_TIMEOUT_MS = 3000;

@Override
public Invocation.Builder buildRequest(String method, URI uri, Map<String, String> headers) {
Expand All @@ -52,6 +52,7 @@ public Invocation.Builder buildRequest(String method, URI uri, Map<String, Strin
protected void configure(HttpClientTestOptions.Builder optionsBuilder) {
super.configure(optionsBuilder);
optionsBuilder.setTestRedirects(false);
optionsBuilder.setTestClientError(true);
optionsBuilder.setTestNonStandardHttpMethod(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,26 @@ void spanEndsAfterHeadersReceived() throws Exception {
});
}

@Test
void requestClientError() throws Exception {
assumeTrue(options.getTestClientError());

URI uri = resolveAddress("/client-error");
String method = "GET";
int responseCode = doRequest(method, uri);

assertThat(responseCode).isEqualTo(400);

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
assertClientSpan(span, uri, method, 400, null)
.hasNoParent()
.hasStatus(StatusData.error()),
span -> assertServerSpan(span).hasParent(trace.getSpan(0))));
}

// Visible for spock bridge.
SpanDataAssert assertClientSpan(
SpanDataAssert span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public boolean isLowLevelInstrumentation() {

public abstract boolean getTestNonStandardHttpMethod();

public abstract boolean getTestClientError();

public abstract boolean getTestCaptureHttpHeaders();

public abstract Function<URI, String> getHttpProtocolVersion();
Expand Down Expand Up @@ -134,6 +136,7 @@ default Builder withDefaults() {
.setTestErrorWithCallback(true)
.setTestNonStandardHttpMethod(true)
.setTestCaptureHttpHeaders(true)
.setTestClientError(false)
.setHttpProtocolVersion(uri -> "1.1");
}

Expand Down Expand Up @@ -179,6 +182,8 @@ default Builder withDefaults() {

Builder setTestNonStandardHttpMethod(boolean value);

Builder setTestClientError(boolean value);

Builder setHttpProtocolVersion(Function<URI, String> value);

@CanIgnoreReturnValue
Expand Down

0 comments on commit 044bc96

Please sign in to comment.