19
19
import org .apache .pekko .testkit .PekkoSpec ;
20
20
import org .apache .pekko .testkit .TestProbe ;
21
21
import org .apache .pekko .util .Timeout ;
22
+ import org .apache .pekko .util .FutureConverters ;
22
23
import org .junit .ClassRule ;
23
24
import org .junit .Test ;
24
25
import org .scalatestplus .junit .JUnitSuite ;
@@ -219,15 +220,15 @@ public void testAskWithReplyToTimeout() throws Exception {
219
220
@ Test
220
221
public void usePipe () throws Exception {
221
222
TestProbe probe = new TestProbe (system );
222
- pipe (Futures . successful ("ho!" ), system .dispatcher ()).to (probe .ref ());
223
+ pipe (CompletableFuture . completedFuture ("ho!" ), system .dispatcher ()).to (probe .ref ());
223
224
probe .expectMsg ("ho!" );
224
225
}
225
226
226
227
@ Test
227
228
public void usePipeWithActorSelection () throws Exception {
228
229
TestProbe probe = new TestProbe (system );
229
230
ActorSelection selection = system .actorSelection (probe .ref ().path ());
230
- pipe (Futures . successful ("hi!" ), system .dispatcher ()).to (selection );
231
+ pipe (CompletableFuture . completedFuture ("hi!" ), system .dispatcher ()).to (selection );
231
232
probe .expectMsg ("hi!" );
232
233
}
233
234
@@ -291,15 +292,11 @@ public void testRetryCompletionStageRandomDelay() throws Exception {
291
292
public void testRetry () throws Exception {
292
293
final String expected = "hello" ;
293
294
294
- Future <String > retriedFuture =
295
+ CompletionStage <String > retriedFuture =
295
296
Patterns .retry (
296
- () -> Futures .successful (expected ),
297
- 3 ,
298
- scala .concurrent .duration .Duration .apply (200 , "millis" ),
299
- system .scheduler (),
300
- ec );
297
+ () -> CompletableFuture .completedFuture (expected ), 3 , Duration .ofMillis (200 ), system );
301
298
302
- String actual = Await . result ( retriedFuture , FiniteDuration . apply (3 , SECONDS ) );
299
+ String actual = retriedFuture . toCompletableFuture (). get (3 , SECONDS );
303
300
assertEquals (expected , actual );
304
301
}
305
302
@@ -317,21 +314,21 @@ public void testCSRetry() throws Exception {
317
314
}
318
315
319
316
@ Test (expected = IllegalStateException .class )
320
- public void testAfterFailedCallable () throws Exception {
321
- Callable <Future <String >> failedCallable =
322
- () -> Futures .failed (new IllegalStateException ("Illegal!" ));
317
+ public void testAfterFailedCallable () throws Throwable {
318
+ Callable <CompletionStage <String >> failedCallable =
319
+ () -> Futures .failedCompletionStage (new IllegalStateException ("Illegal!" ));
323
320
324
- Future <String > delayedFuture =
325
- Patterns .after (
326
- scala .concurrent .duration .Duration .create (200 , "millis" ),
327
- system .scheduler (),
328
- ec ,
329
- failedCallable );
321
+ CompletionStage <String > delayedFuture =
322
+ Patterns .after (Duration .ofMillis (200 ), system , failedCallable );
330
323
331
- Future <String > resultFuture = Futures .firstCompletedOf (Arrays .asList (delayedFuture ), ec );
332
- Await .result (resultFuture , scala .concurrent .duration .FiniteDuration .apply (3 , SECONDS ));
324
+ try {
325
+ delayedFuture .toCompletableFuture ().get (3 , SECONDS );
326
+ } catch (ExecutionException e ) {
327
+ throw e .getCause ();
328
+ }
333
329
}
334
330
331
+ @ SuppressWarnings ("deprecation" )
335
332
@ Test (expected = IllegalStateException .class )
336
333
public void testAfterFailedFuture () throws Exception {
337
334
@@ -340,7 +337,9 @@ public void testAfterFailedFuture() throws Exception {
340
337
scala .concurrent .duration .Duration .create (200 , "millis" ),
341
338
system .scheduler (),
342
339
ec ,
343
- () -> Futures .failed (new IllegalStateException ("Illegal!" )));
340
+ () ->
341
+ FutureConverters .asScala (
342
+ Futures .failedCompletionStage (new IllegalStateException ("Illegal!" ))));
344
343
345
344
Future <String > resultFuture = Futures .firstCompletedOf (Arrays .asList (delayedFuture ), ec );
346
345
Await .result (resultFuture , FiniteDuration .apply (3 , SECONDS ));
@@ -350,19 +349,16 @@ public void testAfterFailedFuture() throws Exception {
350
349
public void testAfterSuccessfulCallable () throws Exception {
351
350
final String expected = "Hello" ;
352
351
353
- Future <String > delayedFuture =
352
+ CompletionStage <String > delayedFuture =
354
353
Patterns .after (
355
- scala .concurrent .duration .Duration .create (200 , "millis" ),
356
- system .scheduler (),
357
- ec ,
358
- () -> Futures .successful (expected ));
354
+ Duration .ofMillis (200 ), system , () -> CompletableFuture .completedFuture (expected ));
359
355
360
- Future <String > resultFuture = Futures .firstCompletedOf (Arrays .asList (delayedFuture ), ec );
361
- final String actual = Await .result (resultFuture , FiniteDuration .apply (3 , SECONDS ));
356
+ String actual = delayedFuture .toCompletableFuture ().get (3 , SECONDS );
362
357
363
358
assertEquals (expected , actual );
364
359
}
365
360
361
+ @ SuppressWarnings ("deprecation" )
366
362
@ Test
367
363
public void testAfterSuccessfulFuture () throws Exception {
368
364
final String expected = "Hello" ;
@@ -380,6 +376,7 @@ public void testAfterSuccessfulFuture() throws Exception {
380
376
assertEquals (expected , actual );
381
377
}
382
378
379
+ @ SuppressWarnings ("deprecation" )
383
380
@ Test
384
381
public void testAfterFiniteDuration () throws Exception {
385
382
final String expected = "Hello" ;
@@ -391,7 +388,8 @@ public void testAfterFiniteDuration() throws Exception {
391
388
ec ,
392
389
() -> Futures .successful ("world" ));
393
390
394
- Future <String > immediateFuture = Futures .future (() -> expected , ec );
391
+ Future <String > immediateFuture =
392
+ FutureConverters .asScala (CompletableFuture .completedFuture (expected ));
395
393
396
394
Future <String > resultFuture =
397
395
Futures .firstCompletedOf (Arrays .asList (delayedFuture , immediateFuture ), ec );
0 commit comments