Search in sources :

Example 11 with GridTestMessage

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();
    }
}
Also used : GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteException(org.apache.ignite.IgniteException) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 12 with GridTestMessage

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);
}
Also used : GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test)

Example 13 with GridTestMessage

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;
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) IgniteSystemProperties.getBoolean(org.apache.ignite.IgniteSystemProperties.getBoolean) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) ATTR_MACS(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MACS) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteLogger(org.apache.ignite.IgniteLogger) IgniteEx(org.apache.ignite.internal.IgniteEx) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) ArrayList(java.util.ArrayList) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) InetAddress(java.net.InetAddress) IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES(org.apache.ignite.IgniteSystemProperties.IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest) IgniteUtils.spiAttribute(org.apache.ignite.internal.util.IgniteUtils.spiAttribute) NullLogger(org.apache.ignite.logger.NullLogger) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Objects.requireNonNull(java.util.Objects.requireNonNull) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) Objects.isNull(java.util.Objects.isNull) ATTR_HOST_NAMES(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.ATTR_HOST_NAMES) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) F(org.apache.ignite.internal.util.typedef.F) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Test(org.junit.Test) GridTestUtils.getFreeCommPort(org.apache.ignite.testframework.GridTestUtils.getFreeCommPort) InetSocketAddress(java.net.InetSocketAddress) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) GridSpiAbstractConfigTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractConfigTest) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) Message(org.apache.ignite.plugin.extensions.communication.Message) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory)

Example 14 with GridTestMessage

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);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) IgniteMessageFactory(org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory) HashMap(java.util.HashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteMessageFactory(org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with GridTestMessage

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());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) GridNioServerWrapper(org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper) CI1(org.apache.ignite.internal.util.typedef.CI1) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Aggregations

GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)22 ClusterNode (org.apache.ignite.cluster.ClusterNode)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 Test (org.junit.Test)12 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)10 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)10 IgniteException (org.apache.ignite.IgniteException)9 GridSpiAbstractTest (org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest)9 Message (org.apache.ignite.plugin.extensions.communication.Message)8 GridNioServerWrapper (org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper)8 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)7 GridSpiTestContext (org.apache.ignite.testframework.GridSpiTestContext)7 GridTestNode (org.apache.ignite.testframework.GridTestNode)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 GridIoMessageFactory (org.apache.ignite.internal.managers.communication.GridIoMessageFactory)6 IgniteMessageFactoryImpl (org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl)6 MessageFactory (org.apache.ignite.plugin.extensions.communication.MessageFactory)6 MessageFactoryProvider (org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider)6 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)6 GridSpiTest (org.apache.ignite.testframework.junits.spi.GridSpiTest)6