Search in sources :

Example 16 with ZookeeperDiscoverySpi

use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.

the class ZookeeperDiscoveryCommunicationFailureTest method testCommunicationFailureResolve_CachesInfo2.

/**
 * @throws Exception If failed.
 */
@Test
public void testCommunicationFailureResolve_CachesInfo2() throws Exception {
    testCommSpi = true;
    sesTimeout = 5000;
    final CacheInfoCommunicationFailureResolver rslvr = new CacheInfoCommunicationFailureResolver();
    commFailureRslvr = new IgniteOutClosure<CommunicationFailureResolver>() {

        @Override
        public CommunicationFailureResolver apply() {
            return rslvr;
        }
    };
    Ignite srv0 = startGrid(0);
    CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>("c1");
    ccfg.setBackups(1);
    srv0.createCache(ccfg);
    // Block rebalance to make sure node0 will be the only owner.
    TestRecordingCommunicationSpi.spi(srv0).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return msg instanceof GridDhtPartitionSupplyMessage && ((GridDhtPartitionSupplyMessage) msg).groupId() == CU.cacheId("c1");
        }
    });
    startGrid(1);
    U.sleep(1000);
    ZookeeperDiscoverySpi spi = spi(srv0);
    rslvr.latch = new CountDownLatch(1);
    ZkTestCommunicationSpi.testSpi(srv0).initCheckResult(2, 0);
    spi.resolveCommunicationFailure(spi.getRemoteNodes().iterator().next(), new Exception("test"));
    assertTrue(rslvr.latch.await(10, SECONDS));
    List<List<ClusterNode>> cacheOwners = rslvr.ownersMap.get("c1");
    ClusterNode node0 = srv0.cluster().localNode();
    for (int p = 0; p < RendezvousAffinityFunction.DFLT_PARTITION_COUNT; p++) {
        List<ClusterNode> owners = cacheOwners.get(p);
        assertEquals(1, owners.size());
        assertEquals(node0, owners.get(0));
    }
    TestRecordingCommunicationSpi.spi(srv0).stopBlock();
    awaitPartitionMapExchange();
    Map<String, T3<Integer, Integer, Integer>> expCaches = new HashMap<>();
    expCaches.put(DEFAULT_CACHE_NAME, new T3<>(RendezvousAffinityFunction.DFLT_PARTITION_COUNT, 0, 1));
    expCaches.put("c1", new T3<>(RendezvousAffinityFunction.DFLT_PARTITION_COUNT, 1, 2));
    checkResolverCachesInfo(srv0, expCaches);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) CommunicationFailureResolver(org.apache.ignite.configuration.CommunicationFailureResolver) HashMap(java.util.HashMap) ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi) CountDownLatch(java.util.concurrent.CountDownLatch) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) Ignite(org.apache.ignite.Ignite) ArrayList(java.util.ArrayList) List(java.util.List) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) T3(org.apache.ignite.internal.util.typedef.T3) Test(org.junit.Test)

Example 17 with ZookeeperDiscoverySpi

use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.

the class ZookeeperDiscoveryCommunicationFailureTest method testNoOpCommunicationErrorResolve_4.

/**
 * Tests case when Coordinator fails while resolve process is in progress.
 *
 * @throws Exception If failed.
 */
@Test
public void testNoOpCommunicationErrorResolve_4() throws Exception {
    testCommSpi = true;
    sesTimeout = 2000;
    commFailureRslvr = NoOpCommunicationFailureResolver.FACTORY;
    startGrid(0);
    startGridsMultiThreaded(1, 3);
    ZkTestCommunicationSpi commSpi = ZkTestCommunicationSpi.testSpi(ignite(3));
    commSpi.pingLatch = new CountDownLatch(1);
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() {
            ZookeeperDiscoverySpi spi = spi(ignite(1));
            spi.resolveCommunicationFailure(ignite(2).cluster().localNode(), new Exception("test"));
            return null;
        }
    });
    U.sleep(1000);
    assertFalse(fut.isDone());
    stopGrid(0);
    commSpi.pingLatch.countDown();
    fut.get();
    waitForTopology(3);
}
Also used : ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) Test(org.junit.Test)

