/** * @throws Exception If failed. */ @Test public void testPingPong() throws Exception { final AtomicInteger pingCnt = new AtomicInteger(); final AtomicInteger pongCnt = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(PING_PONG_STEPS); grid().message().localListen(null, new MessagingListenActor<String>() { @Override protected void receive(UUID nodeId, String rcvMsg) { System.out.println("Received message: '" + rcvMsg + "'"); if ("PING".equals(rcvMsg)) { pingCnt.incrementAndGet(); respond("PONG"); } else if ("PONG".equals(rcvMsg)) { pongCnt.incrementAndGet(); latch.countDown(); if (latch.getCount() > 0) respond("PING"); else stop(); } } }); grid().message().send(null, "PING"); latch.await(); assert pingCnt.intValue() == PING_PONG_STEPS; assert pongCnt.intValue() == PING_PONG_STEPS; }
/** * * @throws Exception Thrown if failed. */ @Test public void testBasicFlow() throws Exception { final AtomicInteger cnt = new AtomicInteger(0); grid().message().localListen(null, new MessagingListenActor<String>() { @Override public void receive(UUID uuid, String rcvMsg) { if ("TEST".equals(rcvMsg)) { cnt.incrementAndGet(); // "Exit" after 1st message. // Should never receive any more messages. stop(); } else { assert false : "Unknown message: " + rcvMsg; stop(); } } }); grid().message().send(null, "TEST"); // This message we should receive. // Flood it. for (int i = 0; i < 100; i++) grid().message().send(null, "TEST"); // This message should be lost... Thread.sleep(2000); assert cnt.get() == 1 : "Count is " + cnt.get(); }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { ((IgniteKernal)grid()).context().io(). removeMessageListener(GridTopic.TOPIC_COMM_USER.name()); }
final ClusterNode rmt = grid(1).localNode(); grid().message().localListen(null, new MessagingListenActor<String>() { @Override protected void receive(UUID nodeId, String rcvMsg) throws IgniteException { System.out.println("Local node received message: '" + rcvMsg + "'"); grid(1).message().localListen(null, new MessagingListenActor<String>() { @Override public void receive(UUID nodeId, String rcvMsg) { if ("RESPONSE".equals(rcvMsg)) { grid().message().send(null, "REQUEST");