Skip to content

Commit 49a4c5f

Browse files
committed
reuse http client
1 parent 3fa85f6 commit 49a4c5f

File tree

10 files changed

+110
-56
lines changed

10 files changed

+110
-56
lines changed

instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
package io.opentelemetry.javaagent.instrumentation.playws.v2_1;
77

88
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
9+
import java.io.IOException;
910
import java.net.URI;
1011
import java.util.Map;
1112
import java.util.concurrent.CompletionStage;
1213
import java.util.concurrent.ExecutionException;
13-
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.AfterAll;
15+
import org.junit.jupiter.api.BeforeAll;
1416
import play.libs.ws.StandaloneWSClient;
1517
import play.libs.ws.StandaloneWSRequest;
1618
import play.libs.ws.StandaloneWSResponse;
@@ -21,15 +23,17 @@ class PlayJavaStreamedWsClientTest extends PlayWsClientBaseTest<StandaloneWSRequ
2123
private static StandaloneWSClient wsClient;
2224
private static StandaloneWSClient wsClientWithReadTimeout;
2325

24-
@BeforeEach
25-
@Override
26-
void setup() {
27-
super.setup();
26+
@BeforeAll
27+
static void setup() {
2828
wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer);
2929
wsClientWithReadTimeout =
3030
new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer);
31-
autoCleanup.deferCleanup(wsClient);
32-
autoCleanup.deferCleanup(wsClientWithReadTimeout);
31+
}
32+
33+
@AfterAll
34+
static void cleanup() throws IOException {
35+
wsClient.close();
36+
wsClientWithReadTimeout.close();
3337
}
3438

3539
@Override

instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
package io.opentelemetry.javaagent.instrumentation.playws.v2_1;
77

88
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
9+
import java.io.IOException;
910
import java.net.URI;
1011
import java.util.Map;
1112
import java.util.concurrent.ExecutionException;
12-
import org.junit.jupiter.api.BeforeEach;
13+
import org.junit.jupiter.api.AfterAll;
14+
import org.junit.jupiter.api.BeforeAll;
1315
import play.libs.ws.StandaloneWSClient;
1416
import play.libs.ws.StandaloneWSRequest;
1517
import play.libs.ws.ahc.StandaloneAhcWSClient;
@@ -19,15 +21,17 @@ class PlayJavaWsClientTest extends PlayWsClientBaseTest<StandaloneWSRequest> {
1921
private static StandaloneWSClient wsClient;
2022
private static StandaloneWSClient wsClientWithReadTimeout;
2123

22-
@BeforeEach
23-
@Override
24-
void setup() {
25-
super.setup();
24+
@BeforeAll
25+
static void setup() {
2626
wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer);
2727
wsClientWithReadTimeout =
2828
new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer);
29-
autoCleanup.deferCleanup(wsClient);
30-
autoCleanup.deferCleanup(wsClientWithReadTimeout);
29+
}
30+
31+
@AfterAll
32+
static void cleanup() throws IOException {
33+
wsClient.close();
34+
wsClientWithReadTimeout.close();
3135
}
3236

3337
@Override

instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
package io.opentelemetry.javaagent.instrumentation.playws.v2_1;
77

88
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
9+
import java.io.IOException;
910
import java.net.URI;
1011
import java.util.Map;
1112
import java.util.concurrent.TimeUnit;
12-
import org.junit.jupiter.api.BeforeEach;
13+
import org.junit.jupiter.api.AfterAll;
14+
import org.junit.jupiter.api.BeforeAll;
1315
import play.api.libs.ws.StandaloneWSClient;
1416
import play.api.libs.ws.StandaloneWSRequest;
1517
import play.api.libs.ws.StandaloneWSResponse;
@@ -27,15 +29,17 @@ class PlayScalaStreamedWsClientTest extends PlayWsClientBaseTest<StandaloneWSReq
2729
private static StandaloneWSClient wsClient;
2830
private static StandaloneWSClient wsClientWithReadTimeout;
2931

30-
@BeforeEach
31-
@Override
32+
@BeforeAll
3233
void setup() {
33-
super.setup();
3434
wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer);
3535
wsClientWithReadTimeout =
3636
new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer);
37-
autoCleanup.deferCleanup(wsClient);
38-
autoCleanup.deferCleanup(wsClientWithReadTimeout);
37+
}
38+
39+
@AfterAll
40+
static void cleanup() throws IOException {
41+
wsClient.close();
42+
wsClientWithReadTimeout.close();
3943
}
4044

4145
@Override

instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
package io.opentelemetry.javaagent.instrumentation.playws.v2_1;
77

