Repository: curator Updated Branches: refs/heads/CURATOR-155 [created] 1e9b76e12
setData() was using the wrong path. It exhibited when SEQUENTIAL mode was used Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/1e9b76e1 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/1e9b76e1 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/1e9b76e1 Branch: refs/heads/CURATOR-155 Commit: 1e9b76e12589a0705b1328e42b2ddc026358c051 Parents: b9fb9ff Author: randgalt <randg...@apache.org> Authored: Fri Oct 24 10:44:36 2014 -0500 Committer: randgalt <randg...@apache.org> Committed: Fri Oct 24 10:44:36 2014 -0500 ---------------------------------------------------------------------- .../recipes/nodes/PersistentEphemeralNode.java | 2 +- .../nodes/TestPersistentEphemeralNode.java | 27 +++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/1e9b76e1/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java index 1f8be75..d78573c 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java @@ -302,7 +302,7 @@ public class PersistentEphemeralNode implements Closeable this.data.set(Arrays.copyOf(data, data.length)); if ( isActive() ) { - client.setData().inBackground().forPath(basePath, this.data.get()); + client.setData().inBackground().forPath(getActualPath(), this.data.get()); } } http://git-wip-us.apache.org/repos/asf/curator/blob/1e9b76e1/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java index c8a72d4..47ae757 100644 --- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java +++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java @@ -189,19 +189,29 @@ public class TestPersistentEphemeralNode extends BaseClassForTests } @Test + public void testSettingDataSequential() throws Exception + { + setDataTest(PersistentEphemeralNode.Mode.EPHEMERAL_SEQUENTIAL); + } + + @Test public void testSettingData() throws Exception { + setDataTest(PersistentEphemeralNode.Mode.EPHEMERAL); + } + + protected void setDataTest(PersistentEphemeralNode.Mode mode) throws Exception + { PersistentEphemeralNode node = null; CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); try { client.start(); - node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, PATH, "a".getBytes()); + node = new PersistentEphemeralNode(client, mode, PATH, "a".getBytes()); node.start(); Assert.assertTrue(node.waitForInitialCreate(timing.forWaiting().seconds(), TimeUnit.SECONDS)); - Assert.assertEquals(node.getActualPath(), PATH); - Assert.assertEquals(client.getData().forPath(PATH), "a".getBytes()); + Assert.assertEquals(client.getData().forPath(node.getActualPath()), "a".getBytes()); final Semaphore semaphore = new Semaphore(0); Watcher watcher = new Watcher() @@ -212,18 +222,17 @@ public class TestPersistentEphemeralNode extends BaseClassForTests semaphore.release(); } }; - client.checkExists().usingWatcher(watcher).forPath(PATH); + client.checkExists().usingWatcher(watcher).forPath(node.getActualPath()); node.setData("b".getBytes()); Assert.assertTrue(timing.acquireSemaphore(semaphore)); - Assert.assertEquals(node.getActualPath(), PATH); - Assert.assertEquals(client.getData().usingWatcher(watcher).forPath(PATH), "b".getBytes()); + Assert.assertEquals(node.getActualPath(), node.getActualPath()); + Assert.assertEquals(client.getData().usingWatcher(watcher).forPath(node.getActualPath()), "b".getBytes()); node.setData("c".getBytes()); Assert.assertTrue(timing.acquireSemaphore(semaphore)); - Assert.assertEquals(node.getActualPath(), PATH); - Assert.assertEquals(client.getData().usingWatcher(watcher).forPath(PATH), "c".getBytes()); + Assert.assertEquals(node.getActualPath(), node.getActualPath()); + Assert.assertEquals(client.getData().usingWatcher(watcher).forPath(node.getActualPath()), "c".getBytes()); node.close(); Assert.assertTrue(timing.acquireSemaphore(semaphore)); - Assert.assertTrue(client.checkExists().forPath(PATH) == null); } finally {