Search in sources :

Example 6 with GridCommunicationClient

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

the class GridTcpCommunicationSpiAbstractTest method afterTest.

/** {@inheritDoc} */
@Override
protected void afterTest() throws Exception {
    super.afterTest();
    for (CommunicationSpi spi : spis.values()) {
        ConcurrentMap<UUID, GridCommunicationClient[]> clients = U.field(spi, "clients");
        for (int i = 0; i < 20; i++) {
            GridCommunicationClient client0 = null;
            for (GridCommunicationClient[] clients0 : clients.values()) {
                for (GridCommunicationClient client : clients0) {
                    if (client != null) {
                        client0 = client;
                        break;
                    }
                }
                if (client0 != null)
                    break;
            }
            if (client0 == null)
                return;
            info("Check failed for SPI [igniteInstanceName=" + GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName") + ", client=" + client0 + ", spi=" + spi + ']');
            U.sleep(1000);
        }
        fail("Failed to wait when clients are closed.");
    }
}
Also used : CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) IgniteSpiAdapter(org.apache.ignite.spi.IgniteSpiAdapter) UUID(java.util.UUID) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient)

Example 7 with GridCommunicationClient

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

the class GridTcpCommunicationSpiMultithreadedSelfTest method afterTest.

/**
     * @throws Exception If failed.
     */
@Override
protected void afterTest() throws Exception {
    super.afterTest();
    for (MessageListener lsnr : lsnrs.values()) {
        lsnr.rcvdMsgs.clear();
        lsnr.rmtMsgCnt.set(0);
    }
    for (CommunicationSpi spi : spis.values()) {
        final ConcurrentMap<UUID, GridCommunicationClient[]> clients = U.field(spi, "clients");
        assert GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                for (GridCommunicationClient[] clients0 : clients.values()) {
                    for (GridCommunicationClient client : clients0) {
                        if (client != null)
                            return false;
                    }
                }
                return true;
            }
        }, getTestTimeout()) : "Clients: " + clients;
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) UUID(java.util.UUID) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient)

Example 8 with GridCommunicationClient

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

the class GridTcpCommunicationSpiAbstractTest method testSendToManyNodes.

/** {@inheritDoc} */
@Override
public void testSendToManyNodes() throws Exception {
    super.testSendToManyNodes();
    // Test idle clients remove.
    for (CommunicationSpi spi : spis.values()) {
        ConcurrentMap<UUID, GridCommunicationClient> clients = U.field(spi, "clients");
        assertEquals(getSpiCount() - 1, clients.size());
        clients.put(UUID.randomUUID(), F.first(clients.values()));
    }
}
Also used : CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) UUID(java.util.UUID) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient)

Example 9 with GridCommunicationClient

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

the class GridTcpCommunicationSpiConcurrentConnectSelfTest method concurrentConnect.

/**
     * @param threads Number of threads.
     * @param msgPerThread Messages per thread.
     * @param iters Number of iterations.
     * @param sleep If {@code true} sleeps random time before starts send messages.
     * @param load Run load threads flag.
     * @throws Exception If failed.
     */
