use of org.apache.curator.retry.RetryNTimes in project xian by happyyangyuan.
the class TestLockCleanlinessWithFaults method testNodeDeleted.
@Test
public void testNodeDeleted() throws Exception {
final String PATH = "/foo/bar";
CuratorFramework client = null;
try {
client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryNTimes(0, 0));
client.start();
client.create().creatingParentsIfNeeded().forPath(PATH);
Assert.assertEquals(client.checkExists().forPath(PATH).getNumChildren(), 0);
LockInternals internals = new LockInternals(client, new StandardLockInternalsDriver(), PATH, "lock-", 1) {
@Override
List<String> getSortedChildren() throws Exception {
throw new KeeperException.NoNodeException();
}
};
try {
internals.attemptLock(0, null, null);
Assert.fail();
} catch (KeeperException.NoNodeException dummy) {
// expected
}
// make sure no nodes are left lying around
Assert.assertEquals(client.checkExists().forPath(PATH).getNumChildren(), 0);
} finally {
CloseableUtils.closeQuietly(client);
}
}
use of org.apache.curator.retry.RetryNTimes in project xian by happyyangyuan.
the class TestSharedCount method testDisconnectEventOnWatcherDoesNotRetry.
@Test
public void testDisconnectEventOnWatcherDoesNotRetry() throws Exception {
final CountDownLatch gotSuspendEvent = new CountDownLatch(1);
CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryNTimes(10, 1000));
curatorFramework.start();
curatorFramework.blockUntilConnected();
SharedCount sharedCount = new SharedCount(curatorFramework, "/count", 10);
sharedCount.start();
curatorFramework.getConnectionStateListenable().addListener(new ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if (newState == ConnectionState.SUSPENDED) {
gotSuspendEvent.countDown();
}
}
});
try {
server.stop();
// if watcher goes into 10second retry loop we won't get timely notification
Assert.assertTrue(gotSuspendEvent.await(5, TimeUnit.SECONDS));
} finally {
CloseableUtils.closeQuietly(sharedCount);
CloseableUtils.closeQuietly(curatorFramework);
}
}
use of org.apache.curator.retry.RetryNTimes in project xian by happyyangyuan.
the class TestLeaderSelectorEdges method createProtectedNodeInBackgroundTest.
/**
* Create a protected node in background with a retry policy
*/
@Test
public void createProtectedNodeInBackgroundTest() throws Exception {
final CuratorFramework client = CuratorFrameworkFactory.builder().connectString(server.getConnectString()).retryPolicy(new RetryNTimes(2, 1)).connectionTimeoutMs(100).sessionTimeoutMs(60000).build();
final CountDownLatch latch = new CountDownLatch(1);
client.start();
try {
client.create().forPath(ChaosMonkeyCnxnFactory.CHAOS_ZNODE);
client.create().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).inBackground(new BackgroundCallback() {
public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
log.info("Receive event {}", event.toString());
if (event.getResultCode() == KeeperException.Code.CONNECTIONLOSS.intValue()) {
latch.countDown();
}
}
}).forPath(ChaosMonkeyCnxnFactory.CHAOS_ZNODE_PREFIX + "foo-");
Assert.assertTrue(latch.await(30, TimeUnit.SECONDS), "Callback has not been called");
// Wait for the znode to be deleted
Thread.sleep(ChaosMonkeyCnxnFactory.LOCKOUT_DURATION_MS * 2);
// Check that there is no znode
final int children = client.getChildren().forPath(ChaosMonkeyCnxnFactory.CHAOS_ZNODE).size();
Assert.assertEquals(children, 0, "Still " + children + " znodes under " + ChaosMonkeyCnxnFactory.CHAOS_ZNODE + " lock");
} finally {
client.close();
}
}
Aggregations