@Test public void testReceiveCancelRequestNotify() { String initialRequestId = "SomeRequest"; Message longRunningMsg = new Message(); longRunningMsg.setFrom("Eve"); longRunningMsg.setTo("SantaClaus"); longRunningMsg.setRequestId(initialRequestId); DocumentQuery query = getQuery(40000, "Dummy"); DocumentQueryAsk ask = new DocumentQueryAsk(query, null); longRunningMsg.setContent(ask); getLogger().info("First message"); agent.receive(longRunningMsg); // Wait a bit until the request is created. new RunningHandlerCountCheck(agent, 1).assertStaysOkay("1", 2000, 10); // Now let the LongRunningMockRequestHandler run some time sleep(2000); // Now send the cancel message Message cancelMsg = new Message(); cancelMsg.setFrom("Eve"); cancelMsg.setTo("SantaClaus"); cancelMsg.setRequestId("SomeRequest2"); cancelMsg.setContent(new CancelRequestNotify(initialRequestId)); getLogger().info("Second message"); agent.receive(cancelMsg); // Wait until no handlers new RunningHandlerCountCheck(agent, 0).assertGetsOkay("2", 2000, 10); Assert.assertEquals( "[From: SantaClaus / To: Eve / Request: SomeRequest / Message: {DocumentQueryStoredTell {DataList []}}]", // agent.getMessagesSent().toString()); }
@Test public void testUnhandledMessage() { Message msg = new Message(); msg.setFrom("SantaClaus"); msg.setTo(AGENT_NAME); msg.setRequestId("SomeRequest"); msg.setContent(new RegisterAsk("")); agent.receive(msg); sleep(1 * WAITMS); Assert.assertEquals("No message should have been sent", 0, agent.getMessagesSent().size()); }
@Test public void testReceiveAliveAsk() { Message msg = new Message(); msg.setFrom("SantaClaus"); msg.setTo(AGENT_NAME); msg.setRequestId("SomeRequest"); msg.setContent(new AliveAsk()); agent.receive(msg); (new AssertWaiter() { @Override protected boolean isConditionMet() { System.out.println(agent.getMessagesSent().toString()); return agent.getMessagesSent().toString().contains("AliveTell"); } }) .assertGetsOkay("Tell sent", 1 * WAITMS, 50); }