curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject curator git commit: Fixed testRetry() for new LOST behavior
Date Sat, 22 Aug 2015 16:06:39 GMT
Repository: curator
Updated Branches:
  refs/heads/CURATOR-247 847cc0d24 -> ec2f9bd55


Fixed testRetry() for new LOST behavior


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

Branch: refs/heads/CURATOR-247
Commit: ec2f9bd555d01b324bd5ef690b1036d98e1f3702
Parents: 847cc0d
Author: randgalt <randgalt@apache.org>
Authored: Sat Aug 22 11:06:33 2015 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Sat Aug 22 11:06:33 2015 -0500

----------------------------------------------------------------------
 .../org/apache/curator/CuratorZookeeperClient.java | 17 +++++++++++++++--
 .../main/java/org/apache/curator/RetryLoop.java    | 12 +++++++++++-
 .../java/org/apache/curator/utils/DebugUtils.java  | 12 +++++++-----
 .../curator/framework/imps/TestFrameworkEdges.java |  4 +++-
 .../org/apache/curator/test/BaseClassForTests.java |  5 +++++
 5 files changed, 41 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/ec2f9bd5/curator-client/src/main/java/org/apache/curator/CuratorZookeeperClient.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/CuratorZookeeperClient.java b/curator-client/src/main/java/org/apache/curator/CuratorZookeeperClient.java
index ce6e9d3..a065d78 100644
--- a/curator-client/src/main/java/org/apache/curator/CuratorZookeeperClient.java
+++ b/curator-client/src/main/java/org/apache/curator/CuratorZookeeperClient.java
@@ -19,6 +19,7 @@
 
 package org.apache.curator;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import org.apache.curator.drivers.TracerDriver;
 import org.apache.curator.ensemble.EnsembleProvider;
@@ -51,6 +52,7 @@ public class CuratorZookeeperClient implements Closeable
     private final AtomicBoolean started = new AtomicBoolean(false);
     private final AtomicReference<TracerDriver> tracer = new AtomicReference<TracerDriver>(new
DefaultTracerDriver());
     private final boolean manageTimeouts;
