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/04/22 01:07:24 UTC

[27/50] curator git commit: TreeCache: Fix case where root is deleted and recraated.

TreeCache: Fix case where root is deleted and recraated.


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

Branch: refs/heads/CURATOR-154
Commit: febfceca0b7409136a16d51d211212dea621cdc5
Parents: d3c5c36
Author: Scott Blum <dr...@apache.org>
Authored: Fri Jan 16 00:24:14 2015 -0500
Committer: Scott Blum <dr...@apache.org>
Committed: Fri Jan 16 00:24:14 2015 -0500

----------------------------------------------------------------------
 .../framework/recipes/cache/TreeCache.java      |  2 +-
 .../framework/recipes/cache/TestTreeCache.java  | 24 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/febfceca/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
index fbe51df..41fc574 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
@@ -292,7 +292,7 @@ public class TreeCache implements Closeable
             if ( parent == null )
             {
                 // Root node; use an exist query to watch for existence.
-                client.checkExists().usingWatcher(this).inBackground().forPath(path);
+                client.checkExists().usingWatcher(this).inBackground(this).forPath(path);
             }
             else
             {

http://git-wip-us.apache.org/repos/asf/curator/blob/febfceca/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
index 394428e..467f32b 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
@@ -325,6 +325,30 @@ public class TestTreeCache extends BaseTestTreeCache
     }
 
     @Test
+    public void testDeleteThenCreateRoot() throws Exception
+    {
+        client.create().forPath("/test");
+        client.create().forPath("/test/foo", "one".getBytes());
+
+        cache = newTreeCacheWithListeners(client, "/test/foo");
+        cache.start();
+        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/foo");
+        assertEvent(TreeCacheEvent.Type.INITIALIZED);
+
+        client.delete().forPath("/test/foo");
+        assertEvent(TreeCacheEvent.Type.NODE_REMOVED, "/test/foo");
+        client.create().forPath("/test/foo", "two".getBytes());
+        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/foo");
+
+        client.delete().forPath("/test/foo");
+        assertEvent(TreeCacheEvent.Type.NODE_REMOVED, "/test/foo");
+        client.create().forPath("/test/foo", "two".getBytes());
+        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/foo");
+
+        assertNoMoreEvents();
+    }
+
+    @Test
     public void testKilledSession() throws Exception
     {
         client.create().forPath("/test");