Refine search
/** * Receive one message from the test actor and assert that it conforms to the * given class. Wait time is bounded by the given duration, with an * AssertionFailure being thrown in case of timeout. * * @return the received object */ public <T> T expectMsgClass(FiniteDuration max, Class<T> clazz) { return p.expectMsgClass(max, clazz); }
public void reply(Object msg) { p.lastMessage().sender().tell(msg, p.ref()); }
public JavaTestKit(ActorSystem system) { p = new TestProbe(system); }
public void forward(ActorRef actor) { actor.tell(p.lastMessage().msg(), p.lastMessage().sender()); }
@Before public void setUp() throws Exception { initialBehavior = createInitialBehaviorMock(); system = ActorSystem.apply("system1"); final ActorRef storeRef = system.registerExtension(Persistence.lookup()).snapshotStoreFor(null, ConfigFactory.empty()); probe = new TestProbe(system); storeRef.tell(probe.ref(), ActorRef.noSender()); final MemberName name = MemberName.forName("member-1"); id = FrontendIdentifier.create(name, FrontendType.forName("type-1")); mockedActor = system.actorOf(MockedActor.props(id, initialBehavior)); //handle initial actor recovery saveRequest = handleRecovery(null); }
ActorSystem system = ActorSystem.create("x"); ActorRef victim = TestProbe.apply(system).ref(); TestProbe probe = TestProbe.apply(system); probe.watch(victim); ActorRef killer = system.actorOf(Props.create(Killer.class, victim)); killer.tell("kill!", ActorRef.noSender()); probe.expectMsgClass(Terminated.class);
private void registerListeners() { for (final TestProbe listener : listeners) { notifier.tell(new RegisterRoleChangeListener(), listener.ref()); listener.expectMsgClass(RegisterRoleChangeListenerReply.class); } }
@Test public void calculatePiFor0() { TestProbe testProbe = TestProbe.apply(actorSystem); Pi.Work work = new Pi.Work(0, 0); actorRef.tell(work, testProbe.ref()); testProbe.expectMsgClass(Pi.Result.class); TestActor.Message message = testProbe.lastMessage(); Pi.Result resultMsg = (Pi.Result) message.msg(); assertEquals(0.0, resultMsg.getValue(), 0.0000000001); }
@Test public void testRecoveryAfterRestartSaveSnapshotFail() { system.stop(mockedActor); mockedActor = system.actorOf(MockedActor.props(id, initialBehavior)); probe.watch(mockedActor); probe.expectMsgClass(MockedSnapshotStore.LoadRequest.class); probe.reply(Optional.empty()); probe.expectMsgClass(MockedSnapshotStore.SaveRequest.class); probe.reply(new RuntimeException("save failed")); probe.expectMsgClass(MockedSnapshotStore.DeleteByMetadataRequest.class); probe.expectTerminated(mockedActor, TIMEOUT); }
@Test public void testMessageSliceReplyWithNoState() { try (MessageSlicer slicer = newMessageSlicer("testMessageSliceReplyWithNoState", 1000)) { MessageSliceIdentifier messageSliceId = new MessageSliceIdentifier(IDENTIFIER, slicer.getId()); slicer.handleMessage(MessageSliceReply.success(messageSliceId, 1, testProbe.ref())); final AbortSlicing abortSlicing = testProbe.expectMsgClass(AbortSlicing.class); assertEquals("Identifier", messageSliceId, abortSlicing.getIdentifier()); } }
/** * Receive one message from the test actor and assert that it equals the given * object. Wait time is bounded by the given duration, with an * AssertionFailure being thrown in case of timeout. * * @return the received object */ public <T> T expectMsgEquals(FiniteDuration max, T msg) { return p.expectMsg(max, msg); }
/** * Have the testActor watch someone (i.e. * <code>getContext().getWatch(...)</code> ). */ public ActorRef watch(ActorRef ref) { return p.watch(ref); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); system = ActorSystem.apply(); backendProbe = new TestProbe(system); contextProbe = new TestProbe(system); context = new ClientActorContext(contextProbe.ref(), PERSISTENCE_ID, system, CLIENT_ID, AccessClientUtil.newMockClientActorConfig()); replyToProbe = new TestProbe(system); connection = createConnection(); }
/** * Assert that the given ActorRef is Terminated within the specified time. * Don't forget to 'watch' it first! */ public Terminated expectTerminated(Duration max, ActorRef target) { return p.expectTerminated(target, max); }
/** * Receive one message from the internal queue of the TestActor. If the given duration is zero, * the queue is polled (non-blocking). * * <p>This method does NOT automatically scale its Duration parameter! */ public Object receiveOne(Duration max) { return p.receiveOne(max); }
/** * Assert that no message is received for the specified time. */ public void expectNoMsg(FiniteDuration max) { p.expectNoMsg(max); }
/** * Query queue status. */ public boolean msgAvailable() { return p.msgAvailable(); }
private void assertTransmit(final Request<?, ?> expected, final long sequence) { assertTrue(mockActor.msgAvailable()); assertRequestEquals(expected, sequence, mockActor.receiveOne(FiniteDuration.apply(5, TimeUnit.SECONDS))); }
public ActorRef getLastSender() { return p.lastMessage().sender(); }