Search in sources :

Example 6 with ZkTestClientCnxnSocketNIO

use of org.apache.zookeeper.ZkTestClientCnxnSocketNIO in project ignite by apache.

the class ZookeeperDiscoverySegmentationAndConnectionRestoreTest method testSegmentation1.

/**
 * @throws Exception If failed.
 */
@Test
public void testSegmentation1() throws Exception {
    sesTimeout = 2000;
    testSockNio = true;
    Ignite node0 = startGrid(0);
    final CountDownLatch l = new CountDownLatch(1);
    node0.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            l.countDown();
            return false;
        }
    }, EventType.EVT_NODE_SEGMENTED);
    ZkTestClientCnxnSocketNIO c0 = ZkTestClientCnxnSocketNIO.forNode(node0);
    c0.closeSocket(true);
    for (int i = 0; i < 10; i++) {
        // noinspection BusyWait
        Thread.sleep(1_000);
        if (l.getCount() == 0)
            break;
    }
    info("Allow connect");
    c0.allowConnect();
    assertTrue(l.await(10, TimeUnit.SECONDS));
}
Also used : ZkTestClientCnxnSocketNIO(org.apache.zookeeper.ZkTestClientCnxnSocketNIO) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 7 with ZkTestClientCnxnSocketNIO

use of org.apache.zookeeper.ZkTestClientCnxnSocketNIO in project ignite by apache.

the class ZookeeperDiscoverySegmentationAndConnectionRestoreTest method testConnectionRestore1.

/**
 * @throws Exception If failed.
 */
@Test
public void testConnectionRestore1() throws Exception {
    testSockNio = true;
    Ignite node0 = startGrid(0);
    ZkTestClientCnxnSocketNIO c0 = ZkTestClientCnxnSocketNIO.forNode(node0);
    c0.closeSocket(false);
    startGrid(1);
}
Also used : ZkTestClientCnxnSocketNIO(org.apache.zookeeper.ZkTestClientCnxnSocketNIO) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 8 with ZkTestClientCnxnSocketNIO

use of org.apache.zookeeper.ZkTestClientCnxnSocketNIO in project ignite by apache.

the class ZookeeperDiscoverySegmentationAndConnectionRestoreTest method connectionRestore_Coordinator.

/**
 * @param initNodes Number of initially started nodes.
 * @param startNodes Number of nodes to start after coordinator loose connection.
 * @param failCnt Number of nodes to stop after coordinator loose connection.
 * @throws Exception If failed.
 */
private void connectionRestore_Coordinator(final int initNodes, int startNodes, int failCnt) throws Exception {
    sesTimeout = 30_000;
    testSockNio = true;
    Ignite node0 = startGrids(initNodes);
    ZkTestClientCnxnSocketNIO c0 = ZkTestClientCnxnSocketNIO.forNode(node0);
    c0.closeSocket(true);
    final AtomicInteger nodeIdx = new AtomicInteger(initNodes);
    IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

        @Override
        public Void call() {
            try {
                startGrid(nodeIdx.getAndIncrement());
            } catch (Exception e) {
                error("Start failed: " + e);
            }
            return null;
        }
    }, startNodes, "start-node");
    int cnt = 0;
    DiscoveryEvent[] expEvts = new DiscoveryEvent[startNodes - failCnt];
    int expEvtCnt = 0;
    sesTimeout = 1000;
    List<ZkTestClientCnxnSocketNIO> blockedC = new ArrayList<>();
    final List<String> failedZkNodes = new ArrayList<>(failCnt);
    for (int i = initNodes; i < initNodes + startNodes; i++) {
        final ZookeeperDiscoverySpi spi = helper.waitSpi(getTestIgniteInstanceName(i), spis);
        assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                Object spiImpl = GridTestUtils.getFieldValue(spi, "impl");
                if (spiImpl == null)
                    return false;
                long internalOrder = GridTestUtils.getFieldValue(spiImpl, "rtState", "internalOrder");
                return internalOrder > 0;
            }
        }, 10_000));
        if (cnt++ < failCnt) {
            ZkTestClientCnxnSocketNIO c = ZkTestClientCnxnSocketNIO.forNode(getTestIgniteInstanceName(i));
            c.closeSocket(true);
            blockedC.add(c);
            failedZkNodes.add(ZookeeperDiscoverySpiTestHelper.aliveZkNodePath(spi));
        } else {
            expEvts[expEvtCnt] = ZookeeperDiscoverySpiTestHelper.joinEvent(initNodes + expEvtCnt + 1);
            expEvtCnt++;
        }
    }
    ZookeeperDiscoverySpiTestHelper.waitNoAliveZkNodes(log, zkCluster.getConnectString(), failedZkNodes, 30_000);
    c0.allowConnect();
    for (ZkTestClientCnxnSocketNIO c : blockedC) c.allowConnect();
    if (expEvts.length > 0) {
        for (int i = 0; i < initNodes; i++) helper.checkEvents(ignite(i), evts, expEvts);
    }
    fut.get();
    waitForTopology(initNodes + startNodes - failCnt);
}
Also used : ZkTestClientCnxnSocketNIO(org.apache.zookeeper.ZkTestClientCnxnSocketNIO) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Ignite(org.apache.ignite.Ignite)

