use of org.apache.ignite.spi.communication.GridTestMessage 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();
}
}
use of org.apache.ignite.spi.communication.GridTestMessage in project ignite by apache.
the class GridTcpCommunicationSpiLanLoadTest method testRunSender.
/**
* @throws Exception If failed.
*/
@Test
public void testRunSender() throws Exception {
reject = true;
info(">>> Starting send to remote node multithreaded test. <<<");
final AtomicInteger cntr = new AtomicInteger();
final int msgCnt = 10000;
long start = System.currentTimeMillis();
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
@Override
public void run() {
try {
while (cntr.getAndIncrement() < msgCnt) {
GridTestMessage msg = new GridTestMessage(locNode.id(), msgId.getAndIncrement(), 0);
msg.payload(new byte[13 * 1024]);
spi.sendMessage(remoteNode, msg);
}
} catch (IgniteException e) {
fail("Unable to send message: " + e.getMessage());
}
}
}, THREAD_CNT, "message-sender");
fut.get();
info(">>> Sent all messages in " + (System.currentTimeMillis() - start) + " milliseconds");
assertEquals("Invalid count of messages was sent", msgCnt, msgId.get());
U.sleep(IDLE_CONN_TIMEOUT * 2);
}
use of org.apache.ignite.spi.communication.GridTestMessage in project ignite by apache.
the class GridTcpCommunicationSpiConfigSelfTest method initializeSpi.
/**
* Initializes TcpCommunicationSpi with given context, node, logger and clientMode flag.
*/
private TcpCommunicationSpi initializeSpi(GridSpiTestContext ctx, GridTestNode node, IgniteLogger log, boolean clientMode) throws Exception {
TcpCommunicationSpi spi = new TcpCommunicationSpi();
spi.setLocalPort(GridTestUtils.getNextCommPort(getClass()));
spi.setIdleConnectionTimeout(2000);
IgniteConfiguration cfg = new IgniteConfiguration().setGridLogger(log).setClientMode(clientMode);
IgniteTestResources rsrcs = new IgniteTestResources(cfg);
resourcesToClean.add(rsrcs);
cfg.setMBeanServer(rsrcs.getMBeanServer());
node.setId(rsrcs.getNodeId());
MessageFactoryProvider testMsgFactory = factory -> factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
ctx.setLocalNode(node);
rsrcs.inject(spi);
spi.spiStart(getTestIgniteInstanceName() + node.order());
node.setAttributes(spi.getNodeAttributes());
node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
return spi;
}
use of org.apache.ignite.spi.communication.GridTestMessage in project ignite by apache.
the class GridTcpCommunicationSpiRecoveryAckSelfTest method startSpis.
/**
* @param ackCnt Recovery acknowledgement count.
* @param idleTimeout Idle connection timeout.
* @param queueLimit Message queue limit.
* @throws Exception If failed.
*/
private void startSpis(int ackCnt, int idleTimeout, int queueLimit) throws Exception {
spis.clear();
nodes.clear();
spiRsrcs.clear();
Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
timeoutProcessor.start();
timeoutProcessor.onKernalStart(true);
for (int i = 0; i < SPI_CNT; i++) {
TcpCommunicationSpi spi = getSpi(ackCnt, idleTimeout, queueLimit);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
GridSpiTestContext ctx = initSpiContext();
MessageFactoryProvider testMsgFactory = new MessageFactoryProvider() {
@Override
public void registerAll(IgniteMessageFactory factory) {
factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
}
};
ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
ctx.setLocalNode(node);
ctx.timeoutProcessor(timeoutProcessor);
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
spi.setListener(new TestListener());
node.order(i);
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
node.setAttributes(spi.getNodeAttributes());
spis.add(spi);
spi.onContextInitialized(ctx);
ctxs.put(node, ctx);
}
// For each context set remote nodes.
for (Map.Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
for (ClusterNode n : nodes) {
if (!n.equals(e.getKey()))
e.getValue().remoteNodes().add(n);
}
}
}
use of org.apache.ignite.spi.communication.GridTestMessage in project ignite by apache.
the class IgniteTcpCommunicationRecoveryAckClosureSelfTest method checkOverflow.
/**
* @throws Exception If failed.
*/
private void checkOverflow() throws Exception {
TcpCommunicationSpi spi0 = spis.get(0);
TcpCommunicationSpi spi1 = spis.get(1);
ClusterNode node0 = nodes.get(0);
ClusterNode node1 = nodes.get(1);
// Await time to close the session by queue overflow.
final int awaitTime = 5_000;
// Check that session will not be closed by idle timeout because expected close by queue overflow.
assertTrue(spi0.getIdleConnectionTimeout() > awaitTime);
final GridNioServer<?> srv1 = ((GridNioServerWrapper) U.field(spi1, "nioSrvWrapper")).nio();
// For prevent session close by write timeout.
srv1.writeTimeout(60_000);
final AtomicInteger ackMsgs = new AtomicInteger(0);
IgniteInClosure<IgniteException> ackC = new CI1<IgniteException>() {
@Override
public void apply(IgniteException o) {
assert o == null;
ackMsgs.incrementAndGet();
}
};
int msgId = 0;
// Send message to establish connection.
spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0), ackC);
int sentMsgs = 1;
// Prevent node1 from send
GridTestUtils.setFieldValue(srv1, "skipWrite", true);
final GridNioSession ses0 = communicationSession(spi0);
int queueLimit = ses0.outRecoveryDescriptor().queueLimit();
for (int i = sentMsgs; i < queueLimit; i++) {
try {
spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0), ackC);
sentMsgs++;
} catch (IgniteSpiException e) {
log.info("Send error [err=" + e + ", sentMsgs=" + sentMsgs + ']');
break;
}
}
// Wait when session is closed because of queue overflow.
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return ses0.closeTime() != 0;
}
}, awaitTime);
assertTrue("Failed to wait for session close", ses0.closeTime() != 0);
GridTestUtils.setFieldValue(srv1, "skipWrite", false);
// It to gain all acks since acks have batch nature.
int cnt = 100 - sentMsgs % spi0.getAckSendThreshold();
for (int i = 0; i < cnt; i++) spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0), ackC);
final int expMsgs = sentMsgs + cnt;
final TestListener lsnr = (TestListener) spi1.getListener();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return lsnr.rcvCnt.get() >= expMsgs;
}
}, 5000);
assertEquals(expMsgs, lsnr.rcvCnt.get());
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return expMsgs == ackMsgs.get();
}
}, 5000);
assertEquals(expMsgs, ackMsgs.get());
}
Aggregations