示例#1
0
 @Test
 public void mustBeAbleToUseIdleTimeout() throws Throwable {
   try {
     try {
       Source.maybe()
           .idleTimeout(Duration.create(1, "second"))
           .runWith(Sink.head(), materializer)
           .toCompletableFuture()
           .get(3, TimeUnit.SECONDS);
       fail("A TimeoutException was expected");
     } catch (ExecutionException e) {
       throw e.getCause();
     }
   } catch (TimeoutException e) {
     // expected
   }
 }
示例#2
0
  @Test
  public void mustBeAbleToUseIdleInject() throws Exception {
    Integer result =
        Source.maybe()
            .keepAlive(
                Duration.create(1, "second"),
                new Creator<Integer>() {
                  public Integer create() {
                    return 0;
                  }
                })
            .takeWithin(Duration.create(1500, "milliseconds"))
            .runWith(Sink.<Integer>head(), materializer)
            .toCompletableFuture()
            .get(3, TimeUnit.SECONDS);

    assertEquals((Object) 0, result);
  }