예제 #1
0
파일: SourceTest.java 프로젝트: hochgi/akka
 @Test
 public void mustProduceTicks() throws Exception {
   final JavaTestKit probe = new JavaTestKit(system);
   Source<String, Cancellable> tickSource =
       Source.tick(
           FiniteDuration.create(1, TimeUnit.SECONDS),
           FiniteDuration.create(500, TimeUnit.MILLISECONDS),
           "tick");
   @SuppressWarnings("unused")
   Cancellable cancellable =
       tickSource
           .to(
               Sink.foreach(
                   new Procedure<String>() {
                     public void apply(String elem) {
                       probe.getRef().tell(elem, ActorRef.noSender());
                     }
                   }))
           .run(materializer);
   probe.expectNoMsg(FiniteDuration.create(600, TimeUnit.MILLISECONDS));
   probe.expectMsgEquals("tick");
   probe.expectNoMsg(FiniteDuration.create(200, TimeUnit.MILLISECONDS));
   probe.expectMsgEquals("tick");
   probe.expectNoMsg(FiniteDuration.create(200, TimeUnit.MILLISECONDS));
 }
예제 #2
0
파일: SourceTest.java 프로젝트: hochgi/akka
 @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);
 }