curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cammcken...@apache.org
Subject git commit: CURATOR-79 - Modified exception handling to occur in a single block. Updated some minor unit test niceties.
Date Mon, 11 Aug 2014 23:27:45 GMT
Repository: curator
Updated Branches:
  refs/heads/CURATOR-79 5398b72f0 -> c92ffee9d


CURATOR-79 - Modified exception handling to occur in a single block.
Updated some minor unit test niceties.

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

Branch: refs/heads/CURATOR-79
Commit: c92ffee9de614aa43bf56a5ef9533b59cb9ded81
Parents: 5398b72
Author: Cam McKenzie <cammckenzie@apache.org>
Authored: Tue Aug 12 09:27:05 2014 +1000
Committer: Cam McKenzie <cammckenzie@apache.org>
Committed: Tue Aug 12 09:27:05 2014 +1000

----------------------------------------------------------------------
 .../framework/imps/CreateBuilderImpl.java       | 31 +++++---------------
 .../recipes/locks/TestInterProcessMutex.java    |  4 +--
 2 files changed, 9 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/c92ffee9/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
index 3028cd5..70b92ab 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
@@ -452,43 +452,26 @@ class CreateBuilderImpl implements CreateBuilder, BackgroundOperation<PathAndByt
         {
             return pathInForeground(adjustedPath, data);
         }
-        catch ( KeeperException.ConnectionLossException e )
+        catch ( Exception e)
         {
-            if ( protectedId != null )
+            if ( ( e instanceof KeeperException.ConnectionLossException ||
+                !( e instanceof KeeperException )) && protectedId != null )
             {
                 /*
-                 * CURATOR-45 : we don't know if the create operation was successful or not,
+                 * CURATOR-45 + CURATOR-79: we don't know if the create operation was successful
or not,
                  * register the znode to be sure it is deleted later.
                  */
-                findAndDeleteProtectedNodeInBackground(adjustedPath, protectedId, null);
+                String localProtectedId = protectedId;
+                findAndDeleteProtectedNodeInBackground(adjustedPath, localProtectedId, null);
                 /*
                 * The current UUID is scheduled to be deleted, it is not safe to use it again.
                 * If this builder is used again later create a new UUID
                 */
                 protectedId = UUID.randomUUID().toString();
             }
+            
             throw e;
         }
-        catch ( KeeperException e )
-        {
-            throw e;
-        }
-        catch ( Exception e )
-        {
-            if ( protectedId != null )
-            {
-                /*
-                 * CURATOR-79 - Handle an runtime exception's here and treat the
-                 * same as a connection loss exception. This is necessary as, from
-                 * the clients point of view, an exception has been thrown and the
-                 * zNode should not exist on ZK. This was causing deadlock in the
-                 * locking recipes.
-                 */
-                findAndDeleteProtectedNodeInBackground(adjustedPath, protectedId, null);
-                protectedId = UUID.randomUUID().toString();
-            }
-            throw e;            
-        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/curator/blob/c92ffee9/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutex.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutex.java
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutex.java
index 85e5c39..83f5473 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutex.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutex.java
@@ -155,12 +155,12 @@ public class TestInterProcessMutex extends TestInterProcessMutexBase
             //We need to reinterrupt in the debugUnhandledErrorListener above.
             Thread.currentThread().interrupt();
             lock.acquire();
-            Assert.fail();
+            Assert.fail("Lock acquisition succeeded when failure was expected");
         }
         catch(InterruptedException e)
         {
             //Expected lock to have failed.
-            Assert.assertTrue(!lock.isOwnedByCurrentThread());
+            Assert.assertFalse(lock.isOwnedByCurrentThread());
         }
         
         try


Mime
View raw message