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,14 @@ 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
+ () -> CompletableFuture . completedFuture (expected ),
297
298
3 ,
298
- scala .concurrent .duration .Duration .apply (200 , "millis" ),
299
- system .scheduler (),
300
- ec );
299
+ Duration .ofMillis (200 ),
300
+ system );
301
301
302
- String actual = Await . result ( retriedFuture , FiniteDuration . apply (3 , SECONDS ) );
302
+ String actual = retriedFuture . toCompletableFuture (). get (3 , SECONDS );
303
303
assertEquals (expected , actual );
304
304
}
305
305
@@ -317,21 +317,24 @@ public void testCSRetry() throws Exception {
317
317
}
318
318
319
319
@ Test (expected = IllegalStateException .class )
320
- public void testAfterFailedCallable () throws Exception {
321
- Callable <Future <String >> failedCallable =
322
- () -> Futures .failed (new IllegalStateException ("Illegal!" ));
320
+ public void testAfterFailedCallable () throws Throwable {
321
+ Callable <CompletionStage <String >> failedCallable =
322
+ () -> Futures .failedCompletionStage (new IllegalStateException ("Illegal!" ));
323
323
324
- Future <String > delayedFuture =
324
+ CompletionStage <String > delayedFuture =
325
325
Patterns .after (
326
- scala .concurrent .duration .Duration .create (200 , "millis" ),
327
- system .scheduler (),
328
- ec ,
326
+ Duration .ofMillis (200 ),
327
+ system ,
329
328
failedCallable );
330
329
331
- Future <String > resultFuture = Futures .firstCompletedOf (Arrays .asList (delayedFuture ), ec );
332
- Await .result (resultFuture , scala .concurrent .duration .FiniteDuration .apply (3 , SECONDS ));
330
+ try {
331
+ delayedFuture .toCompletableFuture ().get (3 , SECONDS );
332
+ } catch (ExecutionException e ) {
333
+ throw e .getCause ();
334
+ }
333
335
}
334
336
337
+ @ SuppressWarnings ("deprecation" )
335
338
@ Test (expected = IllegalStateException .class )
336
339
public void testAfterFailedFuture () throws Exception {
337
340
@@ -340,7 +343,7 @@ public void testAfterFailedFuture() throws Exception {
340
343
scala .concurrent .duration .Duration .create (200 , "millis" ),
341
344
system .scheduler (),
342
345
ec ,
343
- () -> Futures .failed (new IllegalStateException ("Illegal!" )));
346
+ () -> FutureConverters . asScala ( Futures .failedCompletionStage (new IllegalStateException ("Illegal!" ) )));
344
347
345
348
Future <String > resultFuture = Futures .firstCompletedOf (Arrays .asList (delayedFuture ), ec );
346
349
Await .result (resultFuture , FiniteDuration .apply (3 , SECONDS ));
@@ -350,19 +353,18 @@ public void testAfterFailedFuture() throws Exception {
350
353
public void testAfterSuccessfulCallable () throws Exception {
351
354
final String expected = "Hello" ;
352
355
353
- Future <String > delayedFuture =
356
+ CompletionStage <String > delayedFuture =
354
357
Patterns .after (
355
- scala .concurrent .duration .Duration .create (200 , "millis" ),
356
- system .scheduler (),
357
- ec ,
358
- () -> Futures .successful (expected ));
358
+ Duration .ofMillis (200 ),
359
+ system ,
360
+ () -> CompletableFuture .completedFuture (expected ));
359
361
360
- Future <String > resultFuture = Futures .firstCompletedOf (Arrays .asList (delayedFuture ), ec );
361
- final String actual = Await .result (resultFuture , FiniteDuration .apply (3 , SECONDS ));
362
+ String actual = delayedFuture .toCompletableFuture ().get (3 , SECONDS );
362
363
363
364
assertEquals (expected , actual );
364
365
}
365
366
367
+ @ SuppressWarnings ("deprecation" )
366
368
@ Test
367
369
public void testAfterSuccessfulFuture () throws Exception {
368
370
final String expected = "Hello" ;
@@ -380,6 +382,7 @@ public void testAfterSuccessfulFuture() throws Exception {
380
382
assertEquals (expected , actual );
381
383
}
382
384
385
+ @ SuppressWarnings ("deprecation" )
383
386
@ Test
384
387
public void testAfterFiniteDuration () throws Exception {
385
388
final String expected = "Hello" ;
@@ -391,7 +394,7 @@ public void testAfterFiniteDuration() throws Exception {
391
394
ec ,
392
395
() -> Futures .successful ("world" ));
393
396
394
- Future <String > immediateFuture = Futures . future (() -> expected , ec );
397
+ Future <String > immediateFuture = FutureConverters . asScala ( CompletableFuture . completedFuture ( expected ) );
395
398
396
399
Future <String > resultFuture =
397
400
Futures .firstCompletedOf (Arrays .asList (delayedFuture , immediateFuture ), ec );
0 commit comments