88
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
9+
import java.io.IOException;
910
import java.net.MalformedURLException;
1011
import java.net.URI;
1112
import java.util.Map;
1213
import java.util.concurrent.TimeUnit;
13-
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.AfterAll;
15+
import org.junit.jupiter.api.BeforeAll;
1416
import play.api.libs.ws.StandaloneWSClient;
1517
import play.api.libs.ws.StandaloneWSRequest;
1618
import play.api.libs.ws.StandaloneWSResponse;
@@ -28,15 +30,17 @@ class PlayScalaWsClientTest extends PlayWsClientBaseTest<StandaloneWSRequest> {
2830
private static StandaloneWSClient wsClient;
2931
private static StandaloneWSClient wsClientWithReadTimeout;
3032

31-
@BeforeEach
32-
@Override
33+
@BeforeAll
3334
void setup() {
34-
super.setup();
3535
wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer);
3636
wsClientWithReadTimeout =
3737
new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer);
38-
autoCleanup.deferCleanup(wsClient);
39-
autoCleanup.deferCleanup(wsClientWithReadTimeout);
38+
}
39+
40+
@AfterAll
41+
static void cleanup() throws IOException {
42+
wsClient.close();
43+
wsClientWithReadTimeout.close();
4044
}
4145

4246
@Override

instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@
88
import akka.actor.ActorSystem;
99
import akka.stream.Materializer;
1010
import io.opentelemetry.api.common.AttributeKey;
11-
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
1211
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
1312
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
1413
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
1514
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
1615
import io.opentelemetry.semconv.NetworkAttributes;
1716
import io.opentelemetry.semconv.ServerAttributes;
17+
import java.io.IOException;
1818
import java.net.InetAddress;
1919
import java.net.UnknownHostException;
2020
import java.util.Collections;
2121
import java.util.HashSet;
2222
import java.util.List;
2323
import java.util.Set;
24+
import org.junit.jupiter.api.AfterAll;
25+
import org.junit.jupiter.api.BeforeAll;
2426
import org.junit.jupiter.api.extension.RegisterExtension;
2527
import play.shaded.ahc.io.netty.resolver.InetNameResolver;
2628
import play.shaded.ahc.io.netty.util.concurrent.EventExecutor;
@@ -37,14 +39,13 @@ abstract class PlayWsClientBaseTest<REQUEST> extends AbstractHttpClientTest<REQU
3739
@RegisterExtension
3840
static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent();
3941

40-
static final AutoCleanupExtension autoCleanup = AutoCleanupExtension.create();
41-
4242
private static ActorSystem system;
4343
protected static AsyncHttpClient asyncHttpClient;
4444
protected static AsyncHttpClient asyncHttpClientWithReadTimeout;
4545
protected static Materializer materializer;
4646