private void concurrentConnect(final int threads, final int msgPerThread, final int iters, final boolean sleep, boolean load) throws Exception {
    log.info("Concurrent connect [threads=" + threads + ", msgPerThread=" + msgPerThread + ", iters=" + iters + ", load=" + load + ", sleep=" + sleep + ']');
    final AtomicBoolean stop = new AtomicBoolean();
    IgniteInternalFuture<?> loadFut = null;
    if (load) {
        loadFut = GridTestUtils.runMultiThreadedAsync(new Callable<Long>() {

            @Override
            public Long call() throws Exception {
                long dummyRes = 0;
                List<String> list = new ArrayList<>();
                while (!stop.get()) {
                    for (int i = 0; i < 100; i++) {
                        String str = new String(new byte[i]);
                        list.add(str);
                        dummyRes += str.hashCode();
                    }
                    if (list.size() > 1000_000) {
                        list = new ArrayList<>();
                        System.gc();
                    }
                }
                return dummyRes;
            }
        }, 2, "test-load");
    }
    try {
        for (int i = 0; i < iters; i++) {
            log.info("Iteration: " + i);
            final AtomicInteger msgId = new AtomicInteger();
            final int expMsgs = threads * msgPerThread;
            CountDownLatch latch = new CountDownLatch(expMsgs);
            MessageListener lsnr = new MessageListener(latch);
            createSpis(lsnr);
            final AtomicInteger idx = new AtomicInteger();
            try {
                final Callable<Void> c = new Callable<Void>() {

                    @Override
                    public Void call() throws Exception {
                        int idx0 = idx.getAndIncrement();
                        Thread.currentThread().setName("Test thread [idx=" + idx0 + ", grid=" + (idx0 % 2) + ']');
                        CommunicationSpi<Message> spi = spis.get(idx0 % 2);
                        ClusterNode srcNode = nodes.get(idx0 % 2);
                        ClusterNode dstNode = nodes.get((idx0 + 1) % 2);
                        if (sleep) {
                            ThreadLocalRandom rnd = ThreadLocalRandom.current();
                            long millis = rnd.nextLong(10);
                            if (millis > 0)
                                Thread.sleep(millis);
                        }
                        for (int i = 0; i < msgPerThread; i++) spi.sendMessage(dstNode, new GridTestMessage(srcNode.id(), msgId.incrementAndGet(), 0));
                        return null;
                    }
                };
                List<Thread> threadsList = new ArrayList<>();
                final AtomicBoolean fail = new AtomicBoolean();
                final AtomicLong tId = new AtomicLong();
                for (int t = 0; t < threads; t++) {
                    Thread t0 = new Thread(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                c.call();
                            } catch (Throwable e) {
                                log.error("Unexpected error: " + e, e);
                                fail.set(true);
                            }
                        }
                    }) {

                        @Override
                        public long getId() {
                            // Override getId to use all connections.
                            return tId.getAndIncrement();
                        }
                    };
                    threadsList.add(t0);
                    t0.start();
                }
                for (Thread t0 : threadsList) t0.join();
                assertTrue(latch.await(10, TimeUnit.SECONDS));
                for (CommunicationSpi spi : spis) {
                    ConcurrentMap<UUID, GridCommunicationClient> clients = U.field(spi, "clients");
                    assertEquals(1, clients.size());
                    final GridNioServer srv = U.field(spi, "nioSrvr");
                    final int conns = pairedConnections ? 2 : 1;
                    GridTestUtils.waitForCondition(new GridAbsPredicate() {

                        @Override
                        public boolean apply() {
                            Collection sessions = U.field(srv, "sessions");
                            return sessions.size() == conns * connectionsPerNode;
                        }
                    }, 5000);
                    Collection sessions = U.field(srv, "sessions");
                    assertEquals(conns * connectionsPerNode, sessions.size());
                }
                assertEquals(expMsgs, lsnr.cntr.get());
            } finally {
                stopSpis();
            }
        }
    } finally {
        stop.set(true);
        if (loadFut != null)
            loadFut.get();
    }
}
Also used : GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) UUID(java.util.UUID) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) Collection(java.util.Collection)

Example 10 with GridCommunicationClient

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

the class IgniteCacheMessageRecoveryAbstractTest method closeSessions.

/**
     * @param ignite Node.
     * @throws Exception If failed.
     * @return {@code True} if closed at least one session.
     */
static boolean closeSessions(Ignite ignite) throws Exception {
    TcpCommunicationSpi commSpi = (TcpCommunicationSpi) ignite.configuration().getCommunicationSpi();
    Map<UUID, GridCommunicationClient[]> clients = U.field(commSpi, "clients");
    boolean closed = false;
    for (GridCommunicationClient[] clients0 : clients.values()) {
        for (GridCommunicationClient client : clients0) {
            if (client != null) {
                GridTcpNioCommunicationClient client0 = (GridTcpNioCommunicationClient) client;
                GridNioSession ses = client0.session();
                ses.close();
                closed = true;
            }
        }
    }
    return closed;
}
Also used : GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) UUID(java.util.UUID) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) GridTcpNioCommunicationClient(org.apache.ignite.internal.util.nio.GridTcpNioCommunicationClient) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)

Aggregations

GridCommunicationClient (org.apache.ignite.internal.util.nio.GridCommunicationClient)16 UUID (java.util.UUID)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 IpcEndpoint (org.apache.ignite.internal.util.ipc.IpcEndpoint)4 IpcSharedMemoryServerEndpoint (org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint)4 CommunicationSpi (org.apache.ignite.spi.communication.CommunicationSpi)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 GridTcpNioCommunicationClient (org.apache.ignite.internal.util.nio.GridTcpNioCommunicationClient)3 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)3 IOException (java.io.IOException)2 SocketChannel (java.nio.channels.SocketChannel)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)2 IpcOutOfSystemResourcesException (org.apache.ignite.internal.util.ipc.shmem.IpcOutOfSystemResourcesException)2 GridNioRecoveryDescriptor (org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor)2 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)2 IgniteSpiOperationTimeoutException (org.apache.ignite.spi.IgniteSpiOperationTimeoutException)2 IgniteSpiOperationTimeoutHelper (org.apache.ignite.spi.IgniteSpiOperationTimeoutHelper)2