You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ca...@apache.org on 2015/08/12 00:29:02 UTC

[1/4] curator git commit: CURATOR-241: Write updated data on reconnect

Repository: curator
Updated Branches:
  refs/heads/master 40b458ee1 -> 41f49ec37


CURATOR-241: Write updated data on reconnect

PersistentEphemeralNode can be initialised with certain data, then
later updated. If the client reconnects, the replacing ephemeral
should write the updated data.


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

Branch: refs/heads/master
Commit: 7fd4034e30f2ed3690226d2d78bf9f139df8b491
Parents: 3a4d541
Author: Alex Brasetvik <al...@brasetvik.com>
Authored: Mon Aug 3 00:57:51 2015 +0200
Committer: Alex Brasetvik <al...@brasetvik.com>
Committed: Mon Aug 3 01:02:19 2015 +0200

----------------------------------------------------------------------
 .../recipes/nodes/PersistentEphemeralNode.java  |  8 +++-
 .../nodes/TestPersistentEphemeralNode.java      | 41 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/7fd4034e/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 f50dca4..1011ad5 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
@@ -240,7 +240,7 @@ public class PersistentEphemeralNode implements Closeable
 
                     if(nodeExists)
                     {
-                    	client.setData().inBackground(setDataCallback).forPath(getActualPath(), data);
+                       client.setData().inBackground(setDataCallback).forPath(getActualPath(), getData());
                     }
                     else
                     {
@@ -338,10 +338,14 @@ public class PersistentEphemeralNode implements Closeable
         this.data.set(Arrays.copyOf(data, data.length));
         if ( isActive() )
         {
-            client.setData().inBackground().forPath(getActualPath(), this.data.get());
+            client.setData().inBackground().forPath(getActualPath(), getData());
         }
     }
 
+    byte[] getData() {
+        return this.data.get();
+    }
+
     private void deleteNode() throws Exception
     {
         String localNodePath = nodePath.getAndSet(null);

http://git-wip-us.apache.org/repos/asf/curator/blob/7fd4034e/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 34620ff..9f5907a 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
@@ -23,6 +23,8 @@ import com.google.common.collect.Lists;
 
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.api.BackgroundCallback;
+import org.apache.curator.framework.api.CuratorEvent;
 import org.apache.curator.framework.state.ConnectionState;
 import org.apache.curator.framework.state.ConnectionStateListener;
 import org.apache.curator.retry.RetryOneTime;
@@ -536,6 +538,45 @@ public class TestPersistentEphemeralNode extends BaseClassForTests
             node.close();
         }    	
     }
+
+    @Test
+    public void testSetUpdatedDataWhenReconnected() throws Exception
+    {
+        CuratorFramework curator = newCurator();
+
+        byte[] initialData = "Hello World".getBytes();
+        byte[] updatedData = "Updated".getBytes();
+
+        PersistentEphemeralNode node = new PersistentEphemeralNode(curator, PersistentEphemeralNode.Mode.EPHEMERAL, PATH, initialData);
+        node.start();
+        try
+        {
+            node.waitForInitialCreate(timing.forWaiting().seconds(), TimeUnit.SECONDS);
+            assertTrue(Arrays.equals(curator.getData().forPath(node.getActualPath()), initialData));
+
+            node.setData(updatedData);
+            assertTrue(Arrays.equals(curator.getData().forPath(node.getActualPath()), updatedData));
+
+            server.restart();
+
+            final CountDownLatch dataUpdateLatch = new CountDownLatch(1);
+            curator.getData().inBackground(new BackgroundCallback() {
+
+                @Override
+                public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+                    dataUpdateLatch.countDown();
+                }
+            }).forPath(node.getActualPath());
+
+            assertTrue(timing.awaitLatch(dataUpdateLatch));
+
+            assertTrue(Arrays.equals(curator.getData().forPath(node.getActualPath()), updatedData));
+        }
+        finally
+        {
+            node.close();
+        }
+    }
     
     /**
      * See CURATOR-190


[4/4] curator git commit: Merge branch 'CURATOR-241'

Posted by ca...@apache.org.
Merge branch 'CURATOR-241'


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

Branch: refs/heads/master
Commit: 41f49ec3751a1d76313c2d93da7aa72ebae2a80d
Parents: 40b458e f3ff7e7
Author: Cameron McKenzie <ca...@unico.com.au>
Authored: Tue Aug 11 07:49:32 2015 +1000
Committer: Cameron McKenzie <ca...@unico.com.au>
Committed: Tue Aug 11 07:49:32 2015 +1000

----------------------------------------------------------------------
 .../recipes/nodes/PersistentEphemeralNode.java  |  8 +++-
 .../nodes/TestPersistentEphemeralNode.java      | 41 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



[2/4] curator git commit: Make getData private and access data directly in setData

Posted by ca...@apache.org.
Make getData private and access data directly in setData


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

Branch: refs/heads/master
Commit: 5cfa4839e0798249d32b34b792b5f59f111dd022
Parents: 7fd4034
Author: Alex Brasetvik <al...@brasetvik.com>
Authored: Mon Aug 3 01:52:51 2015 +0200
Committer: Alex Brasetvik <al...@brasetvik.com>
Committed: Mon Aug 3 01:52:51 2015 +0200

----------------------------------------------------------------------
 .../curator/framework/recipes/nodes/PersistentEphemeralNode.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/5cfa4839/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 1011ad5..7a2ab73 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
@@ -338,11 +338,11 @@ public class PersistentEphemeralNode implements Closeable
         this.data.set(Arrays.copyOf(data, data.length));
         if ( isActive() )
         {
-            client.setData().inBackground().forPath(getActualPath(), getData());
+            client.setData().inBackground().forPath(getActualPath(), this.data.get());
         }
     }
 
-    byte[] getData() {
+    private byte[] getData() {
         return this.data.get();
     }
 


[3/4] curator git commit: Access data the same way

Posted by ca...@apache.org.
Access data the same way


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

Branch: refs/heads/master
Commit: f3ff7e75f305a6d52a8fc9f7e9defae4299a66a2
Parents: 5cfa483
Author: Alex Brasetvik <al...@brasetvik.com>
Authored: Mon Aug 3 02:00:44 2015 +0200
Committer: Alex Brasetvik <al...@brasetvik.com>
Committed: Mon Aug 3 02:00:44 2015 +0200

----------------------------------------------------------------------
 .../curator/framework/recipes/nodes/PersistentEphemeralNode.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/f3ff7e75/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 7a2ab73..0d963e0 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
@@ -338,7 +338,7 @@ public class PersistentEphemeralNode implements Closeable
         this.data.set(Arrays.copyOf(data, data.length));
         if ( isActive() )
         {
-            client.setData().inBackground().forPath(getActualPath(), this.data.get());
+            client.setData().inBackground().forPath(getActualPath(), getData());
         }
     }