2020import io .opentelemetry .instrumentation .testing .junit .InstrumentationExtension ;
2121import io .vertx .core .Vertx ;
2222import java .time .Duration ;
23- import java .util .concurrent .CountDownLatch ;
23+ import java .util .concurrent .CompletableFuture ;
2424import java .util .concurrent .TimeUnit ;
2525import javax .persistence .EntityManagerFactory ;
2626import javax .persistence .Persistence ;
@@ -119,7 +119,7 @@ void testMutiny() {
119119
120120 @ Test
121121 void testStage () throws Exception {
122- CountDownLatch latch = new CountDownLatch ( 1 );
122+ CompletableFuture < Object > result = new CompletableFuture <>( );
123123 testing .runWithSpan (
124124 "parent" ,
125125 () ->
@@ -136,15 +136,15 @@ void testStage() throws Exception {
136136 .find (Value .class , 1L )
137137 .thenAccept (value -> testing .runWithSpan ("callback" , () -> {}));
138138 })
139- .thenAccept ( unused -> latch . countDown ( ))));
140- latch . await (30 , TimeUnit .SECONDS );
139+ .whenComplete (( value , throwable ) -> complete ( result , value , throwable ))));
140+ result . get (30 , TimeUnit .SECONDS );
141141
142142 assertTrace ();
143143 }
144144
145145 @ Test
146146 void testStageWithStatelessSession () throws Exception {
147- CountDownLatch latch = new CountDownLatch ( 1 );
147+ CompletableFuture < Object > result = new CompletableFuture <>( );
148148 testing .runWithSpan (
149149 "parent" ,
150150 () ->
@@ -161,15 +161,15 @@ void testStageWithStatelessSession() throws Exception {
161161 .get (Value .class , 1L )
162162 .thenAccept (value -> testing .runWithSpan ("callback" , () -> {}));
163163 })
164- .thenAccept ( unused -> latch . countDown ( ))));
165- latch . await (30 , TimeUnit .SECONDS );
164+ .whenComplete (( value , throwable ) -> complete ( result , value , throwable ))));
165+ result . get (30 , TimeUnit .SECONDS );
166166
167167 assertTrace ();
168168 }
169169
170170 @ Test
171171 void testStageSessionWithTransaction () throws Exception {
172- CountDownLatch latch = new CountDownLatch ( 1 );
172+ CompletableFuture < Object > result = new CompletableFuture <>( );
173173 testing .runWithSpan (
174174 "parent" ,
175175 () ->
@@ -186,15 +186,15 @@ void testStageSessionWithTransaction() throws Exception {
186186 .withTransaction (transaction -> session .find (Value .class , 1L ))
187187 .thenAccept (value -> testing .runWithSpan ("callback" , () -> {}));
188188 })
189- .thenAccept ( unused -> latch . countDown ( ))));
190- latch . await (30 , TimeUnit .SECONDS );
189+ .whenComplete (( value , throwable ) -> complete ( result , value , throwable ))));
190+ result . get (30 , TimeUnit .SECONDS );
191191
192192 assertTrace ();
193193 }
194194
195195 @ Test
196196 void testStageStatelessSessionWithTransaction () throws Exception {
197- CountDownLatch latch = new CountDownLatch ( 1 );
197+ CompletableFuture < Object > result = new CompletableFuture <>( );
198198 testing .runWithSpan (
199199 "parent" ,
200200 () ->
@@ -211,15 +211,15 @@ void testStageStatelessSessionWithTransaction() throws Exception {
211211 .withTransaction (transaction -> session .get (Value .class , 1L ))
212212 .thenAccept (value -> testing .runWithSpan ("callback" , () -> {}));
213213 })
214- .thenAccept ( unused -> latch . countDown ( ))));
215- latch . await (30 , TimeUnit .SECONDS );
214+ .whenComplete (( value , throwable ) -> complete ( result , value , throwable ))));
215+ result . get (30 , TimeUnit .SECONDS );
216216
217217 assertTrace ();
218218 }
219219
220220 @ Test
221221 void testStageOpenSession () throws Exception {
222- CountDownLatch latch = new CountDownLatch ( 1 );
222+ CompletableFuture < Object > result = new CompletableFuture <>( );
223223 testing .runWithSpan (
224224 "parent" ,
225225 () ->
@@ -237,15 +237,15 @@ void testStageOpenSession() throws Exception {
237237 .find (Value .class , 1L )
238238 .thenAccept (value -> testing .runWithSpan ("callback" , () -> {}));
239239 })
240- .thenAccept ( unused -> latch . countDown ( ))));
241- latch . await (30 , TimeUnit .SECONDS );
240+ .whenComplete (( value , throwable ) -> complete ( result , value , throwable ))));
241+ result . get (30 , TimeUnit .SECONDS );
242242
243243 assertTrace ();
244244 }
245245
246246 @ Test
247247 void testStageOpenStatelessSession () throws Exception {
248- CountDownLatch latch = new CountDownLatch ( 1 );
248+ CompletableFuture < Object > result = new CompletableFuture <>( );
249249 testing .runWithSpan (
250250 "parent" ,
251251 () ->
@@ -263,8 +263,8 @@ void testStageOpenStatelessSession() throws Exception {
263263 .get (Value .class , 1L )
264264 .thenAccept (value -> testing .runWithSpan ("callback" , () -> {}));
265265 })
266- .thenAccept ( unused -> latch . countDown ( ))));
267- latch . await (30 , TimeUnit .SECONDS );
266+ .whenComplete (( value , throwable ) -> complete ( result , value , throwable ))));
267+ result . get (30 , TimeUnit .SECONDS );
268268
269269 assertTrace ();
270270 }
@@ -273,6 +273,15 @@ private static void runWithVertx(Runnable runnable) {
273273 Vertx .vertx ().getOrCreateContext ().runOnContext (event -> runnable .run ());
274274 }
275275
276+ private static void complete (
277+ CompletableFuture <Object > completableFuture , Object result , Throwable throwable ) {
278+ if (throwable != null ) {
279+ completableFuture .completeExceptionally (throwable );
280+ } else {
281+ completableFuture .complete (result );
282+ }
283+ }
284+
276285 @ SuppressWarnings ("deprecation" ) // until old http semconv are dropped in 2.0
277286 private static void assertTrace () {
278287 testing .waitAndAssertTraces (
0 commit comments