Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.javahttpclient;

import java.net.http.HttpClient;

class Http1ClientTest extends JavaHttpClientTest {

@Override
protected void configureHttpClientBuilder(HttpClient.Builder httpClientBuilder) {
httpClientBuilder.version(HttpClient.Version.HTTP_1_1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.javahttpclient;

import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import java.net.http.HttpClient;

class Http2ClientTest extends JavaHttpClientTest {

@Override
protected void configureHttpClientBuilder(HttpClient.Builder httpClientBuilder) {
httpClientBuilder.version(HttpClient.Version.HTTP_2);
}

@Override
protected void configure(HttpClientTestOptions.Builder optionsBuilder) {
super.configure(optionsBuilder);

optionsBuilder.setHttpProtocolVersion(
uri -> {
String uriString = uri.toString();
if (uriString.equals("http://localhost:61/") || uriString.equals("https://192.0.2.1/")) {
return "1.1";
}
return "2";
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import io.opentelemetry.instrumentation.javahttpclient.AbstractJavaHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import java.net.http.HttpClient;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.extension.RegisterExtension;

public abstract class JavaHttpClientTest extends AbstractJavaHttpClientTest {
Expand All @@ -22,37 +20,4 @@ public abstract class JavaHttpClientTest extends AbstractJavaHttpClientTest {
protected HttpClient configureHttpClient(HttpClient httpClient) {
return httpClient;
}

@Nested
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested making these classes non-static, but then I hit circular dependency with the inner class extending its enclosing class

If we keep the classes static and remove the @Nested annotation, the tests run, but I believe that we risk test isolation problems

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested tests could be made to work with #14043 Honestly I'm not sure which I like better.

static class Http1ClientTest extends JavaHttpClientTest {

@Override
protected void configureHttpClientBuilder(HttpClient.Builder httpClientBuilder) {
httpClientBuilder.version(HttpClient.Version.HTTP_1_1);
}
}

@Nested
static class Http2ClientTest extends JavaHttpClientTest {

@Override
protected void configureHttpClientBuilder(HttpClient.Builder httpClientBuilder) {
httpClientBuilder.version(HttpClient.Version.HTTP_2);
}

@Override
protected void configure(HttpClientTestOptions.Builder optionsBuilder) {
super.configure(optionsBuilder);

optionsBuilder.setHttpProtocolVersion(
uri -> {
String uriString = uri.toString();
if (uriString.equals("http://localhost:61/")
|| uriString.equals("https://192.0.2.1/")) {
return "1.1";
}
return "2";
});
}
}
}
Loading