Example 18 with ZookeeperDiscoverySpi

use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.

the class ZookeeperDiscoveryCommunicationFailureTest method testDefaultCommunicationFailureResolver2.

/**
 * @throws Exception If failed.
 */
@Test
public void testDefaultCommunicationFailureResolver2() throws Exception {
    testCommSpi = true;
    sesTimeout = 5000;
    startGrids(3);
    startClientGridsMultiThreaded(3, 2);
    ZkTestCommunicationSpi.testSpi(ignite(0)).initCheckResult(5, 0, 1);
    ZkTestCommunicationSpi.testSpi(ignite(1)).initCheckResult(5, 0, 1);
    ZkTestCommunicationSpi.testSpi(ignite(2)).initCheckResult(5, 2, 3, 4);
    ZkTestCommunicationSpi.testSpi(ignite(3)).initCheckResult(5, 2, 3, 4);
    ZkTestCommunicationSpi.testSpi(ignite(4)).initCheckResult(5, 2, 3, 4);
    ZookeeperDiscoverySpi spi = spi(ignite(0));
    spi.resolveCommunicationFailure(spi.getNode(ignite(1).cluster().localNode().id()), new Exception("test"));
    waitForTopology(2);
}
Also used : 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 19 with ZookeeperDiscoverySpi

use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.

the class ZookeeperDiscoveryCommunicationFailureTest method checkResolverCachesInfo.

/**
 * @param crd Coordinator node.
 * @param expCaches Expected caches info.
 * @throws Exception If failed.
 */
private void checkResolverCachesInfo(Ignite crd, Map<String, T3<Integer, Integer, Integer>> expCaches) throws Exception {
    CacheInfoCommunicationFailureResolver rslvr = (CacheInfoCommunicationFailureResolver) crd.configuration().getCommunicationFailureResolver();
    assertNotNull(rslvr);
    ZookeeperDiscoverySpi spi = spi(crd);
    rslvr.latch = new CountDownLatch(1);
    ZkTestCommunicationSpi.testSpi(crd).initCheckResult(crd.cluster().nodes().size(), 0);
    spi.resolveCommunicationFailure(spi.getRemoteNodes().iterator().next(), new Exception("test"));
    assertTrue(rslvr.latch.await(10, SECONDS));
    rslvr.checkCachesInfo(expCaches);
    rslvr.reset();
}
Also used : ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 20 with ZookeeperDiscoverySpi

use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.

the class ZookeeperDiscoverySpiTestHelper method waitSpi.

/**
 * @param nodeName Node name.
 * @return Node's discovery SPI.
 * @throws Exception If failed.
 */
ZookeeperDiscoverySpi waitSpi(final String nodeName, ConcurrentHashMap<String, ZookeeperDiscoverySpi> spis) throws Exception {
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            ZookeeperDiscoverySpi spi = spis.get(nodeName);
            return spi != null && GridTestUtils.getFieldValue(spi, "impl") != null;
        }
    }, 5000);
    ZookeeperDiscoverySpi spi = spis.get(nodeName);
    Assert.assertNotNull("Failed to get SPI for node: " + nodeName, spi);
    return spi;
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi)

Aggregations

ZookeeperDiscoverySpi (org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi)21 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)13 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)12 Test (org.junit.Test)10 Ignite (org.apache.ignite.Ignite)9 UUID (java.util.UUID)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 ArrayList (java.util.ArrayList)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ZkTestClientCnxnSocketNIO (org.apache.zookeeper.ZkTestClientCnxnSocketNIO)3 HashMap (java.util.HashMap)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)2 Event (org.apache.ignite.events.Event)2 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)2 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)2 BitSet (java.util.BitSet)1