use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class GridMessagingSelfTest method testSendReceiveMessageWithStringTopic.
/**
* Tests simple message sending-receiving with string topic.
*
* @throws Exception If error occurs.
*/
@Test
public void testSendReceiveMessageWithStringTopic() throws Exception {
final Collection<Object> rcvMsgs = new GridConcurrentHashSet<>();
// to make it modifiable
final AtomicBoolean error = new AtomicBoolean(false);
final CountDownLatch rcvLatch = new CountDownLatch(3);
ignite1.message().localListen(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 + ", topic=" + S_TOPIC_1 + ']');
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
if (!MSG_1.equals(msg)) {
log.error("Unexpected message " + msg + " for topic: " + S_TOPIC_1);
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
ignite1.message().localListen(S_TOPIC_2, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=" + S_TOPIC_2 + ']');
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
if (!MSG_2.equals(msg)) {
log.error("Unexpected message " + msg + " for topic: " + S_TOPIC_2);
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
ignite1.message().localListen(null, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=default]");
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
if (!MSG_3.equals(msg)) {
log.error("Unexpected message " + msg + " for topic: default");
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
ClusterGroup rNode1 = ignite1.cluster().forLocal();
message(rNode1).send(S_TOPIC_1, MSG_1);
message(rNode1).send(S_TOPIC_2, MSG_2);
message(rNode1).send(null, MSG_3);
assertTrue(rcvLatch.await(3, TimeUnit.SECONDS));
assertFalse(error.get());
assertTrue(rcvMsgs.contains(MSG_1));
assertTrue(rcvMsgs.contains(MSG_2));
assertTrue(rcvMsgs.contains(MSG_3));
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class GridMessagingSelfTest method testRemoteListen.
/**
* Tests simple message sending-receiving with the use of
* remoteListen() method.
*
* @throws Exception If error occurs.
*/
@Test
public void testRemoteListen() throws Exception {
final Collection<Object> rcvMsgs = new GridConcurrentHashSet<>();
rcvLatch = new CountDownLatch(4);
ignite2.message().remoteListen(null, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
// Includes node from grid2.
ClusterGroup prj2 = ignite1.cluster().forRemotes();
message(prj2).send(null, MSG_1);
message(prj2).send(null, MSG_2);
message(ignite2.cluster().forLocal()).send(null, MSG_3);
// We should get only 3 message.
assertFalse(rcvLatch.await(3, TimeUnit.SECONDS));
assertTrue(rcvMsgs.contains(MSG_1));
assertTrue(rcvMsgs.contains(MSG_2));
assertTrue(rcvMsgs.contains(MSG_3));
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class GridMessagingSelfTest method testRemoteListenWithIntTopic.
/**
* Tests simple message sending-receiving with the use of
* remoteListen() method and topics.
*
* @throws Exception If error occurs.
*/
@Test
public void testRemoteListenWithIntTopic() throws Exception {
final Collection<Object> rcvMsgs = new GridConcurrentHashSet<>();
// to make it modifiable
final AtomicBoolean error = new AtomicBoolean(false);
rcvLatch = new CountDownLatch(3);
ignite2.message().remoteListen(I_TOPIC_1, new P2<UUID, Object>() {
@IgniteInstanceResource
private transient Ignite g;
@Override
public boolean apply(UUID nodeId, Object msg) {
assertEquals(ignite2, g);
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=" + I_TOPIC_1 + ']');
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
if (!MSG_1.equals(msg)) {
log.error("Unexpected message " + msg + " for topic: " + I_TOPIC_1);
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
ignite2.message().remoteListen(I_TOPIC_2, new P2<UUID, Object>() {
@IgniteInstanceResource
private transient Ignite g;
@Override
public boolean apply(UUID nodeId, Object msg) {
assertEquals(ignite2, g);
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=" + I_TOPIC_2 + ']');
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
if (!MSG_2.equals(msg)) {
log.error("Unexpected message " + msg + " for topic: " + I_TOPIC_2);
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
ignite2.message().remoteListen(null, new P2<UUID, Object>() {
@IgniteInstanceResource
private transient Ignite g;
@Override
public boolean apply(UUID nodeId, Object msg) {
assertEquals(ignite2, g);
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=default]");
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
if (!MSG_3.equals(msg)) {
log.error("Unexpected message " + msg + " for topic: default");
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
// Includes node from grid2.
ClusterGroup prj2 = ignite1.cluster().forRemotes();
message(prj2).send(I_TOPIC_1, MSG_1);
message(prj2).send(I_TOPIC_2, MSG_2);
message(prj2).send(null, MSG_3);
assertTrue(rcvLatch.await(3, TimeUnit.SECONDS));
assertFalse(error.get());
assertTrue(rcvMsgs.contains(MSG_1));
assertTrue(rcvMsgs.contains(MSG_2));
assertTrue(rcvMsgs.contains(MSG_3));
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class IgniteFailoverAbstractBenchmark method onException.
/**
* {@inheritDoc}
*/
@Override
public void onException(Throwable e) {
// Proceess only the first exception to prevent a multiple printing of a full thread dump.
if (firtsExProcessed.compareAndSet(false, true)) {
// Debug info on current client.
println("Full thread dump of the current node below.");
U.dumpThreads(null);
println("");
((IgniteKernal) ignite()).dumpDebugInfo();
// Debug info on servers.
Ignite ignite = ignite();
ClusterGroup srvs = ignite.cluster().forServers();
ignite.compute(srvs).broadcastAsync(new ThreadDumpPrinterTask(ignite.cluster().localNode().id(), e)).get(10_000);
}
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class TcpCommunicationStatisticsTest method testStatistics.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("ConstantConditions")
@Test
public void testStatistics() throws Exception {
startGrids(2);
try {
Object node0consistentId = grid(0).localNode().consistentId();
Object node1consistentId = grid(1).localNode().consistentId();
String node0regName = MetricUtils.metricName(COMMUNICATION_METRICS_GROUP_NAME, node0consistentId.toString());
String node1regName = MetricUtils.metricName(COMMUNICATION_METRICS_GROUP_NAME, node1consistentId.toString());
// Send custom message from node0 to node1.
grid(0).context().io().sendToGridTopic(grid(1).cluster().localNode(), GridTopic.TOPIC_IO_TEST, new GridTestMessage(), GridIoPolicy.PUBLIC_POOL);
latch.await(10, TimeUnit.SECONDS);
ClusterGroup clusterGrpNode1 = grid(0).cluster().forNodeId(grid(1).localNode().id());
// Send job from node0 to node1.
grid(0).compute(clusterGrpNode1).call(new IgniteCallable<Boolean>() {
@Override
public Boolean call() throws Exception {
return Boolean.TRUE;
}
});
synchronized (mux) {
TcpCommunicationSpiMBean mbean0 = mbean(0);
TcpCommunicationSpiMBean mbean1 = mbean(1);
Map<UUID, Long> msgsSentByNode0 = mbean0.getSentMessagesByNode();
Map<UUID, Long> msgsSentByNode1 = mbean1.getSentMessagesByNode();
Map<UUID, Long> msgsReceivedByNode0 = mbean0.getReceivedMessagesByNode();
Map<UUID, Long> msgsReceivedByNode1 = mbean1.getReceivedMessagesByNode();
UUID nodeId0 = grid(0).localNode().id();
UUID nodeId1 = grid(1).localNode().id();
assertEquals(msgsReceivedByNode0.get(nodeId1).longValue(), mbean0.getReceivedMessagesCount());
assertEquals(msgsReceivedByNode1.get(nodeId0).longValue(), mbean1.getReceivedMessagesCount());
assertEquals(msgsSentByNode0.get(nodeId1).longValue(), mbean0.getSentMessagesCount());
assertEquals(msgsSentByNode1.get(nodeId0).longValue(), mbean1.getSentMessagesCount());
assertEquals(mbean0.getSentMessagesCount(), mbean1.getReceivedMessagesCount());
assertEquals(mbean1.getSentMessagesCount(), mbean0.getReceivedMessagesCount());
Map<String, Long> msgsSentByType0 = mbean0.getSentMessagesByType();
Map<String, Long> msgsSentByType1 = mbean1.getSentMessagesByType();
Map<String, Long> msgsReceivedByType0 = mbean0.getReceivedMessagesByType();
Map<String, Long> msgsReceivedByType1 = mbean1.getReceivedMessagesByType();
// Node0 sent exactly the same types and count of messages as node1 received.
assertEquals(msgsSentByType0, msgsReceivedByType1);
// Node1 sent exactly the same types and count of messages as node0 received.
assertEquals(msgsSentByType1, msgsReceivedByType0);
assertEquals(1, msgsSentByType0.get(GridTestMessage.class.getName()).longValue());
assertEquals(1, msgsReceivedByType1.get(GridTestMessage.class.getName()).longValue());
MetricRegistry mreg0 = grid(0).context().metric().registry(node1regName);
MetricRegistry mreg1 = grid(1).context().metric().registry(node0regName);
LongAdderMetric sentMetric = mreg0.findMetric(SENT_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME);
assertNotNull(sentMetric);
assertEquals(mbean0.getSentMessagesCount(), sentMetric.value());
LongAdderMetric rcvMetric = mreg1.findMetric(RECEIVED_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME);
assertNotNull(rcvMetric);
assertEquals(mbean1.getReceivedMessagesCount(), rcvMetric.value());
stopGrid(1);
mreg0 = grid(0).context().metric().registry(node1regName);
sentMetric = mreg0.findMetric(SENT_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME);
// Automatically generated by MetricRegistryCreationListener.
assertNotNull(sentMetric);
assertEquals(0, sentMetric.value());
}
} finally {
stopAllGrids();
}
}
Aggregations