use of akka.testkit.TestKit in project controller by opendaylight.
the class MeteredBoundedMailboxTest method shouldSendMsgToDeadLetterWhenQueueIsFull.
@Test
public void shouldSendMsgToDeadLetterWhenQueueIsFull() throws InterruptedException {
final TestKit mockReceiver = new TestKit(actorSystem);
actorSystem.eventStream().subscribe(mockReceiver.testActor(), DeadLetter.class);
final FiniteDuration twentySeconds = new FiniteDuration(20, TimeUnit.SECONDS);
ActorRef pingPongActor = actorSystem.actorOf(PingPongActor.props(lock).withMailbox(config.getMailBoxName()), "pingpongactor");
actorSystem.mailboxes().settings();
lock.lock();
try {
// 12th message is sent to dead letter.
for (int i = 0; i < 12; i++) {
pingPongActor.tell("ping", mockReceiver.testActor());
}
mockReceiver.expectMsgClass(twentySeconds, DeadLetter.class);
} finally {
lock.unlock();
}
mockReceiver.receiveN(11, twentySeconds);
}
use of akka.testkit.TestKit in project tutorials by eugenp.
the class AkkaActorsUnitTest method givenAnActor_sendHimAMessageUsingTell.
@Test
public void givenAnActor_sendHimAMessageUsingTell() {
final TestKit probe = new TestKit(system);
ActorRef myActorRef = probe.childActorOf(Props.create(MyActor.class));
myActorRef.tell("printit", probe.testActor());
probe.expectMsg("Got Message");
}
use of akka.testkit.TestKit in project tutorials by eugenp.
the class AkkaActorsUnitTest method givenAnActor_sendHimAMessageUsingAsk.
@Test
public void givenAnActor_sendHimAMessageUsingAsk() throws ExecutionException, InterruptedException {
final TestKit probe = new TestKit(system);
ActorRef wordCounterActorRef = probe.childActorOf(Props.create(WordCounterActor.class));
CompletableFuture<Object> future = ask(wordCounterActorRef, new WordCounterActor.CountWords("this is a text"), 1000).toCompletableFuture();
Integer numberOfWords = (Integer) future.get();
assertTrue("The actor should count 4 words", 4 == numberOfWords);
}
use of akka.testkit.TestKit in project tutorials by eugenp.
the class AkkaActorsUnitTest method givenAnActor_whenTheMessageIsNull_respondWithException.
@Test
public void givenAnActor_whenTheMessageIsNull_respondWithException() {
final TestKit probe = new TestKit(system);
ActorRef wordCounterActorRef = probe.childActorOf(Props.create(WordCounterActor.class));
CompletableFuture<Object> future = ask(wordCounterActorRef, new WordCounterActor.CountWords(null), 1000).toCompletableFuture();
try {
future.get(1000, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
assertTrue("Invalid error message", e.getMessage().contains("The text to process can't be null!"));
} catch (InterruptedException | TimeoutException e) {
fail("Actor should respond with an exception instead of timing out !");
}
}
Aggregations