You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2016/03/29 19:20:26 UTC

[1/2] curator git commit: Check for initial create in setData()

Repository: curator
Updated Branches:
  refs/heads/master 3d1fca231 -> 73cd00aed


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/master
Commit: f4dcec3e6f80616f76f428c25787ff3293273a5a
Parents: 3d1fca2
Author: randgalt <ra...@apache.org>
Authored: Mon Mar 28 20:32:55 2016 -0500
Committer: randgalt <ra...@apache.org>
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();


[2/2] curator git commit: Added comment

Posted by ra...@apache.org.
Added comment


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/73cd00ae
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/73cd00ae
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/73cd00ae

Branch: refs/heads/master
Commit: 73cd00aed8e42cf38dcbf5b1dd36826b3041ee13
Parents: f4dcec3
Author: randgalt <ra...@apache.org>
Authored: Mon Mar 28 21:18:58 2016 -0500
Committer: randgalt <ra...@apache.org>
Committed: Mon Mar 28 21:18:58 2016 -0500

----------------------------------------------------------------------
 .../apache/curator/framework/recipes/nodes/PersistentNode.java  | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/73cd00ae/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 bf11f81..5f94ea1 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
@@ -309,7 +309,10 @@ public class PersistentNode implements Closeable
     }
 
     /**
-     * Set data that node should set in ZK also writes the data to the node
+     * Set data that node should set in ZK also writes the data to the node. NOTE: it
+     * is an error to call this method after {@link #start()} but before the initial create
+     * has completed. Use {@link #waitForInitialCreate(long, TimeUnit)} to ensure initial
+     * creation.
      *
      * @param data new data value
      * @throws Exception errors