@Test
 public void demonstrateSlowProcessing() {
   // #tweets-slow-consumption-dropHead
   tweets
       .buffer(10, OverflowStrategy.dropHead())
       .map(t -> slowComputation(t))
       .runWith(Sink.ignore(), mat);
   // #tweets-slow-consumption-dropHead
 }
Esempio n. 2
0
 @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"));
 }
Esempio n. 3
0
  @Test
  public void mustBeAbleToUseBuffer() throws Exception {
    final JavaTestKit probe = new JavaTestKit(system);
    final List<String> input = Arrays.asList("A", "B", "C");
    final CompletionStage<List<String>> future =
        Source.from(input)
            .buffer(2, OverflowStrategy.backpressure())
            .grouped(4)
            .runWith(Sink.<List<String>>head(), materializer);

    List<String> result = future.toCompletableFuture().get(3, TimeUnit.SECONDS);
    assertEquals(input, result);
  }
Esempio n. 4
0
 @Test
 public void mustBeAbleToUseActorRefSource() throws Exception {
   final JavaTestKit probe = new JavaTestKit(system);
   final Source<Integer, ActorRef> actorRefSource = Source.actorRef(10, OverflowStrategy.fail());
   final ActorRef ref =
       actorRefSource
           .to(
               Sink.foreach(
                   new Procedure<Integer>() {
                     public void apply(Integer elem) {
                       probe.getRef().tell(elem, ActorRef.noSender());
                     }
                   }))
           .run(materializer);
   ref.tell(1, ActorRef.noSender());
   probe.expectMsgEquals(1);
   ref.tell(2, ActorRef.noSender());
   probe.expectMsgEquals(2);
 }