curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cammcken...@apache.org
Subject [1/2] curator git commit: [CURATOR-331] Make unhandledErrorListenable in TreeCache
Date Tue, 14 Jun 2016 22:35:41 GMT
Repository: curator
Updated Branches:
  refs/heads/master 1cc120251 -> 64767734a


[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/master
Commit: 7ae8c2da7eb401e376030643770d408fdeaa8239
Parents: 5584a61
Author: Julie Kim <kjulee114@gmail.com>
Authored: Sat Jun 4 17:30:19 2016 +0900
Committer: Julie Kim <kjulee114@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();
+    }
 }


Mime
View raw message