curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cammcken...@apache.org
Subject git commit: CURATOR-121 - Modified exception handling on the operation queue to ignore InterruptedException during shutdown. Added additional unit test for this case.
Date Sun, 20 Jul 2014 22:30:23 GMT
Repository: curator
Updated Branches:
  refs/heads/CURATOR-121 [created] 51109813e


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/CURATOR-121
Commit: 51109813ebd3104b74181be26532c3692f41bb02
Parents: c358bbc
Author: Cam McKenzie <cammckenzie@apache.org>
Authored: Sun Jul 20 04:10:32 2014 +1000
Committer: Cam McKenzie <cammckenzie@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
     {


Mime
View raw message