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 2014/07/21 02:30:12 UTC

[1/2] git commit: CURATOR-121 - Modified exception handling on the operation queue to ignore InterruptedException during shutdown. Added additional unit test for this case.

Repository: curator
Updated Branches:
  refs/heads/master c358bbce9 -> 67399386f


CURATOR-121 - Modified exception handling on the operation queue to
ignore InterruptedException during shutdown. Added additional unit test
for this case.

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

Branch: refs/heads/master
Commit: 51109813ebd3104b74181be26532c3692f41bb02
Parents: c358bbc
Author: Cam McKenzie <ca...@apache.org>
Authored: Sun Jul 20 04:10:32 2014 +1000
Committer: Cam McKenzie <ca...@apache.org>
Committed: Sun Jul 20 04:10:32 2014 +1000

----------------------------------------------------------------------
 .../recipes/cache/PathChildrenCache.java        | 11 ++++-
 .../recipes/cache/TestPathChildrenCache.java    | 46 ++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/51109813/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
index dd41b5f..077cfb3 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
@@ -745,7 +745,7 @@ public class PathChildrenCache implements Closeable
         return (uninitializedChildren.size() != 0);
     }
 
-    private void offerOperation(final Operation operation)
+    void offerOperation(final Operation operation)
     {
         if ( operationsQuantizer.add(operation) )
         {
@@ -761,6 +761,15 @@ public class PathChildrenCache implements Closeable
                             operationsQuantizer.remove(operation);
                             operation.invoke();
                         }
+                        catch ( InterruptedException e )
+                        {
+                            //We expect to get interrupted during shutdown,
+                            //so just ignore these events
+                            if ( state.get() != State.CLOSED )
+                            {
+                                handleException(e);    
+                            }
+                        }
                         catch ( Exception e )
                         {
                             handleException(e);

http://git-wip-us.apache.org/repos/asf/curator/blob/51109813/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
index bf57ed8..653a8b1 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
@@ -841,6 +841,52 @@ public class TestPathChildrenCache extends BaseClassForTests
         }
 
     }
+    
+    /**
+     * Tests the case where there's an outstanding operation being executed when the cache is
+     * shut down. See CURATOR-121, this was causing misleading warning messages to be logged.
+     * @throws Exception
+     */
+    @Test
+    public void testInterruptedOperationOnShutdown() throws Exception
+    {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), 30000, 30000, new RetryOneTime(1));
+        client.start();
+
+        try
+        {
+            final CountDownLatch latch = new CountDownLatch(1);
+            final PathChildrenCache cache = new PathChildrenCache(client, "/test", false) {
+                @Override
+                protected void handleException(Throwable e)
+                {
+                    latch.countDown();
+                }
+            };
+            cache.start();
+
+            cache.offerOperation(new Operation()
+            {
+
+                @Override
+                public void invoke() throws Exception
+                {
+                    Thread.sleep(5000);
+                }
+            });
+            
+            Thread.sleep(1000);
+
+            cache.close();
+            
+            latch.await(5, TimeUnit.SECONDS);
+            
+            Assert.assertTrue(latch.getCount() == 1, "Unexpected exception occurred");
+        } finally
+        {
+            CloseableUtils.closeQuietly(client);
+        }
+    }    
 
     public static class ExecuteCalledWatchingExecutorService extends DelegatingExecutorService
     {


[2/2] git commit: COMM-121 - Reset interrupted status when catching InterruptedException.

Posted by ca...@apache.org.
COMM-121 - Reset interrupted status when catching InterruptedException.

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

Branch: refs/heads/master
Commit: 67399386f51948ddae898362834d2d3f852c013d
Parents: 5110981
Author: Cam McKenzie <ca...@apache.org>
Authored: Mon Jul 21 09:57:02 2014 +1000
Committer: Cam McKenzie <ca...@apache.org>
Committed: Mon Jul 21 09:57:02 2014 +1000

----------------------------------------------------------------------
 .../apache/curator/framework/recipes/cache/PathChildrenCache.java  | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/67399386/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
index 077cfb3..ad433d8 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
@@ -769,6 +769,8 @@ public class PathChildrenCache implements Closeable
                             {
                                 handleException(e);    
                             }
+                            
+                            Thread.currentThread().interrupt();
                         }
                         catch ( Exception e )
                         {