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 2016/06/14 22:30:41 UTC

[1/2] curator git commit: [CURATOR-331] Make unhandledErrorListenable in TreeCache

Repository: curator
Updated Branches:
  refs/heads/CURATOR-331 [created] dd8170507


[CURATOR-331] Make unhandledErrorListenable in TreeCache


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

Branch: refs/heads/CURATOR-331
Commit: 7ae8c2da7eb401e376030643770d408fdeaa8239
Parents: 5584a61
Author: Julie Kim <kj...@gmail.com>
Authored: Sat Jun 4 17:30:19 2016 +0900
Committer: Julie Kim <kj...@gmail.com>
Committed: Sat Jun 4 17:30:19 2016 +0900

----------------------------------------------------------------------
 .../framework/recipes/cache/TreeCache.java      |  2 +-
 .../framework/recipes/cache/TestTreeCache.java  | 50 ++++++++++++++++++--
 2 files changed, 48 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/7ae8c2da/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 914d336..95b8b99 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
@@ -633,7 +633,7 @@ public class TreeCache implements Closeable
      * TODO: consider making public.
      */
     @VisibleForTesting
-    Listenable<UnhandledErrorListener> getUnhandledErrorListenable()
+    public Listenable<UnhandledErrorListener> getUnhandledErrorListenable()
     {
         return errorListeners;
     }

http://git-wip-us.apache.org/repos/asf/curator/blob/7ae8c2da/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 2cf9e70..2d0ae83 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
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -21,12 +21,15 @@ package org.apache.curator.framework.recipes.cache;
 
 import com.google.common.collect.ImmutableSet;
 import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.api.UnhandledErrorListener;
+import org.apache.curator.framework.recipes.cache.TreeCacheEvent.Type;
 import org.apache.curator.test.KillSession;
 import org.apache.curator.utils.CloseableUtils;
 import org.apache.zookeeper.CreateMode;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 import java.util.concurrent.Semaphore;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 public class TestTreeCache extends BaseTestTreeCache
 {
@@ -567,4 +570,45 @@ public class TestTreeCache extends BaseTestTreeCache
         assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
         assertNoMoreEvents();
     }
+
+    @Test
+    public void testErrorListener() throws Exception
+    {
+        client.create().forPath("/test");
+
+        cache = buildWithListeners(TreeCache.newBuilder(client, "/test"));
+
+        // Register a listener that throws an exception for the event
+        cache.getListenable().addListener(new TreeCacheListener()
+        {
+            @Override
+            public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception
+            {
+                if (event.getType() == Type.NODE_UPDATED) {
+                    throw new RuntimeException("Test Exception");
+                }
+            }
+        });
+
+        cache.getUnhandledErrorListenable().removeListener(errorListener);
+        final AtomicBoolean isProcessed = new AtomicBoolean(false);
+        cache.getUnhandledErrorListenable().addListener(new UnhandledErrorListener()
+        {
+            @Override
+            public void unhandledError(String message, Throwable e)
+            {
+                Assert.assertFalse(isProcessed.compareAndSet(false, true));
+            }
+        });
+
+        cache.start();
+
+        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
+        assertEvent(TreeCacheEvent.Type.INITIALIZED);
+
+        client.setData().forPath("/test", "hey there".getBytes());
+        assertEvent(TreeCacheEvent.Type.NODE_UPDATED, "/test");
+
+        assertNoMoreEvents();
+    }
 }


[2/2] curator git commit: Merge branch 'CURATOR-331' of https://github.com/julnamoo/curator into CURATOR-331

Posted by ca...@apache.org.
Merge branch 'CURATOR-331' of https://github.com/julnamoo/curator into CURATOR-331

Conflicts:
	curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java


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

Branch: refs/heads/CURATOR-331
Commit: dd8170507b2edd7bb8dbbdf4bb4277749a73144f
Parents: 31a8241 7ae8c2d
Author: Cam McKenzie <ca...@apache.org>
Authored: Wed Jun 15 08:30:17 2016 +1000
Committer: Cam McKenzie <ca...@apache.org>
Committed: Wed Jun 15 08:30:17 2016 +1000

----------------------------------------------------------------------
 .../framework/recipes/cache/TreeCache.java      |  2 +-
 .../framework/recipes/cache/TestTreeCache.java  | 51 ++++++++++++++++++--
 2 files changed, 48 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/dd817050/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/curator/blob/dd817050/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
----------------------------------------------------------------------
diff --cc curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
index b10df68,2d0ae83..62cf586
--- 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
@@@ -21,8 -21,9 +21,9 @@@ package org.apache.curator.framework.re
  
  import com.google.common.collect.ImmutableSet;
  import org.apache.curator.framework.CuratorFramework;
 +import org.apache.curator.test.KillServerSession;
- import org.apache.curator.test.KillSession;
+ import org.apache.curator.framework.api.UnhandledErrorListener;
+ import org.apache.curator.framework.recipes.cache.TreeCacheEvent.Type;
 -import org.apache.curator.test.KillSession;
  import org.apache.curator.utils.CloseableUtils;
  import org.apache.zookeeper.CreateMode;
  import org.testng.Assert;