Search in sources :

Example 11 with GridNioServer

use of org.apache.ignite.internal.util.nio.GridNioServer in project ignite by apache.

the class IgniteTcpCommunicationRecoveryAckClosureSelfTest method checkOverflow.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
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 = U.field(spi1, "nioSrvr");
    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);
    // Prevent node1 from send
    GridTestUtils.setFieldValue(srv1, "skipWrite", true);
    final GridNioSession ses0 = communicationSession(spi0);
    int sentMsgs = 1;
    for (int i = 0; i < 150; 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;
        }
    }, 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), ackC);
    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());
    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) CI1(org.apache.ignite.internal.util.typedef.CI1) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 12 with GridNioServer

use of org.apache.ignite.internal.util.nio.GridNioServer in project ignite by apache.

the class IgniteTcpCommunicationRecoveryAckClosureSelfTest method checkAck.

/**
 * @param ackCnt Recovery acknowledgement count.
 * @param idleTimeout Idle connection timeout.
 * @param msgPerIter Messages per iteration.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
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);
            final AtomicInteger ackMsgs = new AtomicInteger(0);
            IgniteInClosure<IgniteException> ackC = new CI1<IgniteException>() {

                @Override
                public void apply(IgniteException o) {
                    assert o == null;
                    ackMsgs.incrementAndGet();
                }
            };
            for (int j = 0; j < msgPerIter; j++) {
                spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0), ackC);
                spi1.sendMessage(node0, new GridTestMessage(node1.id(), ++msgId, 0), ackC);
                if (j == 0) {
                    final TestListener lsnr0 = (TestListener) spi0.getListener();
                    final TestListener lsnr1 = (TestListener) spi1.getListener();
                    GridTestUtils.waitForCondition(new GridAbsPredicate() {

                        @Override
                        public boolean apply() {
                            return lsnr0.rcvCnt.get() >= 1 && lsnr1.rcvCnt.get() >= 1;
                        }
                    }, 1000);
                }
            }
            expMsgs += msgPerIter;
            final long totAcked0 = totAcked;
            for (TcpCommunicationSpi spi : spis) {
                GridNioServer srv = U.field(spi, "nioSrvr");
                Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
                assertFalse(sessions.isEmpty());
                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());
            }
            assertEquals(msgPerIter * 2, ackMsgs.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) CI1(org.apache.ignite.internal.util.typedef.CI1) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor)

Example 13 with GridNioServer

use of org.apache.ignite.internal.util.nio.GridNioServer in project ignite by apache.

the class IgniteTcpCommunicationRecoveryAckClosureSelfTest method communicationSession.

/**
 * @param spi SPI.
 * @return Session.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private GridNioSession communicationSession(TcpCommunicationSpi spi) throws Exception {
    final GridNioServer srv = U.field(spi, "nioSrvr");
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
            return !sessions.isEmpty();
        }
    }, 5000);
    Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
    assertEquals(1, sessions.size());
    return sessions.iterator().next();
}
Also used : GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Collection(java.util.Collection) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer)

Example 14 with GridNioServer

use of org.apache.ignite.internal.util.nio.GridNioServer in project ignite by apache.

the class GridTcpCommunicationSpiRecoveryAckSelfTest method communicationSession.

/**
 * @param spi SPI.
 * @return Session.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private GridNioSession communicationSession(TcpCommunicationSpi spi) throws Exception {
    final GridNioServer srv = U.field(spi, "nioSrvr");
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
            return !sessions.isEmpty();
        }
    }, 5000);
    Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
    assertEquals(1, sessions.size());
    return sessions.iterator().next();
}
Also used : GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Collection(java.util.Collection) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer)

Aggregations

GridNioServer (org.apache.ignite.internal.util.nio.GridNioServer)14 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)11 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)8 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)6 Collection (java.util.Collection)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 IgniteException (org.apache.ignite.IgniteException)3 GridNioRecoveryDescriptor (org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor)3 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)3 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Ignite (org.apache.ignite.Ignite)2 GridIoManager (org.apache.ignite.internal.managers.communication.GridIoManager)2 CI1 (org.apache.ignite.internal.util.typedef.CI1)2 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)2 Message (org.apache.ignite.plugin.extensions.communication.Message)2 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)2