use of org.apache.ignite.IgniteMessaging in project ignite by apache.
the class IgniteMessagingWithClientTest method testMessageSendWithClientJoin.
/**
* @throws Exception If failed.
*/
@Test
public void testMessageSendWithClientJoin() throws Exception {
startGrid(0);
Ignite ignite1 = startGrid(1);
ClusterGroup rmts = ignite1.cluster().forRemotes();
IgniteMessaging msg = ignite1.message(rmts);
msg.localListen(TOPIC.ORDERED, new LocalListener());
msg.remoteListen(TOPIC.ORDERED, new RemoteListener());
final AtomicBoolean stop = new AtomicBoolean();
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
int iter = 0;
while (!stop.get()) {
if (iter % 10 == 0)
log.info("Client start/stop iteration: " + iter);
iter++;
try (Ignite ignite = startClientGrid(2)) {
assertTrue(ignite.configuration().isClientMode());
}
}
return null;
}
}, 1, "client-start-stop");
try {
long stopTime = U.currentTimeMillis() + 30_000;
int iter = 0;
while (System.currentTimeMillis() < stopTime) {
try {
ignite1.message(rmts).sendOrdered(TOPIC.ORDERED, Integer.toString(iter), 0);
} catch (IgniteException e) {
log.info("Message send failed: " + e);
}
iter++;
if (iter % 100 == 0)
Thread.sleep(5);
}
} finally {
stop.set(true);
}
fut.get();
}
use of org.apache.ignite.IgniteMessaging in project ignite by apache.
the class GridMarshallerAbstractTest method testMessaging.
/**
* @throws Exception If failed.
*/
@Test
public void testMessaging() throws Exception {
IgniteConfiguration cfg = optimize(getConfiguration("g1"));
try (Ignite g1 = G.start(cfg)) {
IgniteMessaging messaging = message(grid().cluster().forNode(g1.cluster().localNode()));
messaging.send(null, "test");
GridMarshallerTestBean inBean = newTestBean(messaging);
byte[] buf = marshal(inBean);
GridMarshallerTestBean outBean = unmarshal(buf);
assert inBean.getObjectField() != null;
assert outBean.getObjectField() != null;
assert inBean.getObjectField().getClass().equals(IgniteMessagingImpl.class);
assert outBean.getObjectField().getClass().equals(IgniteMessagingImpl.class);
assert inBean != outBean;
assert inBean.equals(outBean);
ClusterGroup inPrj = messaging.clusterGroup();
ClusterGroup outPrj = ((IgniteMessaging) outBean.getObjectField()).clusterGroup();
assert inPrj.getClass().equals(outPrj.getClass());
assert F.eqNotOrdered(inPrj.nodes(), outPrj.nodes());
outBean.checkNullResources();
}
}
use of org.apache.ignite.IgniteMessaging in project ignite by apache.
the class TcpClientDiscoverySpiSelfTest method testDataExchangeFromServer2.
/**
* @throws Exception If failed.
*/
@Test
public void testDataExchangeFromServer2() throws Exception {
startServerNodes(2);
IgniteMessaging msg = grid("server-1").message();
UUID id = msg.remoteListen(null, new MessageListener());
try {
startClientNodes(1);
assertEquals(G.ignite("server-0").cluster().localNode().id(), ((TcpDiscoveryNode) G.ignite("client-0").cluster().localNode()).clientRouterNodeId());
checkNodes(2, 1);
msgLatch = new CountDownLatch(3);
msg.send(null, "Message");
await(msgLatch);
} finally {
msg.stopRemoteListen(id);
}
}
use of org.apache.ignite.IgniteMessaging in project ignite by apache.
the class TcpClientDiscoverySpiSelfTest method testDataExchange.
/**
* @param masterName Node name
* @throws Exception If failed.
*/
private void testDataExchange(String masterName) throws Exception {
startServerNodes(2);
startClientNodes(2);
checkNodes(2, 2);
IgniteMessaging msg = grid(masterName).message();
UUID id = msg.remoteListen(null, new MessageListener());
try {
msgLatch = new CountDownLatch(2);
msg.send(null, "Message 1");
await(msgLatch);
startServerNodes(1);
startClientNodes(1);
checkNodes(3, 3);
msgLatch = new CountDownLatch(3);
msg.send(null, "Message 2");
await(msgLatch);
} finally {
msg.stopRemoteListen(id);
}
}
use of org.apache.ignite.IgniteMessaging in project ignite by apache.
the class GridCacheReplicatedPreloadSelfTest method testExternalClassesAtMessage.
/**
* @throws Exception If test failed.
*/
@Test
public void testExternalClassesAtMessage() throws Exception {
try {
useExtClassLoader = true;
disableP2p = true;
final Class cls = (Class) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentExternalizableTestValue");
Ignite g1 = startGrid(1);
startGrid(2);
IgniteMessaging rmtMsg = g1.message();
latch = new CountDownLatch(2);
rmtMsg.remoteListen("MyOrderedTopic", new MessageListener());
Object o = cls.newInstance();
o.toString();
rmtMsg.send("MyOrderedTopic", o);
rmtMsg.sendOrdered("MyOrderedTopic", o, 0);
latch.await();
// Custom topic.
final Class cls2 = (Class) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentTestEnumValue");
Object topic = cls2.getEnumConstants()[0];
latch = new CountDownLatch(2);
rmtMsg.remoteListen(topic, new MessageListener());
rmtMsg.send(topic, topic);
rmtMsg.sendOrdered(topic, topic, 0);
latch.await();
} finally {
useExtClassLoader = false;
disableP2p = false;
}
}
Aggregations