Repository: curator Updated Branches: refs/heads/CURATOR-3.0 88da05c03 -> f7ef2f1e0
Check for initial create in setData() Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/f4dcec3e Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/f4dcec3e Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/f4dcec3e Branch: refs/heads/CURATOR-3.0 Commit: f4dcec3e6f80616f76f428c25787ff3293273a5a Parents: 3d1fca2 Author: randgalt <[email protected]> Authored: Mon Mar 28 20:32:55 2016 -0500 Committer: randgalt <[email protected]> Committed: Mon Mar 28 20:32:55 2016 -0500 ---------------------------------------------------------------------- .../framework/recipes/nodes/PersistentNode.java | 1 + .../recipes/nodes/TestPersistentNode.java | 31 ++++++++++++++++++++ 2 files changed, 32 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/f4dcec3e/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java index c472fdd..bf11f81 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java @@ -317,6 +317,7 @@ public class PersistentNode implements Closeable public void setData(byte[] data) throws Exception { data = Preconditions.checkNotNull(data, "data cannot be null"); + Preconditions.checkState(nodePath.get() != null, "initial create has not been processed. Call waitForInitialCreate() to ensure."); this.data.set(Arrays.copyOf(data, data.length)); if ( isActive() ) { http://git-wip-us.apache.org/repos/asf/curator/blob/f4dcec3e/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentNode.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentNode.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentNode.java index 386a0fe..ac8c65d 100644 --- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentNode.java +++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentNode.java @@ -32,6 +32,37 @@ import java.util.concurrent.TimeUnit; public class TestPersistentNode extends BaseClassForTests { @Test + public void testQuickSetData() throws Exception + { + final byte[] TEST_DATA = "hey".getBytes(); + final byte[] ALT_TEST_DATA = "there".getBytes(); + + Timing timing = new Timing(); + PersistentNode pen = null; + CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); + try + { + client.start(); + pen = new PersistentNode(client, CreateMode.PERSISTENT, false, "/test", TEST_DATA); + pen.start(); + try + { + pen.setData(ALT_TEST_DATA); + Assert.fail("IllegalStateException should have been thrown"); + } + catch ( IllegalStateException dummy ) + { + // expected + } + } + finally + { + CloseableUtils.closeQuietly(pen); + CloseableUtils.closeQuietly(client); + } + } + + @Test public void testBasic() throws Exception { final byte[] TEST_DATA = "hey".getBytes();
