Repository: curator Updated Branches: refs/heads/CURATOR-436 [created] d502dde1c
getSortedChildren() should ignore NoNode exceptions and just treat it as if there are no children. This works around issues with container nodes, parents not yet created, etc. Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/d502dde1 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/d502dde1 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/d502dde1 Branch: refs/heads/CURATOR-436 Commit: d502dde1c4601b2abc6d831d764561a73316bf00 Parents: 6ba4de3 Author: randgalt <[email protected]> Authored: Thu Oct 12 12:51:39 2017 +0200 Committer: randgalt <[email protected]> Committed: Thu Oct 12 12:51:39 2017 +0200 ---------------------------------------------------------------------- .../framework/recipes/locks/LockInternals.java | 33 ++++++++++++-------- .../recipes/leader/TestLeaderLatch.java | 11 +++++++ 2 files changed, 31 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/d502dde1/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/LockInternals.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/LockInternals.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/LockInternals.java index dc2f681..46820af 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/LockInternals.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/LockInternals.java @@ -149,21 +149,28 @@ public class LockInternals public static List<String> getSortedChildren(CuratorFramework client, String basePath, final String lockName, final LockInternalsSorter sorter) throws Exception { - List<String> children = client.getChildren().forPath(basePath); - List<String> sortedList = Lists.newArrayList(children); - Collections.sort - ( - sortedList, - new Comparator<String>() - { - @Override - public int compare(String lhs, String rhs) + try + { + List<String> children = client.getChildren().forPath(basePath); + List<String> sortedList = Lists.newArrayList(children); + Collections.sort + ( + sortedList, + new Comparator<String>() { - return sorter.fixForSorting(lhs, lockName).compareTo(sorter.fixForSorting(rhs, lockName)); + @Override + public int compare(String lhs, String rhs) + { + return sorter.fixForSorting(lhs, lockName).compareTo(sorter.fixForSorting(rhs, lockName)); + } } - } - ); - return sortedList; + ); + return sortedList; + } + catch ( KeeperException.NoNodeException ignore ) + { + return Collections.emptyList(); + } } public static List<String> getSortedChildren(final String lockName, final LockInternalsSorter sorter, List<String> children) http://git-wip-us.apache.org/repos/asf/curator/blob/d502dde1/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java index ef25ba6..011e4a0 100644 --- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java +++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java @@ -59,6 +59,17 @@ public class TestLeaderLatch extends BaseClassForTests private static final int MAX_LOOPS = 5; @Test + public void testUncreatedPathGetLeader() throws Exception + { + try ( CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)) ) + { + client.start(); + LeaderLatch latch = new LeaderLatch(client, "/foo/bar"); + latch.getLeader(); // CURATOR-436 - was throwing NoNodeException + } + } + + @Test public void testSessionErrorPolicy() throws Exception { Timing timing = new Timing();