47-
void setup() {
47+
@BeforeAll
48+
static void setupHttpClient() {
4849
String name = "play-ws";
4950
system = ActorSystem.create(name);
5051
materializer = Materializer.matFromSystem(system);
@@ -57,8 +58,13 @@ void setup() {
5758

5859
asyncHttpClient = createClient(false);
5960
asyncHttpClientWithReadTimeout = createClient(true);
60-
autoCleanup.deferCleanup(asyncHttpClient);
61-
autoCleanup.deferCleanup(asyncHttpClientWithReadTimeout);
61+
}
62+
63+
@AfterAll
64+
static void cleanupHttpClient() throws IOException {
65+
asyncHttpClient.close();
66+
asyncHttpClientWithReadTimeout.close();
67+
system.terminate();
6268
}
6369

6470
@Override

instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
package io.opentelemetry.javaagent.instrumentation.playws;
77

88
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
9+
import java.io.IOException;
910
import java.net.URI;
1011
import java.util.Map;
1112
import java.util.concurrent.CompletionStage;
1213
import java.util.concurrent.ExecutionException;
14+
import org.junit.jupiter.api.AfterAll;
15+
import org.junit.jupiter.api.BeforeAll;
1316
import play.libs.ws.StandaloneWSClient;
1417
import play.libs.ws.StandaloneWSRequest;
1518
import play.libs.ws.StandaloneWSResponse;
@@ -20,14 +23,17 @@ public class PlayJavaStreamedWsClientBaseTest extends PlayWsClientBaseTest<Stand
2023
private static StandaloneWSClient wsClient;
2124
private static StandaloneWSClient wsClientWithReadTimeout;
2225

23-
@Override
24-
void setup() {
25-
super.setup();
26+
@BeforeAll
27+
static void setup() {
2628
wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer);
2729
wsClientWithReadTimeout =
2830
new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer);
29-
autoCleanup.deferCleanup(wsClient);
30-
autoCleanup.deferCleanup(wsClientWithReadTimeout);
31+
}
32+
33+
@AfterAll
34+
static void cleanup() throws IOException {
35+
wsClient.close();
36+
wsClientWithReadTimeout.close();
3137
}
3238

3339
@Override

instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
package io.opentelemetry.javaagent.instrumentation.playws;
77

88
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
9+
import java.io.IOException;
910
import java.net.URI;
1011
import java.util.Map;
1112
import java.util.concurrent.ExecutionException;
13+
import org.junit.jupiter.api.AfterAll;
14+
import org.junit.jupiter.api.BeforeAll;
1215
import play.libs.ws.StandaloneWSClient;
1316
import play.libs.ws.StandaloneWSRequest;
1417
import play.libs.ws.ahc.StandaloneAhcWSClient;
@@ -18,14 +21,19 @@ public class PlayJavaWsClientBaseTest extends PlayWsClientBaseTest<StandaloneWSR
1821
private static StandaloneWSClient wsClient;
1922
private static StandaloneWSClient wsClientWithReadTimeout;
2023

21-
@Override
22-
void setup() {
23-
super.setup();
24+
@BeforeAll
25+
static void setup() {
2426
wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer);
2527
wsClientWithReadTimeout =
2628
new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer);
27-
autoCleanup.deferCleanup(wsClient);
28-
autoCleanup.deferCleanup(wsClientWithReadTimeout);
29+
// autoCleanup.deferCleanup(wsClient);
30+
// autoCleanup.deferCleanup(wsClientWithReadTimeout);
31+
}
32+
33+
@AfterAll
34+
static void cleanup() throws IOException {
35+
wsClient.close();
36+
wsClientWithReadTimeout.close();
2937
}
3038

3139
@Override

instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
package io.opentelemetry.javaagent.instrumentation.playws;
77

88
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
9+
import java.io.IOException;
910
import java.net.URI;
1011
import java.util.Map;
1112
import java.util.concurrent.TimeUnit;
13+
import org.junit.jupiter.api.AfterAll;
14+
import org.junit.jupiter.api.BeforeAll;
1215
import play.api.libs.ws.StandaloneWSClient;
1316
import play.api.libs.ws.StandaloneWSRequest;
1417
import play.api.libs.ws.StandaloneWSResponse;
@@ -26,14 +29,17 @@ public class PlayScalaStreamedWsClientBaseTest extends PlayWsClientBaseTest<Stan
2629
private static StandaloneWSClient wsClient;
2730
private static StandaloneWSClient wsClientWithReadTimeout;
2831

29-
@Override
32+
@BeforeAll
3033
void setup() {
31-
super.setup();
3234
wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer);
3335
wsClientWithReadTimeout =
3436
new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer);
35-
autoCleanup.deferCleanup(wsClient);
36-
autoCleanup.deferCleanup(wsClientWithReadTimeout);
37+
}
38+
39+
@AfterAll
40+
static void cleanup() throws IOException {
41+
wsClient.close();
42+
wsClientWithReadTimeout.close();
3743
}
3844

3945
@Override

instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
package io.opentelemetry.javaagent.instrumentation.playws;
77

88
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
9+
import java.io.IOException;
910
import java.net.MalformedURLException;
1011
import java.net.URI;
1112
import java.util.Map;
1213
import java.util.concurrent.TimeUnit;
14+
import org.junit.jupiter.api.AfterAll;
15+
import org.junit.jupiter.api.BeforeAll;
1316
import play.api.libs.ws.StandaloneWSClient;
1417
import play.api.libs.ws.StandaloneWSRequest;
1518
import play.api.libs.ws.StandaloneWSResponse;
@@ -27,14 +30,17 @@ public class PlayScalaWsClientBaseTest extends PlayWsClientBaseTest<StandaloneWS
2730
private static StandaloneWSClient wsClient;
2831
private static StandaloneWSClient wsClientWithReadTimeout;
2932

30-
@Override
33+
@BeforeAll
3134
void setup() {
32-
super.setup();
3335
wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer);
3436
wsClientWithReadTimeout =
3537
new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer);
36-
autoCleanup.deferCleanup(wsClient);
37-
autoCleanup.deferCleanup(wsClientWithReadTimeout);
38+
}
39+
40+
@AfterAll
41+
static void cleanup() throws IOException {
42+
wsClient.close();
43+
wsClientWithReadTimeout.close();
3844
}
3945

4046
@Override

0 commit comments

Comments
 (0)