Skip to content

Commit 3699c44

Browse files
authored
Add JAX-RS client async test (#167)
Signed-off-by: Pavol Loffay <[email protected]>
1 parent 22c528a commit 3699c44

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

instrumentation/jaxrs-client-2.0/src/test/java/io/opentelemetry/instrumentation/hypertrace/jaxrs/v2_0/JaxrsClientBodyInstrumentationTest.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.lang.annotation.Annotation;
2424
import java.lang.reflect.Type;
2525
import java.util.List;
26+
import java.util.concurrent.ExecutionException;
27+
import java.util.concurrent.Future;
2628
import java.util.concurrent.TimeoutException;
2729
import javax.ws.rs.WebApplicationException;
2830
import javax.ws.rs.client.Client;
@@ -69,6 +71,27 @@ public void getJson() throws TimeoutException, InterruptedException {
6971
.request()
7072
.header("test-request-header", "test-header-value")
7173
.get();
74+
assertGetJson(response);
75+
}
76+
77+
@Test
78+
public void getJsonAsync() throws TimeoutException, InterruptedException, ExecutionException {
79+
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
80+
Client client = clientBuilder.build();
81+
82+
Future<Response> responseFuture =
83+
client
84+
.target(String.format("http://localhost:%d/get_json", testHttpServer.port()))
85+
.request()
86+
.header("test-request-header", "test-header-value")
87+
.async()
88+
.get();
89+
90+
Response response = responseFuture.get();
91+
assertGetJson(response);
92+
}
93+
94+
public void assertGetJson(Response response) throws TimeoutException, InterruptedException {
7295
Assertions.assertEquals(200, response.getStatus());
7396
// read entity has to happen before response.close()
7497
String entity = response.readEntity(String.class);
@@ -134,19 +157,21 @@ public void postJson() throws TimeoutException, InterruptedException {
134157
}
135158

136159
@Test
137-
public void postJsonDto() throws TimeoutException, InterruptedException {
160+
public void postJsonDtoAsync() throws TimeoutException, InterruptedException, ExecutionException {
138161
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
139162
Client client = clientBuilder.register(MyDtoMessageBodyWriter.class).build();
140163

141164
MyDto myDto = new MyDto();
142165
myDto.name = "name";
143166

144-
Response response =
167+
Future<Response> post =
145168
client
146169
.target(String.format("http://localhost:%d/post", testHttpServer.port()))
147170
.request()
148171
.header("test-request-header", "test-header-value")
172+
.async()
149173
.post(Entity.json(myDto));
174+
Response response = post.get();
150175
Assertions.assertEquals(204, response.getStatus());
151176

152177
TEST_WRITER.waitForTraces(1);

0 commit comments

Comments
 (0)