Search in sources :

Example 1 with GridTestMessage

use of org.apache.ignite.spi.communication.GridTestMessage in project ignite by apache.

the class GridTcpCommunicationSpiLanTest method testRunSender.

/**
 * @throws Exception If failed.
 */
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)

Example 2 with GridTestMessage

use of org.apache.ignite.spi.communication.GridTestMessage in project ignite by apache.

the class IgniteTcpCommunicationRecoveryAckClosureSelfTest 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);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        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);
        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 3 with GridTestMessage

use of org.apache.ignite.spi.communication.GridTestMessage in project ignite by apache.

the class GridTcpCommunicationSpiConcurrentConnectSelfTest method startSpis.

/**
 * @param lsnr Message listener.
 * @throws Exception If failed.
 */
private void startSpis(MessageListener lsnr) 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++) {
        CommunicationSpi<Message> spi = createSpi();
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        node.setAttribute(IgniteNodeAttributes.ATTR_CLIENT_MODE, false);
        node.order(i + 1);
        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);
        info(">>> Initialized context: nodeId=" + ctx.localNode().id());
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        if (useSsl) {
            IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
            IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
            ignite.setStaticCfg(cfg);
        }
        spi.setListener(lsnr);
        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) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) 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) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 4 with GridTestMessage

use of org.apache.ignite.spi.communication.GridTestMessage in project ignite by apache.

the class GridTcpCommunicationSpiMultithreadedSelfTest method testFlowSend.

/**
 * @throws Exception If failed.
 */
@Test
public void testFlowSend() throws Exception {
    reject = true;
    final CyclicBarrier barrier = new CyclicBarrier(THREAD_CNT);
    final Random rnd = new Random();
    final ClusterNode from = randomNode(rnd);
    ClusterNode tmp;
    do {
        tmp = randomNode(rnd);
    } while (tmp.id().equals(from.id()));
    final ClusterNode to = tmp;
    final int iterationCnt = 1000;
    final AtomicInteger threadId = new AtomicInteger();
    final int interval = 50;
    IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void run() {
            try {
                // Only first thread will print messages.
                int id = threadId.getAndIncrement();
                for (int i = 0; i < iterationCnt; i++) {
                    if (id == 0 && (i % 50) == 0)
                        info(">>> Running iteration " + i);
                    try {
                        for (ClusterNode node : nodes) {
                            Message msg = new GridTestMessage(from.id(), msgId.getAndIncrement(), 0);
                            spis.get(from.id()).sendMessage(node, msg);
                        }
                    } catch (IgniteException e) {
                        log.warning(">>> Oops, unable to send message (safe to ignore).", e);
                    }
                    barrier.await();
                }
            } catch (InterruptedException ignored) {
                Thread.currentThread().interrupt();
            } catch (BrokenBarrierException e) {
                info("Wait on barrier failed: " + e);
                Thread.currentThread().interrupt();
            }
        }
    }, THREAD_CNT, "message-sender");
    final AtomicBoolean run = new AtomicBoolean(true);
    IgniteInternalFuture<?> fut2 = multithreadedAsync(() -> {
        try {
            while (run.get() && !Thread.currentThread().isInterrupted()) {
                U.sleep(interval * 3 / 2);
                ((TcpCommunicationSpi) spis.get(from.id())).onNodeLeft(to.consistentId(), to.id());
            }
        } catch (IgniteInterruptedCheckedException ignored) {
            Thread.currentThread().interrupt();
        }
    }, 1);
    fut.get();
    run.set(false);
    fut2.get();
    // Wait when all messages are acknowledged to do not break next tests' logic.
    for (CommunicationSpi<Message> spi : spis.values()) {
        GridNioServer srv = ((GridNioServerWrapper) U.field(spi, "nioSrvWrapper")).nio();
        Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
        for (GridNioSession ses : sessions) {
            final GridNioRecoveryDescriptor snd = ses.outRecoveryDescriptor();
            if (snd != null) {
                GridTestUtils.waitForCondition(() -> snd.messagesRequests().isEmpty(), 10_000);
                assertEquals("Unexpected messages: " + snd.messagesRequests(), 0, snd.messagesRequests().size());
            }
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridNioServerWrapper(org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test)

Example 5 with GridTestMessage

use of org.apache.ignite.spi.communication.GridTestMessage in project ignite by apache.

the class GridTcpCommunicationSpiRecoverySelfTest method startSpis.

/**
 * @throws Exception If failed.
 */
private void startSpis() 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(i);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        node.order(i);
        GridSpiTestContext ctx = initSpiContext();
        MessageFactoryProvider testMsgFactory = 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);
        if (useSsl) {
            IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
            IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
            ignite.setStaticCfg(cfg);
        }
        spi.setListener(new TestListener());
        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) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) CommunicationListener(org.apache.ignite.spi.communication.CommunicationListener) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) BindException(java.net.BindException) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) ArrayList(java.util.ArrayList) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest) ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Map(java.util.Map) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridNioServerWrapper(org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test) UUID(java.util.UUID) GridTestNode(org.apache.ignite.testframework.GridTestNode) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock) CountDownLatch(java.util.concurrent.CountDownLatch) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteSpiAdapter(org.apache.ignite.spi.IgniteSpiAdapter) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) Message(org.apache.ignite.plugin.extensions.communication.Message) 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) HashMap(java.util.HashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock) HashMap(java.util.HashMap) Map(java.util.Map)

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