use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridP2PSameClassLoaderSelfTest method processTest.
/**
* Test.
* @throws Exception if error occur
*/
@SuppressWarnings({ "unchecked" })
private void processTest() throws Exception {
try {
final Ignite ignite1 = startGrid(1);
Ignite ignite2 = startGrid(2);
Ignite ignite3 = startGrid(3);
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return ignite1.cluster().nodes().size() == 3;
}
}, 20000L);
Class task1 = CLASS_LOADER.loadClass(TEST_TASK1_NAME);
Class task2 = CLASS_LOADER.loadClass(TEST_TASK2_NAME);
// Execute task1 and task2 from node1 on node2 and make sure that they reuse same class loader on node2.
Integer res1 = (Integer) ignite1.compute().execute(task1, ignite2.cluster().localNode().id());
Integer res2 = (Integer) ignite1.compute().execute(task2, ignite2.cluster().localNode().id());
// Class loaders are same
assert res1.equals(res2);
Integer res3 = (Integer) ignite3.compute().execute(task1, ignite2.cluster().localNode().id());
Integer res4 = (Integer) ignite3.compute().execute(task2, ignite2.cluster().localNode().id());
assert res3.equals(res4);
} finally {
stopGrid(1);
stopGrid(2);
stopGrid(3);
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridListenActorSelfTest method testRespondToRemote.
/**
* Testing {@link org.apache.ignite.messaging.MessagingListenActor#respond(UUID, Object)} method.
*
* @throws Exception If failed.
*/
public void testRespondToRemote() throws Exception {
startGrid(1);
try {
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 + "'");
respond(rmt.id(), "RESPONSE");
}
});
final AtomicInteger cnt = new AtomicInteger();
// Response listener
grid(1).message().localListen(null, new MessagingListenActor<String>() {
@Override
public void receive(UUID nodeId, String rcvMsg) {
if ("RESPONSE".equals(rcvMsg)) {
System.out.println("Remote node received message: '" + rcvMsg + "'");
cnt.incrementAndGet();
}
}
});
grid().message().send(null, "REQUEST");
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return cnt.intValue() == 1;
}
}, getTestTimeout());
} finally {
stopGrid(1);
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteDbPutGetAbstractTest method checkEmpty.
private void checkEmpty(final GridCacheAdapter internalCache, final Object key) throws Exception {
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return internalCache.peekEx(key) == null;
}
}, 5000);
assertNull(internalCache.peekEx(key));
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridMessagingSelfTest method testAsyncOld.
/**
* @throws Exception If failed.
*/
public void testAsyncOld() throws Exception {
final AtomicInteger msgCnt = new AtomicInteger();
TestTcpDiscoverySpi discoSpi = (TestTcpDiscoverySpi) ignite2.configuration().getDiscoverySpi();
assertFalse(ignite2.message().isAsync());
final IgniteMessaging msg = ignite2.message().withAsync();
assertTrue(msg.isAsync());
assertFalse(ignite2.message().isAsync());
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
msg.future();
return null;
}
}, IllegalStateException.class, null);
discoSpi.blockCustomEvent();
final String topic = "topic";
UUID id = msg.remoteListen(topic, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
System.out.println(Thread.currentThread().getName() + " Listener received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
msgCnt.incrementAndGet();
return true;
}
});
Assert.assertNull(id);
IgniteFuture<UUID> starFut = msg.future();
Assert.assertNotNull(starFut);
U.sleep(500);
Assert.assertFalse(starFut.isDone());
discoSpi.stopBlock();
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
msg.future();
return null;
}
}, IllegalStateException.class, null);
id = starFut.get();
Assert.assertNotNull(id);
Assert.assertTrue(starFut.isDone());
discoSpi.blockCustomEvent();
message(ignite1.cluster().forRemotes()).send(topic, "msg1");
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return msgCnt.get() > 0;
}
}, 5000);
assertEquals(1, msgCnt.get());
msg.stopRemoteListen(id);
IgniteFuture<?> stopFut = msg.future();
Assert.assertNotNull(stopFut);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
msg.future();
return null;
}
}, IllegalStateException.class, null);
U.sleep(500);
Assert.assertFalse(stopFut.isDone());
discoSpi.stopBlock();
stopFut.get();
Assert.assertTrue(stopFut.isDone());
message(ignite1.cluster().forRemotes()).send(topic, "msg2");
U.sleep(1000);
assertEquals(1, msgCnt.get());
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridMessagingSelfTest method testStopRemoteListen.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("TooBroadScope")
public void testStopRemoteListen() throws Exception {
final AtomicInteger msgCnt1 = new AtomicInteger();
final AtomicInteger msgCnt2 = new AtomicInteger();
final AtomicInteger msgCnt3 = new AtomicInteger();
final String topic1 = null;
final String topic2 = "top2";
final String topic3 = "top3";
UUID id1 = ignite2.message().remoteListen(topic1, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
System.out.println(Thread.currentThread().getName() + " Listener1 received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
msgCnt1.incrementAndGet();
return true;
}
});
UUID id2 = ignite2.message().remoteListen(topic2, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
System.out.println(Thread.currentThread().getName() + " Listener2 received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
msgCnt2.incrementAndGet();
return true;
}
});
UUID id3 = ignite2.message().remoteListen(topic3, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
System.out.println(Thread.currentThread().getName() + " Listener3 received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
msgCnt3.incrementAndGet();
return true;
}
});
message(ignite1.cluster().forRemotes()).send(topic1, "msg1-1");
message(ignite1.cluster().forRemotes()).send(topic2, "msg1-2");
message(ignite1.cluster().forRemotes()).send(topic3, "msg1-3");
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return msgCnt1.get() > 0 && msgCnt2.get() > 0 && msgCnt3.get() > 0;
}
}, 5000);
assertEquals(1, msgCnt1.get());
assertEquals(1, msgCnt2.get());
assertEquals(1, msgCnt3.get());
ignite2.message().stopRemoteListen(id2);
message(ignite1.cluster().forRemotes()).send(topic1, "msg2-1");
message(ignite1.cluster().forRemotes()).send(topic2, "msg2-2");
message(ignite1.cluster().forRemotes()).send(topic3, "msg2-3");
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return msgCnt1.get() > 1 && msgCnt3.get() > 1;
}
}, 5000);
assertEquals(2, msgCnt1.get());
assertEquals(1, msgCnt2.get());
assertEquals(2, msgCnt3.get());
// Try remove one more time.
ignite2.message().stopRemoteListen(id2);
ignite2.message().stopRemoteListen(id1);
ignite2.message().stopRemoteListen(id3);
message(ignite1.cluster().forRemotes()).send(topic1, "msg3-1");
message(ignite1.cluster().forRemotes()).send(topic2, "msg3-2");
message(ignite1.cluster().forRemotes()).send(topic3, "msg3-3");
U.sleep(1000);
assertEquals(2, msgCnt1.get());
assertEquals(1, msgCnt2.get());
assertEquals(2, msgCnt3.get());
}
Aggregations