add testcase testDeleteChildrenConcurrently
Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/b01926d1 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/b01926d1 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/b01926d1 Branch: refs/heads/master Commit: b01926d1be18775fa6d3255038e9267a32325479 Parents: ca1e9fb Author: hebelala <[email protected]> Authored: Wed Aug 16 01:40:22 2017 +0800 Committer: hebelala <[email protected]> Committed: Wed Aug 16 01:40:22 2017 +0800 ---------------------------------------------------------------------- .../framework/imps/TestFrameworkEdges.java | 53 ++++++++++++++++++++ 1 file changed, 53 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/b01926d1/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java index db5210d..71b11e4 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java @@ -612,4 +612,57 @@ public class TestFrameworkEdges extends BaseClassForTests // correct } } + + @Test + public void testDeleteChildrenConcurrently() throws Exception { + final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); + CuratorFramework client2 = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); + try { + client.start(); + client.getZookeeperClient().blockUntilConnectedOrTimedOut(); + client2.start(); + client2.getZookeeperClient().blockUntilConnectedOrTimedOut(); + + int childCount = 5000; + for (int i = 0; i < childCount; i++) { + client.create().creatingParentsIfNeeded().forPath("/parent/child" + i); + } + + final CountDownLatch countDownLatch = new CountDownLatch(1); + new Thread(new Runnable() { + @Override + public void run() { + try { + client.delete().deletingChildrenIfNeeded().forPath("/parent"); + } catch (Exception e) { + if (e instanceof KeeperException.NoNodeException) { + Assert.fail("client delete failed, shouldn't throw NoNodeException", e); + } else { + Assert.fail("unknown exception", e); + } + } finally { + countDownLatch.countDown(); + } + } + }).start(); + + Thread.sleep(20L); + try { + client2.delete().forPath("/parent/child" + (childCount/2)); + } catch (Exception e) { + if (e instanceof KeeperException.NoNodeException) { + Assert.fail("client2 delete failed, shouldn't throw NoNodeException", e); + } else { + Assert.fail("unknown exception", e); + } + } + + Assert.assertTrue(countDownLatch.await(10, TimeUnit.SECONDS)); + + Assert.assertNull(client2.checkExists().forPath("/parent")); + } finally { + CloseableUtils.closeQuietly(client); + CloseableUtils.closeQuietly(client2); + } + } }
