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