Search in sources :

Example 6 with GridNioServerWrapper

use of org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper in project ignite by apache.

the class TooManyOpenFilesTcpCommunicationSpiTest method testTooManyOpenFilesErr.

/**
 * Test checks that node will fail in case of error "Too many open files" in {@link TcpCommunicationSpi}.
 *
 * @throws Exception If failed.
 */
@Test
public void testTooManyOpenFilesErr() throws Exception {
    IgniteEx crd = startGrids(3);
    crd.cluster().state(ClusterState.ACTIVE);
    IgniteEx stopNode = grid(2);
    CommunicationSpi stopNodeSpi = stopNode.context().config().getCommunicationSpi();
    ConnectionClientPool connPool = U.field(stopNodeSpi, "clientPool");
    GridNioServerWrapper nioSrvWrapper = U.field(stopNodeSpi, "nioSrvWrapper");
    IgniteEx txNode = grid(1);
    try (Transaction tx = txNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 60_000, 4)) {
        IgniteCache<Object, Object> cache = txNode.cache(DEFAULT_CACHE_NAME);
        cache.put(0, 1);
        nioSrvWrapper.socketChannelFactory(() -> {
            throw new SocketException("Too many open files");
        });
        connPool.forceCloseConnection(txNode.localNode().id());
        cache.put(1, 2);
        cache.put(2, 3);
        cache.put(3, 4);
        // hungs here.
        tx.commit();
    } catch (ClusterTopologyException e) {
        log.error("Error wait commit", e);
    }
    assertTrue(waitForCondition(((IgniteKernal) stopNode)::isStopping, 60_000));
}
Also used : SocketException(java.net.SocketException) IgniteKernal(org.apache.ignite.internal.IgniteKernal) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) ConnectionClientPool(org.apache.ignite.spi.communication.tcp.internal.ConnectionClientPool) GridNioServerWrapper(org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 7 with GridNioServerWrapper

use of org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper 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 8 with GridNioServerWrapper

use of org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper in project ignite by apache.

the class GridTcpCommunicationSpiRecoveryAckSelfTest 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);
    final GridNioServer<?> srv1 = ((GridNioServerWrapper) U.field(spi1, "nioSrvWrapper")).nio();
    int msgId = 0;
    // Send message to establish connection.
    spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
    // Prevent node1 from send
    GridTestUtils.setFieldValue(srv1, "skipWrite", true);
    final GridNioSession ses0 = communicationSession(spi0);
    int sentMsgs = 1;
    for (int i = 0; i < 1280; i++) {
        try {
            spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
            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;
        }
    }, 5000);
    assertTrue("Failed to wait for session close", ses0.closeTime() != 0);
    GridTestUtils.setFieldValue(srv1, "skipWrite", false);
    for (int i = 0; i < 100; i++) spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
    final int expMsgs = sentMsgs + 100;
    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());
}
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) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 9 with GridNioServerWrapper

use of org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper in project ignite by apache.

the class GridTcpCommunicationSpiRecoveryAckSelfTest method checkAck.

/**
 * @param ackCnt Recovery acknowledgement count.
 * @param idleTimeout Idle connection timeout.
 * @param msgPerIter Messages per iteration.
 * @throws Exception If failed.
 */
private void checkAck(int ackCnt, int idleTimeout, int msgPerIter) throws Exception {
    createSpis(ackCnt, idleTimeout, TcpCommunicationSpi.DFLT_MSG_QUEUE_LIMIT);
    try {
        TcpCommunicationSpi spi0 = spis.get(0);
        TcpCommunicationSpi spi1 = spis.get(1);
        ClusterNode node0 = nodes.get(0);
        ClusterNode node1 = nodes.get(1);
        int msgId = 0;
        int expMsgs = 0;
        long totAcked = 0;
        for (int i = 0; i < 5; i++) {
            info("Iteration: " + i);
            for (int j = 0; j < msgPerIter; j++) {
                spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
                spi1.sendMessage(node0, new GridTestMessage(node1.id(), ++msgId, 0));
            }
            U.sleep(500);
            expMsgs += msgPerIter;
            final long totAcked0 = totAcked;
            for (TcpCommunicationSpi spi : spis) {
                GridNioServer<?> srv = ((GridNioServerWrapper) U.field(spi, "nioSrvWrapper")).nio();
                final Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
                GridTestUtils.waitForCondition(new GridAbsPredicate() {

                    @Override
                    public boolean apply() {
                        return !sessions.isEmpty();
                    }
                }, 5_000);
                boolean found = false;
                for (GridNioSession ses : sessions) {
                    final GridNioRecoveryDescriptor recoveryDesc = ses.outRecoveryDescriptor();
                    if (recoveryDesc != null) {
                        found = true;
                        GridTestUtils.waitForCondition(new GridAbsPredicate() {

                            @Override
                            public boolean apply() {
                                long acked = GridTestUtils.getFieldValue(recoveryDesc, "acked");
                                return acked > totAcked0;
                            }
                        }, 5000);
                        GridTestUtils.waitForCondition(new GridAbsPredicate() {

                            @Override
                            public boolean apply() {
                                return recoveryDesc.messagesRequests().isEmpty();
                            }
                        }, 10_000);
                        assertEquals("Unexpected messages: " + recoveryDesc.messagesRequests(), 0, recoveryDesc.messagesRequests().size());
                        break;
                    }
                }
                assertTrue(found);
            }
            final int expMsgs0 = expMsgs;
            for (TcpCommunicationSpi spi : spis) {
                final TestListener lsnr = (TestListener) spi.getListener();
                GridTestUtils.waitForCondition(new GridAbsPredicate() {

                    @Override
                    public boolean apply() {
                        return lsnr.rcvCnt.get() >= expMsgs0;
                    }
                }, 5000);
                assertEquals(expMsgs, lsnr.rcvCnt.get());
            }
            totAcked += msgPerIter;
        }
    } finally {
        stopSpis();
    }
}
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) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor)

Example 10 with GridNioServerWrapper

use of org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper in project ignite by apache.

the class ClientReconnectContinuousQueryTest method skipRead.

/**
 * @param igniteClient Ignite client.
 * @param skip Skip.
 */
private void skipRead(IgniteEx igniteClient, boolean skip) {
    GridIoManager ioMgr = igniteClient.context().io();
    TcpCommunicationSpi commSpi = (TcpCommunicationSpi) ((Object[]) U.field(ioMgr, "spis"))[0];
    GridNioServer nioSrvr = ((GridNioServerWrapper) U.field(commSpi, "nioSrvWrapper")).nio();
    GridTestUtils.setFieldValue(nioSrvr, "skipRead", skip);
}
Also used : GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) GridNioServerWrapper(org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer)

Aggregations

GridNioServerWrapper (org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper)17 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)10 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)9 GridNioServer (org.apache.ignite.internal.util.nio.GridNioServer)6 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)6 Collection (java.util.Collection)4 IgniteException (org.apache.ignite.IgniteException)4 GridNioRecoveryDescriptor (org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor)4 Message (org.apache.ignite.plugin.extensions.communication.Message)4 Test (org.junit.Test)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Ignite (org.apache.ignite.Ignite)3 GridIoManager (org.apache.ignite.internal.managers.communication.GridIoManager)3 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)3 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)3 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)3 ConnectionClientPool (org.apache.ignite.spi.communication.tcp.internal.ConnectionClientPool)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3