Java Code Examples for akka.testkit.javadsl.TestKit#expectNoMessage()

The following examples show how to use akka.testkit.javadsl.TestKit#expectNoMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackOffActorTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void maxBackOffTimeIsNotExceeded() {
    final Duration minBackOff = Duration.ofSeconds(1);
    final Duration maxBackOff = Duration.ofSeconds(2);
    final BackOffConfig configWithSmallMaxTimeout = createBackOffConfig(minBackOff, maxBackOff);

    final TestKit probe = new TestKit(actorSystem);
    final ActorRef underTest = probe.childActorOf(BackOffActor.props(configWithSmallMaxTimeout));
    final String message = "I expect to receive this after backOff";

    final int iterations = 10;
    Duration currentBackOff = minBackOff;
    for (int i = 0; i < iterations; ++i) {
        underTest.tell(BackOffActor.createBackOffWithAnswerMessage(message), probe.getRef());
        probe.expectNoMessage(currentBackOff.dividedBy(2L));
        probe.expectMsg(currentBackOff, message);
        currentBackOff = min(currentBackOff.multipliedBy(2L), maxBackOff);
    }
}
 
Example 2
Source File: AriCommandResponseProcessingTest.java    From ari-proxy with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
void registerCallContextDoesNothingWhenItShouldnt() {
	final TestKit callContextProvider = new TestKit(system);
	final AriCommand ariCommand = mock(AriCommand.class);
	doReturn("/channels/CHANNEL_ID/answer").when(ariCommand).getUrl();
	doReturn(mock(JsonNode.class)).when(ariCommand).getBody();

	final Either<RuntimeException, Runnable> res = AriCommandResponseProcessing
			.registerCallContext(callContextProvider.getRef(), "CALL_CONTEXT", ariCommand);

	res.get().run();

	callContextProvider.expectNoMessage(Duration.ofMillis(500));
}
 
Example 3
Source File: ConnectionPersistenceActorTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private void testForwardThingEvent(final CreateConnection createConnection, final boolean isForwarded,
        final Signal<?> signal, final Target expectedTarget) {
    new TestKit(actorSystem) {{
        final TestKit probe = new TestKit(actorSystem);
        final ActorRef underTest =
                TestConstants.createConnectionSupervisorActor(connectionId, actorSystem,
                        conciergeForwarder,
                        (connection, conciergeForwarder, connectionActor) -> TestActor.props(probe),
                        TestConstants.dummyDittoProtocolSub(pubSubMediator, dittoProtocolSubMock), pubSubMediator);
        watch(underTest);

        // create connection
        underTest.tell(createConnection, getRef());
        expectMsgClass(CreateConnectionResponse.class);

        // wait until connection actor is subscribed otherwise the signal won't be forwarded
        expectAnySubscribe();

        underTest.tell(signal, getRef());

        if (isForwarded) {
            final OutboundSignal unmappedOutboundSignal =
                    probe.expectMsgClass(OutboundSignal.class);
            assertThat(unmappedOutboundSignal.getSource()).isEqualTo(signal);

            // check target address only due to live migration
            assertThat(unmappedOutboundSignal.getTargets().stream().map(Target::getAddress))
                    .containsExactly(expectedTarget.getAddress());
        } else {
            probe.expectNoMessage();
        }
    }};
}
 
Example 4
Source File: PersistentCacheTest.java    From ari-proxy with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
void queryReturnsExpectedValue() {
	final TestKit probe = new TestKit(system);
	final TestKit metricsService = new TestKit(system);
	final ActorRef cache = system.actorOf(Props.create(Cache.class, metricsService.getRef()), "cache");

	probe.send(cache, new UpdateCache(KEY, VALUE));

	final SetDone setDone = probe.expectMsgClass(SetDone.class);

	assertThat(setDone.getKey(), is(cache.path().name() + ":" + KEY));
	assertThat(setDone.getValue(), is(VALUE));

	final RedisUpdateTimerStart updateTimerStart = metricsService.expectMsgClass(RedisUpdateTimerStart.class);
	final RedisUpdateTimerStop updateTimerStop = metricsService.expectMsgClass(RedisUpdateTimerStop.class);

	assertThat(updateTimerStart.getContext(), is(updateTimerStop.getContext()));

	probe.send(cache, new QueryCache(KEY));

	final Option result = probe.expectMsgClass(Option.class);

	assertThat(result, is(Some(VALUE)));

	metricsService.expectNoMessage(Duration.ofMillis(100));
}
 
Example 5
Source File: BackOffActorTest.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void providesInformationIfCurrentlyInBackOff() {
    final TestKit probe = new TestKit(actorSystem);
    final ActorRef underTest = probe.childActorOf(BackOffActor.props(createBackOffConfig()));
    final String message = "I expect to receive this after backOff";


    assertIsInBackOffMode(underTest, probe, false);

    underTest.tell(BackOffActor.createBackOffWithAnswerMessage(message), probe.getRef());

    assertIsInBackOffMode(underTest, probe, true);

    // verify we receive the answer afterwards
    probe.expectNoMessage(HALF_BACK_OFF_DURATION);
    probe.expectMsg(BACK_OFF_DURATION, message);


    assertIsInBackOffMode(underTest, probe, false);
}