curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cammcken...@apache.org
Subject curator git commit: CURATOR-161 - Updates to naming based on review. Added unit test for local() case, which has still not been resolved. Need to make changes to the framework to allow some ZK calls (local watch removal in this case) to occur even if no
Date Fri, 08 May 2015 04:08:10 GMT
Repository: curator
Updated Branches:
  refs/heads/CURATOR-161 b2b9af31c -> a83090bea


CURATOR-161 - Updates to naming based on review. Added unit test for
local() case, which has still not been resolved. Need to make changes to
the framework to allow some ZK calls (local watch removal in this case) to
occur even if no ZK connection is available.


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

Branch: refs/heads/CURATOR-161
Commit: a83090bea7cdd69aa094ddaa9d4a70f401c28861
Parents: b2b9af3
Author: Cameron McKenzie <cameron@unico.com.au>
Authored: Fri May 8 14:05:18 2015 +1000
Committer: Cameron McKenzie <cameron@unico.com.au>
Committed: Fri May 8 14:07:48 2015 +1000

----------------------------------------------------------------------
 .../curator/framework/CuratorFramework.java     |  2 +-
 .../framework/api/RemoveWatchesBuilder.java     |  6 +-
 .../framework/api/RemoveWatchesLocal.java       |  3 +-
 .../framework/imps/CuratorFrameworkImpl.java    |  2 +-
 .../imps/RemoveWatchesBuilderImpl.java          | 10 +--
 .../framework/imps/TestRemoveWatches.java       | 67 +++++++++++++++++---
 6 files changed, 70 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/a83090be/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
index 9d1039a..4b30fd4 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
@@ -148,7 +148,7 @@ public interface CuratorFramework extends Closeable
      * Start a remove watches builder.
      * @return builder object
      */
-    public RemoveWatchesBuilder removeWatches();    
+    public RemoveWatchesBuilder watches();    
 
     /**
      * Returns the listenable interface for the Connect State

http://git-wip-us.apache.org/repos/asf/curator/blob/a83090be/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesBuilder.java
b/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesBuilder.java
index 2ed3c05..5d48a9e 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesBuilder.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesBuilder.java
@@ -12,18 +12,18 @@ public interface RemoveWatchesBuilder
      * @param watcher
      * @return
      */
-    public RemoveWatchesType watcher(Watcher watcher);
+    public RemoveWatchesType remove(Watcher watcher);
     
     /**
      * Specify the watcher to be removed
      * @param watcher
      * @return
      */
-    public RemoveWatchesType watcher(CuratorWatcher watcher);
+    public RemoveWatchesType remove(CuratorWatcher watcher);
     
     /**
      * Specify that all watches should be removed
      * @return
      */
-    public RemoveWatchesType allWatches();
+    public RemoveWatchesType removeAll();
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/a83090be/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java
b/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java
index d54638c..2e9816b 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java
@@ -10,9 +10,8 @@ public interface RemoveWatchesLocal extends BackgroundPathable<Void>
     /**
      * Specify if the client should just remove client side watches if a connection to ZK
      * is not available.
-     * @param local
      * @return
      */
-    public BackgroundPathable<Void> local(boolean local);
+    public BackgroundPathable<Void> local();
     
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/a83090be/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
index b9614ee..5caff7d 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
@@ -455,7 +455,7 @@ public class CuratorFrameworkImpl implements CuratorFramework
     }
     
     @Override
-    public RemoveWatchesBuilder removeWatches()
+    public RemoveWatchesBuilder watches()
     {
         return new RemoveWatchesBuilderImpl(this);
     }

http://git-wip-us.apache.org/repos/asf/curator/blob/a83090be/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java
b/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java
index 08f0791..5d1f945 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java
@@ -38,21 +38,21 @@ public class RemoveWatchesBuilderImpl implements RemoveWatchesBuilder,
RemoveWat
     }
     
     @Override
-    public RemoveWatchesType watcher(Watcher watcher)
+    public RemoveWatchesType remove(Watcher watcher)
     {
         this.watcher = watcher == null ? null : client.getNamespaceWatcherMap().getNamespaceWatcher(watcher);
         return this;
     }
     
     @Override
-    public RemoveWatchesType watcher(CuratorWatcher watcher)
+    public RemoveWatchesType remove(CuratorWatcher watcher)
     {
         this.watcher = watcher == null ? null : client.getNamespaceWatcherMap().getNamespaceWatcher(watcher);
         return this;
     }    
 
     @Override
