예제 #1
0
파일: SourceTest.java 프로젝트: hochgi/akka
 @Test
 public void mustBeAbleToUseQueue() throws Exception {
   final Pair<SourceQueueWithComplete<String>, CompletionStage<List<String>>> x =
       Flow.of(String.class)
           .runWith(Source.queue(2, OverflowStrategy.fail()), Sink.seq(), materializer);
   final SourceQueueWithComplete<String> source = x.first();
   final CompletionStage<List<String>> result = x.second();
   source.offer("hello");
   source.offer("world");
   source.complete();
   assertEquals(
       result.toCompletableFuture().get(3, TimeUnit.SECONDS), Arrays.asList("hello", "world"));
 }
예제 #2
0
파일: SourceTest.java 프로젝트: hochgi/akka
  @Test
  public void mustBeAbleToUseConflate() throws Exception {
    final JavaTestKit probe = new JavaTestKit(system);
    final List<String> input = Arrays.asList("A", "B", "C");
    CompletionStage<String> future =
        Source.from(input)
            .conflateWithSeed(s -> s, (aggr, in) -> aggr + in)
            .runFold("", (aggr, in) -> aggr + in, materializer);
    String result = future.toCompletableFuture().get(3, TimeUnit.SECONDS);
    assertEquals("ABC", result);

    final Flow<String, String, NotUsed> flow2 = Flow.of(String.class).conflate((a, b) -> a + b);

    CompletionStage<String> future2 =
        Source.from(input)
            .conflate((String a, String b) -> a + b)
            .runFold("", (a, b) -> a + b, materializer);
    String result2 = future2.toCompletableFuture().get(3, TimeUnit.SECONDS);
    assertEquals("ABC", result2);
  }