コード例 #1
0
ファイル: SourceTest.java プロジェクト: hochgi/akka
 public void mustSuitablyOverrideAttributeHandlingMethods() {
   @SuppressWarnings("unused")
   final Source<Integer, NotUsed> f =
       Source.single(42)
           .withAttributes(Attributes.name(""))
           .addAttributes(Attributes.asyncBoundary())
           .named("");
 }
コード例 #2
0
ファイル: FlowThrottleTest.java プロジェクト: hochgi/akka
  @Test
  public void mustWorksForTwoStreams() throws Exception {
    final Flow<Integer, Integer, NotUsed> sharedThrottle =
        Flow.of(Integer.class)
            .throttle(1, FiniteDuration.create(1, TimeUnit.DAYS), 1, ThrottleMode.enforcing());

    CompletionStage<List<Integer>> result1 =
        Source.single(1).via(sharedThrottle).via(sharedThrottle).runWith(Sink.seq(), materializer);

    // If there is accidental shared state then we would not be able to pass through the single
    // element
    assertEquals(
        result1.toCompletableFuture().get(3, TimeUnit.SECONDS), Collections.singletonList(1));

    // It works with a new stream, too
    CompletionStage<List<Integer>> result2 =
        Source.single(1).via(sharedThrottle).via(sharedThrottle).runWith(Sink.seq(), materializer);

    assertEquals(
        result2.toCompletableFuture().get(3, TimeUnit.SECONDS), Collections.singletonList(1));
  }
コード例 #3
0
ファイル: SourceTest.java プロジェクト: hochgi/akka
  @Test
  public void mustBeAbleToUseIntersperseAndConcat() throws Exception {
    final JavaTestKit probe = new JavaTestKit(system);
    final Source<String, NotUsed> source =
        Source.from(Arrays.asList("0", "1", "2", "3")).intersperse(",");

    final CompletionStage<Done> future =
        Source.single(">> ")
            .concat(source)
            .runWith(
                Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer);

    probe.expectMsgEquals(">> ");
    probe.expectMsgEquals("0");
    probe.expectMsgEquals(",");
    probe.expectMsgEquals("1");
    probe.expectMsgEquals(",");
    probe.expectMsgEquals("2");
    probe.expectMsgEquals(",");
    probe.expectMsgEquals("3");
    future.toCompletableFuture().get(200, TimeUnit.MILLISECONDS);
  }