Search in sources :

Example 6 with DependencyResolver

use of org.apache.ignite.internal.processors.resource.DependencyResolver in project ignite by apache.

the class TcpCommunicationHandshakeTimeoutTest method testSocketForcedClosedBecauseSlowReadFromSocket.

/**
 * 1. Cluster from three nodes.
 * 2. Waiting when communication connection goes idle.
 * 4. Configure the delay during the communication connection handshake.
 * 5. Force establishing of new connection from node2 to node1 from timeout object processor thread
 * (it use compute in this test).
 * 6. Expected:  The frozen attempt of handshake would be successfully handled and a new connection
 * would be established.
 *
 * @throws Exception If fail.
 */
@Test
public void testSocketForcedClosedBecauseSlowReadFromSocket() throws Exception {
    // given: Two ordinary nodes.
    startGrid(0);
    IgniteEx g1 = startGrid(1);
    // and: One more node which communication connection can be delayed by demand.
    AtomicBoolean delayHandshakeUntilSocketClosed = new AtomicBoolean();
    IgniteEx g2 = startGrid(2, new DependencyResolver() {

        @Override
        public <T> T resolve(T instance) {
            if (instance instanceof TcpHandshakeExecutor) {
                TcpHandshakeExecutor gridNioServer = (TcpHandshakeExecutor) instance;
                return (T) new DelaydTcpHandshakeExecutor(gridNioServer, delayHandshakeUntilSocketClosed);
            }
            return instance;
        }
    });
    awaitPartitionMapExchange();
    AtomicBoolean result = new AtomicBoolean(false);
    // Wait for connections go idle.
    doSleep(1000);
    // when: Initiate communication connection from timeout object processor thread.
    g2.context().timeout().addTimeoutObject(new GridTimeoutObjectAdapter(0) {

        @Override
        public void onTimeout() {
            delayHandshakeUntilSocketClosed.set(true);
            g2.compute(g2.cluster().forNodes(Arrays.asList(g1.localNode()))).withNoFailover().call(() -> true);
            result.set(true);
        }
    });
    // then: Despite the first attempt of handshake would be frozen the compute should be handled well eventually.
    assertTrue("Compute should be successfully handled.", waitForCondition(result::get, 20_000));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TcpHandshakeExecutor(org.apache.ignite.spi.communication.tcp.internal.TcpHandshakeExecutor) GridTimeoutObjectAdapter(org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) DependencyResolver(org.apache.ignite.internal.processors.resource.DependencyResolver) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)6 DependencyResolver (org.apache.ignite.internal.processors.resource.DependencyResolver)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)5 Test (org.junit.Test)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)4 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteSystemProperties (org.apache.ignite.IgniteSystemProperties)1 IGNITE_PDS_WAL_REBALANCE_THRESHOLD (org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD)1 ATOMIC (org.apache.ignite.cache.CacheAtomicityMode.ATOMIC)1 REPLICATED (org.apache.ignite.cache.CacheMode.REPLICATED)1