Example 9 with ZkTestClientCnxnSocketNIO

use of org.apache.zookeeper.ZkTestClientCnxnSocketNIO in project ignite by apache.

the class ZookeeperDiscoverySegmentationAndConnectionRestoreTest method testStopNodeOnSegmentaion.

/**
 * Verifies correct handling of SEGMENTATION event with STOP segmentation policy: node is stopped successfully,
 * all its threads are shut down.
 *
 * @throws Exception If failed.
 *
 * @see <a href="https://issues.apache.org/jira/browse/IGNITE-9040">IGNITE-9040</a> ticket for more context of the test.
 */
@Test
public void testStopNodeOnSegmentaion() throws Exception {
    sesTimeout = 2000;
    testSockNio = true;
    persistence = true;
    atomicityMode = CacheAtomicityMode.TRANSACTIONAL;
    backups = 2;
    final Ignite node0 = startGrid(0);
    sesTimeout = 10_000;
    testSockNio = false;
    startGrid(1);
    node0.cluster().active(true);
    final IgniteEx client = startClientGrid(2);
    // first transaction
    client.transactions().txStart(PESSIMISTIC, READ_COMMITTED, 0, 0);
    client.cache(DEFAULT_CACHE_NAME).put(0, 0);
    // second transaction to create a deadlock with the first one
    // and guarantee transaction futures will be presented on segmented node
    // (erroneous write to WAL on segmented node stop happens
    // on completing transaction with NodeStoppingException)
    GridTestUtils.runAsync(new Runnable() {

        @Override
        public void run() {
            Transaction tx2 = client.transactions().txStart(OPTIMISTIC, READ_COMMITTED, 0, 0);
            client.cache(DEFAULT_CACHE_NAME).put(0, 0);
            tx2.commit();
        }
    });
    // next block simulates Ignite node segmentation by closing socket of ZooKeeper client
    {
        final CountDownLatch l = new CountDownLatch(1);
        node0.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                l.countDown();
                return false;
            }
        }, EventType.EVT_NODE_SEGMENTED);
        ZkTestClientCnxnSocketNIO c0 = ZkTestClientCnxnSocketNIO.forNode(node0);
        c0.closeSocket(true);
        for (int i = 0; i < 10; i++) {
            // noinspection BusyWait
            Thread.sleep(1_000);
            if (l.getCount() == 0)
                break;
        }
        info("Allow connect");
        c0.allowConnect();
        assertTrue(l.await(10, TimeUnit.SECONDS));
    }
    waitForNodeStop(node0.name());
    checkStoppedNodeThreads(node0.name());
}
Also used : ZkTestClientCnxnSocketNIO(org.apache.zookeeper.ZkTestClientCnxnSocketNIO) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 10 with ZkTestClientCnxnSocketNIO

use of org.apache.zookeeper.ZkTestClientCnxnSocketNIO in project ignite by apache.

the class ZookeeperDiscoveryConcurrentStartAndStartStopTest method testConnectionRestore4.

/**
 * @throws Exception If failed.
 */
@Test
public void testConnectionRestore4() throws Exception {
    testSockNio = true;
    Ignite node0 = startGrid(0);
    ZkTestClientCnxnSocketNIO c0 = ZkTestClientCnxnSocketNIO.forNode(node0);
    c0.closeSocket(false);
    startGrid(1);
}
Also used : ZkTestClientCnxnSocketNIO(org.apache.zookeeper.ZkTestClientCnxnSocketNIO) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Aggregations

ZkTestClientCnxnSocketNIO (org.apache.zookeeper.ZkTestClientCnxnSocketNIO)10 Ignite (org.apache.ignite.Ignite)8 Test (org.junit.Test)7 CountDownLatch (java.util.concurrent.CountDownLatch)3 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)3 Event (org.apache.ignite.events.Event)3 ZookeeperDiscoverySpi (org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi)3 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)1 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)1 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)1 Transaction (org.apache.ignite.transactions.Transaction)1