use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class GridMessagingSelfTest method testRemoteListenOrderedMessages.
/**
* Tests simple message sending-receiving with the use of
* remoteListen() method.
*
* @throws Exception If error occurs.
*/
@Test
public void testRemoteListenOrderedMessages() throws Exception {
List<TestMessage> msgs = Arrays.asList(new TestMessage(MSG_1), new TestMessage(MSG_2, 3000), new TestMessage(MSG_3));
final Collection<Object> rcvMsgs = new ConcurrentLinkedDeque<>();
// to make it modifiable
final AtomicBoolean error = new AtomicBoolean(false);
rcvLatch = new CountDownLatch(3);
ignite2.message().remoteListen(S_TOPIC_1, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
// Includes node from grid2.
ClusterGroup prj2 = ignite1.cluster().forRemotes();
for (TestMessage msg : msgs) message(prj2).sendOrdered(S_TOPIC_1, msg, 15000);
assertTrue(rcvLatch.await(6, TimeUnit.SECONDS));
assertFalse(error.get());
assertEquals(msgs, Arrays.asList(rcvMsgs.toArray()));
}
use of org.apache.ignite.cluster.ClusterGroup 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.cluster.ClusterGroup 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.cluster.ClusterGroup in project ignite by apache.
the class GridMarshallerAbstractTest method testEvents.
/**
* @throws Exception If failed.
*/
@Test
public void testEvents() throws Exception {
IgniteConfiguration cfg = optimize(getConfiguration("g1"));
try (Ignite g1 = G.start(cfg)) {
IgniteEvents evts = events(grid().cluster().forNode(g1.cluster().localNode()));
evts.localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event gridEvt) {
return true;
}
}, EVTS_CACHE);
grid().cache(DEFAULT_CACHE_NAME).put(1, 1);
GridMarshallerTestBean inBean = newTestBean(evts);
byte[] buf = marshal(inBean);
GridMarshallerTestBean outBean = unmarshal(buf);
assert inBean.getObjectField() != null;
assert outBean.getObjectField() != null;
assert inBean.getObjectField().getClass().equals(IgniteEventsImpl.class);
assert outBean.getObjectField().getClass().equals(IgniteEventsImpl.class);
assert inBean != outBean;
assert inBean.equals(outBean);
ClusterGroup inPrj = evts.clusterGroup();
ClusterGroup outPrj = ((IgniteEvents) outBean.getObjectField()).clusterGroup();
assert inPrj.getClass().equals(outPrj.getClass());
assert F.eqNotOrdered(inPrj.nodes(), outPrj.nodes());
outBean.checkNullResources();
}
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class GridMarshallerAbstractTest method testCompute.
/**
* @throws Exception If failed.
*/
@Test
public void testCompute() throws Exception {
IgniteConfiguration cfg = optimize(getConfiguration("g1"));
try (Ignite g1 = G.start(cfg)) {
IgniteCompute compute = compute(grid().cluster().forNode(g1.cluster().localNode()));
compute.run(new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
GridMarshallerTestBean inBean = newTestBean(compute);
byte[] buf = marshal(inBean);
GridMarshallerTestBean outBean = unmarshal(buf);
assert inBean.getObjectField() != null;
assert outBean.getObjectField() != null;
assert inBean.getObjectField().getClass().equals(IgniteComputeImpl.class);
assert outBean.getObjectField().getClass().equals(IgniteComputeImpl.class);
assert inBean != outBean;
assert inBean.equals(outBean);
ClusterGroup inPrj = compute.clusterGroup();
ClusterGroup outPrj = ((IgniteCompute) outBean.getObjectField()).clusterGroup();
assert inPrj.getClass().equals(outPrj.getClass());
assert F.eqNotOrdered(inPrj.nodes(), outPrj.nodes());
outBean.checkNullResources();
}
}
Aggregations