-    public RemoveWatchesType allWatches()
+    public RemoveWatchesType removeAll()
     {
         this.watcher = null;
         return this;
@@ -109,9 +109,9 @@ public class RemoveWatchesBuilderImpl implements RemoveWatchesBuilder,
RemoveWat
     }
 
     @Override
-    public BackgroundPathable<Void> local(boolean local)
+    public BackgroundPathable<Void> local()
     {
-        this.local = local;
+        local = true;
         return this;
     }
     

http://git-wip-us.apache.org/repos/asf/curator/blob/a83090be/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java
index 15fb24c..b740286 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java
@@ -1,7 +1,7 @@
 package org.apache.curator.framework.imps;
 
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -52,7 +52,7 @@ public class TestRemoveWatches extends BaseClassForTests
                         
             client.checkExists().watched().forPath(path);
             
-            client.removeWatches().allWatches().ofType(WatcherType.Data).forPath(path);
+            client.watches().removeAll().ofType(WatcherType.Data).forPath(path);
             
             Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch
removal");
         }
@@ -91,7 +91,7 @@ public class TestRemoveWatches extends BaseClassForTests
                         
             client.checkExists().usingWatcher(watcher).forPath(path);
             
-            client.removeWatches().watcher(watcher).ofType(WatcherType.Data).forPath(path);
+            client.watches().remove(watcher).ofType(WatcherType.Data).forPath(path);
             
             Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch
removal");
         }
@@ -129,7 +129,7 @@ public class TestRemoveWatches extends BaseClassForTests
             
             client.checkExists().usingWatcher(watcher).forPath(path);
             
-            client.removeWatches().watcher(watcher).ofType(WatcherType.Data).forPath(path);
+            client.watches().remove(watcher).ofType(WatcherType.Data).forPath(path);
             
             Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch
removal");
         }
@@ -181,7 +181,7 @@ public class TestRemoveWatches extends BaseClassForTests
             
             client.checkExists().usingWatcher(watcher).forPath(path);
             
-            client.removeWatches().watcher(watcher).ofType(WatcherType.Any).inBackground(callback).forPath(path);
+            client.watches().remove(watcher).ofType(WatcherType.Any).inBackground(callback).forPath(path);
             
             Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch
removal");
             
@@ -219,7 +219,7 @@ public class TestRemoveWatches extends BaseClassForTests
             
             client.checkExists().usingWatcher(watcher).forPath(path);
             
-            client.removeWatches().watcher(watcher).ofType(WatcherType.Any).inBackground().forPath(path);
+            client.watches().remove(watcher).ofType(WatcherType.Any).inBackground().forPath(path);
             
             Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch
removal");
             
@@ -271,7 +271,7 @@ public class TestRemoveWatches extends BaseClassForTests
             client.checkExists().usingWatcher(watcher1).forPath(path);
             client.checkExists().usingWatcher(watcher2).forPath(path);
             
-            client.removeWatches().allWatches().ofType(WatcherType.Any).forPath(path);
+            client.watches().removeAll().ofType(WatcherType.Any).forPath(path);
             
             Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch
removal");
         }
@@ -279,5 +279,56 @@ public class TestRemoveWatches extends BaseClassForTests
         {
             CloseableUtils.closeQuietly(client);
         }
-    }    
+    }  
+    
+    /**
+     * TODO: THIS IS STILL A WORK IN PROGRESS. local() is currently broken if no connection
to ZK is available.
+     * @throws Exception
+     */
+    @Test
+    public void testRemoveLocalWatch() throws Exception {
+        Timing timing = new Timing();
+        CuratorFramework client = CuratorFrameworkFactory.builder().
+                connectString(server.getConnectString()).
+                retryPolicy(new RetryOneTime(1)).
+                build();
+        try
+        {
+            client.start();
+            
+            final String path = "/";
+            
+            final CountDownLatch removedLatch = new CountDownLatch(1);
+            
+            Watcher watcher = new Watcher()
+            {                
+                @Override
+                public void process(WatchedEvent event)
+                {
+                    if(event.getPath() == null || event.getType() == null) {
+                        return;
+                    }
+                    
+                    if(event.getPath().equals(path) && event.getType() == EventType.DataWatchRemoved)
{
+                        removedLatch.countDown();
+                    }
+                }
+            };            
+            
+            client.checkExists().usingWatcher(watcher).forPath(path);
+            
+            //Stop the server so we can check if we can remove watches locally when offline
+            server.stop();
+            
+            timing.sleepABit();
+            
+            client.watches().removeAll().ofType(WatcherType.Any).local().forPath(path);
+            
+            Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch
removal");
+        }
+        finally
+        {
+            CloseableUtils.closeQuietly(client);
+        }
+    }
 }


Mime
View raw message