Search in sources :

Example 1 with FailedDeleteManagerListener

use of org.apache.curator.framework.imps.FailedDeleteManager.FailedDeleteManagerListener in project xian by happyyangyuan.

the class TestFailedDeleteManager method testGuaranteedDeleteOnNonExistentNodeInForeground.

@Test
public void testGuaranteedDeleteOnNonExistentNodeInForeground() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    client.start();
    final AtomicBoolean pathAdded = new AtomicBoolean(false);
    ((CuratorFrameworkImpl) client).getFailedDeleteManager().debugListener = new FailedDeleteManagerListener() {

        @Override
        public void pathAddedForDelete(String path) {
            pathAdded.set(true);
        }
    };
    try {
        client.delete().guaranteed().forPath("/nonexistent");
        Assert.fail();
    } catch (NoNodeException e) {
        // Exception is expected, the delete should not be retried
        Assert.assertFalse(pathAdded.get());
    } finally {
        client.close();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CuratorFramework(org.apache.curator.framework.CuratorFramework) FailedDeleteManagerListener(org.apache.curator.framework.imps.FailedDeleteManager.FailedDeleteManagerListener) RetryOneTime(org.apache.curator.retry.RetryOneTime) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) Test(org.testng.annotations.Test)

Example 2 with FailedDeleteManagerListener

use of org.apache.curator.framework.imps.FailedDeleteManager.FailedDeleteManagerListener in project xian by happyyangyuan.

the class TestFailedDeleteManager method testGuaranteedDeleteOnNonExistentNodeInBackground.

@Test
public void testGuaranteedDeleteOnNonExistentNodeInBackground() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    client.start();
    final AtomicBoolean pathAdded = new AtomicBoolean(false);
    ((CuratorFrameworkImpl) client).getFailedDeleteManager().debugListener = new FailedDeleteManagerListener() {

        @Override
        public void pathAddedForDelete(String path) {
            pathAdded.set(true);
        }
    };
    final CountDownLatch backgroundLatch = new CountDownLatch(1);
    BackgroundCallback background = new BackgroundCallback() {

        @Override
        public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
            backgroundLatch.countDown();
        }
    };
    try {
        client.delete().guaranteed().inBackground(background).forPath("/nonexistent");
        backgroundLatch.await();
        // Exception is expected, the delete should not be retried
        Assert.assertFalse(pathAdded.get());
    } finally {
        client.close();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CuratorFramework(org.apache.curator.framework.CuratorFramework) FailedDeleteManagerListener(org.apache.curator.framework.imps.FailedDeleteManager.FailedDeleteManagerListener) RetryOneTime(org.apache.curator.retry.RetryOneTime) BackgroundCallback(org.apache.curator.framework.api.BackgroundCallback) CuratorEvent(org.apache.curator.framework.api.CuratorEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 FailedDeleteManagerListener (org.apache.curator.framework.imps.FailedDeleteManager.FailedDeleteManagerListener)2 RetryOneTime (org.apache.curator.retry.RetryOneTime)2 Test (org.testng.annotations.Test)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 BackgroundCallback (org.apache.curator.framework.api.BackgroundCallback)1 CuratorEvent (org.apache.curator.framework.api.CuratorEvent)1 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)1