Search in sources :

Example 1 with ZkTestClientCnxnSocketNIO

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

the class ZookeeperDiscoveryRandomStopOrFailConcurrentTest method stopOrKillMultithreaded.

/**
 */
private void stopOrKillMultithreaded(final List<Integer> stopIndices) throws Exception {
    log.info("Stopping or killing nodes by idx: " + stopIndices.toString());
    final StopMode mode = stopMode;
    GridTestUtils.runMultiThreaded((idx) -> {
        try {
            Random rnd = ThreadLocalRandom.current();
            int nodeIdx = stopIndices.get(idx);
            if (mode == StopMode.FAIL_ONLY || (mode == StopMode.RANDOM && rnd.nextBoolean())) {
                ZkTestClientCnxnSocketNIO c0 = ZkTestClientCnxnSocketNIO.forNode(grid(nodeIdx));
                c0.closeSocket(true);
                nodesFailed.incrementAndGet();
            } else {
                stopGrid(nodeIdx);
                nodesLeft.incrementAndGet();
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }, stopIndices.size(), "stop-node");
}
Also used : ZkTestClientCnxnSocketNIO(org.apache.zookeeper.ZkTestClientCnxnSocketNIO) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 2 with ZkTestClientCnxnSocketNIO

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

the class ZookeeperDiscoveryClientDisconnectTest method testReconnectDisabled_ConnectionLost.

/**
 * @throws Exception If failed.
 */
@Test
public void testReconnectDisabled_ConnectionLost() throws Exception {
    clientReconnectDisabled = true;
    startGrid(0);
    sesTimeout = 3000;
    testSockNio = true;
    Ignite client = startClientGrid(1);
    final CountDownLatch latch = new CountDownLatch(1);
    client.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            latch.countDown();
            return false;
        }
    }, EventType.EVT_NODE_SEGMENTED);
    ZkTestClientCnxnSocketNIO nio = ZkTestClientCnxnSocketNIO.forNode(client);
    nio.closeSocket(true);
    try {
        ZookeeperDiscoverySpiTestHelper.waitNoAliveZkNodes(log, zkCluster.getConnectString(), Collections.singletonList(ZookeeperDiscoverySpiTestHelper.aliveZkNodePath(client)), 10_000);
    } finally {
        nio.allowConnect();
    }
    assertTrue(latch.await(10, SECONDS));
}
Also used : ZkTestClientCnxnSocketNIO(org.apache.zookeeper.ZkTestClientCnxnSocketNIO) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with ZkTestClientCnxnSocketNIO

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

the class ZookeeperDiscoveryCommunicationFailureTest method testNoOpCommunicationErrorResolve_3.

/**
 * Tests case when one node fails before sending communication status.
 *
 * @throws Exception If failed.
 */
@Test
public void testNoOpCommunicationErrorResolve_3() throws Exception {
    sesTimeout = 2000;
    commFailureRslvr = NoOpCommunicationFailureResolver.FACTORY;
    startGridsMultiThreaded(3);
    sesTimeout = 10_000;
    testSockNio = true;
    sesTimeout = 5000;
    startGrid(3);
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() {
            ZookeeperDiscoverySpi spi = spi(ignite(0));
            spi.resolveCommunicationFailure(ignite(1).cluster().localNode(), new Exception("test"));
            return null;
        }
    });
    U.sleep(1000);
    ZkTestClientCnxnSocketNIO nio = ZkTestClientCnxnSocketNIO.forNode(ignite(3));
    nio.closeSocket(true);
    try {
        stopGrid(3);
        fut.get();
    } finally {
        nio.allowConnect();
    }
    waitForTopology(3);
}
Also used : ZkTestClientCnxnSocketNIO(org.apache.zookeeper.ZkTestClientCnxnSocketNIO) ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) Test(org.junit.Test)

Example 4 with ZkTestClientCnxnSocketNIO

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

the class ZookeeperDiscoverySegmentationAndConnectionRestoreTest method connectionRestore_NonCoordinator.

/**
 * @param failWhenDisconnected {@code True} if fail node while another node is disconnected.
 * @throws Exception If failed.
 */
private void connectionRestore_NonCoordinator(boolean failWhenDisconnected) throws Exception {
    testSockNio = true;
    Ignite node0 = startGrid(0);
    Ignite node1 = startGrid(1);
    ZkTestClientCnxnSocketNIO c1 = ZkTestClientCnxnSocketNIO.forNode(node1);
    c1.closeSocket(true);
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() {
            try {
                startGrid(2);
            } catch (Exception e) {
                info("Start error: " + e);
            }
            return null;
        }
    }, "start-node");
    helper.checkEvents(node0, evts, ZookeeperDiscoverySpiTestHelper.joinEvent(3));
    if (failWhenDisconnected) {
        ZookeeperDiscoverySpi spi = spis.get(getTestIgniteInstanceName(2));
        closeZkClient(spi);
        helper.checkEvents(node0, evts, ZookeeperDiscoverySpiTestHelper.leftEvent(4, true));
    }
    c1.allowConnect();
    helper.checkEvents(ignite(1), evts, ZookeeperDiscoverySpiTestHelper.joinEvent(3));
    if (failWhenDisconnected) {
        helper.checkEvents(ignite(1), evts, ZookeeperDiscoverySpiTestHelper.leftEvent(4, true));
        IgnitionEx.stop(getTestIgniteInstanceName(2), true, ShutdownPolicy.IMMEDIATE, true);
    }
    fut.get();
    waitForTopology(failWhenDisconnected ? 2 : 3);
}
Also used : ZkTestClientCnxnSocketNIO(org.apache.zookeeper.ZkTestClientCnxnSocketNIO) ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi) Ignite(org.apache.ignite.Ignite)

Example 5 with ZkTestClientCnxnSocketNIO

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

the class ZookeeperDiscoverySegmentationAndConnectionRestoreTest method testConnectionRestore2.

/**
 * @throws Exception If failed.
 */
@Test
public void testConnectionRestore2() throws Exception {
    testSockNio = true;
    Ignite node0 = startGrid(0);
    ZkTestClientCnxnSocketNIO c0 = ZkTestClientCnxnSocketNIO.forNode(node0);
    c0.closeSocket(false);
    startGridsMultiThreaded(1, 5);
}
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