+    private final AtomicReference<Exception> debugException = new AtomicReference<>();
 
     /**
      *
@@ -207,8 +209,7 @@ public class CuratorZookeeperClient implements Closeable
 
         if ( !started.compareAndSet(false, true) )
         {
-            IllegalStateException ise = new IllegalStateException("Already started");
-            throw ise;
+            throw new IllegalStateException("Already started");
         }
 
         state.start();
@@ -337,6 +338,18 @@ public class CuratorZookeeperClient implements Closeable
         return manageTimeouts;
     }
 
+    @VisibleForTesting
+    public void setDebugException(Exception e)
+    {
+        debugException.set(e);
+    }
+
+    @VisibleForTesting
+    Exception getDebugException()
+    {
+        return debugException.get();
+    }
+
     void addParentWatcher(Watcher watcher)
     {
         state.addParentWatcher(watcher);

http://git-wip-us.apache.org/repos/asf/curator/blob/ec2f9bd5/curator-client/src/main/java/org/apache/curator/RetryLoop.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/RetryLoop.java b/curator-client/src/main/java/org/apache/curator/RetryLoop.java
index 8d77cf7..f6abf21 100644
--- a/curator-client/src/main/java/org/apache/curator/RetryLoop.java
+++ b/curator-client/src/main/java/org/apache/curator/RetryLoop.java
@@ -74,6 +74,7 @@ public class RetryLoop
             unit.sleep(time);
         }
     };
+    private static final boolean checkInjectedDebugExceptions = Boolean.getBoolean(DebugUtils.PROPERTY_CHECK_INJECTED_DEBUG_EXCEPTIONS);
 
     /**
      * Returns the default retry sleeper
@@ -103,13 +104,22 @@ public class RetryLoop
         {
             try
             {
+                if ( checkInjectedDebugExceptions )
+                {
+                    Exception debugException = client.getDebugException();
+                    if ( debugException != null )
+                    {
+                        throw debugException;
+                    }
+                }
+
                 client.internalBlockUntilConnectedOrTimedOut();
                 if ( !client.isConnected() && !client.retryConnectionTimeouts() )
                 {
                     connectionFailed = true;
                     break;
                 }
-                
+
                 result = proc.call();
                 retryLoop.markComplete();
             }

http://git-wip-us.apache.org/repos/asf/curator/blob/ec2f9bd5/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java b/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java
index 383bc13..0e473fb 100644
--- a/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java
+++ b/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java
@@ -16,15 +16,17 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.utils;
 
 public class DebugUtils
 {
-    public static final String          PROPERTY_LOG_EVENTS = "curator-log-events";
-    public static final String          PROPERTY_DONT_LOG_CONNECTION_ISSUES = "curator-dont-log-connection-problems";
-    public static final String          PROPERTY_LOG_ONLY_FIRST_CONNECTION_ISSUE_AS_ERROR_LEVEL
= "curator-log-only-first-connection-issue-as-error-level";
-    public static final String          PROPERTY_REMOVE_WATCHERS_IN_FOREGROUND = "curator-remove-watchers-in-foreground";
-    public static final String          PROPERTY_RETRY_FAILED_TESTS = "curator-retry-failed-tests";
+    public static final String PROPERTY_LOG_EVENTS = "curator-log-events";
+    public static final String PROPERTY_DONT_LOG_CONNECTION_ISSUES = "curator-dont-log-connection-problems";
+    public static final String PROPERTY_LOG_ONLY_FIRST_CONNECTION_ISSUE_AS_ERROR_LEVEL =
"curator-log-only-first-connection-issue-as-error-level";
+    public static final String PROPERTY_REMOVE_WATCHERS_IN_FOREGROUND = "curator-remove-watchers-in-foreground";
+    public static final String PROPERTY_RETRY_FAILED_TESTS = "curator-retry-failed-tests";
+    public static final String PROPERTY_CHECK_INJECTED_DEBUG_EXCEPTIONS = "curator-check-injected-debug-exceptions";
 
     private DebugUtils()
     {

http://git-wip-us.apache.org/repos/asf/curator/blob/ec2f9bd5/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
index cd3ae77..7407eab 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
@@ -32,7 +32,6 @@ import org.apache.curator.framework.state.ConnectionStateListener;
 import org.apache.curator.retry.RetryOneTime;
 import org.apache.curator.test.BaseClassForTests;
 import org.apache.curator.test.KillSession;
-import org.apache.curator.test.TestingServer;
 import org.apache.curator.test.Timing;
 import org.apache.curator.utils.CloseableUtils;
 import org.apache.curator.utils.ZKPaths;
@@ -425,6 +424,7 @@ public class TestFrameworkEdges extends BaseClassForTests
                         {
                             throw new Error(e);
                         }
+                        client.getZookeeperClient().setDebugException(null);
                     }
                     try
                     {
@@ -442,6 +442,7 @@ public class TestFrameworkEdges extends BaseClassForTests
             server.stop();
 
             // test foreground retry
+            client.getZookeeperClient().setDebugException(new KeeperException.ConnectionLossException());
             client.checkExists().forPath("/hey");
             Assert.assertTrue(semaphore.tryAcquire(MAX_RETRIES, timing.forWaiting().seconds(),
TimeUnit.SECONDS), "Remaining leases: " + semaphore.availablePermits());
 
@@ -456,6 +457,7 @@ public class TestFrameworkEdges extends BaseClassForTests
             server.stop();
 
             // test background retry
+            client.getZookeeperClient().setDebugException(new KeeperException.ConnectionLossException());
             client.checkExists().inBackground().forPath("/hey");
             Assert.assertTrue(semaphore.tryAcquire(MAX_RETRIES, timing.forWaiting().seconds(),
TimeUnit.SECONDS), "Remaining leases: " + semaphore.availablePermits());
         }

http://git-wip-us.apache.org/repos/asf/curator/blob/ec2f9bd5/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java b/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java
index c9f3524..55dcb61 100644
--- a/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java
+++ b/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java
@@ -44,17 +44,20 @@ public class BaseClassForTests
     private static final String INTERNAL_PROPERTY_DONT_LOG_CONNECTION_ISSUES;
     private static final String INTERNAL_PROPERTY_REMOVE_WATCHERS_IN_FOREGROUND;
     private static final String INTERNAL_RETRY_FAILED_TESTS;
+    private static final String INTERNAL_CHECK_INJECTED_DEBUG_EXCEPTIONS;
 
     static
     {
         String logConnectionIssues = null;
         String retryFailedTests = null;
+        String checkInjectedDebugExceptions = null;
         try
         {
             // use reflection to avoid adding a circular dependency in the pom
             Class<?> debugUtilsClazz = Class.forName("org.apache.curator.utils.DebugUtils");
             logConnectionIssues = (String)debugUtilsClazz.getField("PROPERTY_DONT_LOG_CONNECTION_ISSUES").get(null);
             retryFailedTests = (String)debugUtilsClazz.getField("PROPERTY_RETRY_FAILED_TESTS").get(null);
+            checkInjectedDebugExceptions = (String)debugUtilsClazz.getField("PROPERTY_CHECK_INJECTED_DEBUG_EXCEPTIONS").get(null);
         }
         catch ( Exception e )
         {
@@ -62,6 +65,7 @@ public class BaseClassForTests
         }
         INTERNAL_PROPERTY_DONT_LOG_CONNECTION_ISSUES = logConnectionIssues;
         INTERNAL_RETRY_FAILED_TESTS = retryFailedTests;
+        INTERNAL_CHECK_INJECTED_DEBUG_EXCEPTIONS = checkInjectedDebugExceptions;
         String s = null;
         try
         {
@@ -114,6 +118,7 @@ public class BaseClassForTests
             System.setProperty(INTERNAL_PROPERTY_DONT_LOG_CONNECTION_ISSUES, "true");
         }
         System.setProperty(INTERNAL_PROPERTY_REMOVE_WATCHERS_IN_FOREGROUND, "true");
+        System.setProperty(INTERNAL_CHECK_INJECTED_DEBUG_EXCEPTIONS, "true");
 
         while ( server == null )
         {


Mime
View raw message