!str #16520 Add ActorRefSource

* and rename the factory for ActorPublisherSource,
  from Source.apply to Source.actorPublisher

* including internal buffer, with OverflowStrategy

* support to complete/fail stream
This commit is contained in:
Patrik Nordwall 2015-03-31 15:13:57 +02:00
parent 946faedd95
commit f4ed62b84c
13 changed files with 318 additions and 33 deletions

View file

@ -23,11 +23,9 @@ import scala.concurrent.Future;
import scala.concurrent.duration.FiniteDuration;
import scala.runtime.BoxedUnit;
import scala.util.Try;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
public class SourceTest extends StreamTest {
@ -459,4 +457,19 @@ public class SourceTest extends StreamTest {
assertEquals(result.size(), 10000);
for (Integer i: result) assertEquals(i, (Integer) 42);
}
@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);
}
}