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);
}
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);
}
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);
}
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();
}
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;
}
Aggregations