You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2015/08/31 16:19:40 UTC

[1/4] curator git commit: CURATOR-239 - Adding RetryForever retry policy

Repository: curator
Updated Branches:
  refs/heads/master 8fae7856e -> 38011678c


CURATOR-239 - Adding RetryForever retry policy


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

Branch: refs/heads/master
Commit: 6e8c10847d4b453a1a1aeafcb6c58f51889f2d1f
Parents: 870b4d5
Author: Leandro Nunes <le...@blip.pt>
Authored: Fri Jul 24 00:06:26 2015 +0100
Committer: Leandro Nunes <le...@blip.pt>
Committed: Fri Jul 24 00:06:26 2015 +0100

----------------------------------------------------------------------
 .../org/apache/curator/retry/RetryForever.java  | 58 ++++++++++++++++++++
 .../java/org/apache/curator/TestRetryLoop.java  | 20 +++++++
 2 files changed, 78 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/6e8c1084/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java b/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java
new file mode 100644
index 0000000..27444b9
--- /dev/null
+++ b/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ *
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.retry;
+
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.RetrySleeper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.TimeUnit;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * {@link RetryPolicy} implementation that always <i>allowsRetry</i>.
+ */
+public class RetryForever implements RetryPolicy
+{
+    private static final Logger log = LoggerFactory.getLogger(RetryForever.class);
+
+    private final int retryIntervalMs;
+
+    public RetryForever(int retryIntervalMs)
+    {
+        checkArgument(retryIntervalMs > 0);
+        this.retryIntervalMs = retryIntervalMs;
+    }
+
+    @Override
+    public boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper sleeper)
+    {
+        try
+        {
+            sleeper.sleepFor(retryIntervalMs, TimeUnit.MILLISECONDS);
+        }
+        catch (InterruptedException e)
+        {
+            log.warn("Error occurred while sleeping", e);
+        }
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/6e8c1084/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java
----------------------------------------------------------------------
diff --git a/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java b/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java
index 0fa9020..17bb91e 100644
--- a/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java
+++ b/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java
@@ -19,14 +19,19 @@
 package org.apache.curator;
 
 import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.curator.retry.RetryForever;
 import org.apache.curator.retry.RetryOneTime;
 import org.apache.curator.test.BaseClassForTests;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs;
+import org.mockito.Mockito;
 import org.testng.Assert;
 import org.testng.annotations.Test;
+
 import java.util.concurrent.TimeUnit;
 
+import static org.mockito.Mockito.times;
+
 public class TestRetryLoop extends BaseClassForTests
 {
     @Test
@@ -142,4 +147,19 @@ public class TestRetryLoop extends BaseClassForTests
             client.close();
         }
     }
+
+    @Test
+    public void     testRetryForever() throws Exception
+    {
+        int retryIntervalMs = 1;
+        RetrySleeper sleeper = Mockito.mock(RetrySleeper.class);
+        RetryForever retryForever = new RetryForever(retryIntervalMs);
+
+        for (int i = 0; i < 10; i++)
+        {
+            boolean allowed = retryForever.allowRetry(i, 0, sleeper);
+            Assert.assertTrue(allowed);
+            Mockito.verify(sleeper, times(i + 1)).sleepFor(retryIntervalMs, TimeUnit.MILLISECONDS);
+        }
+    }
 }


[4/4] curator git commit: return false if interrupted

Posted by ra...@apache.org.
return false if interrupted


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

Branch: refs/heads/master
Commit: 38011678c4faebb1cd9388e56f0d13d29862c609
Parents: 35b2063
Author: randgalt <ra...@apache.org>
Authored: Mon Aug 31 07:19:21 2015 -0700
Committer: randgalt <ra...@apache.org>
Committed: Mon Aug 31 07:19:21 2015 -0700

----------------------------------------------------------------------
 .../src/main/java/org/apache/curator/retry/RetryForever.java      | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/38011678/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java b/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java
index 89f0276..59f3d0d 100644
--- a/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java
+++ b/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java
@@ -51,8 +51,9 @@ public class RetryForever implements RetryPolicy
         }
         catch (InterruptedException e)
         {
-            log.warn("Error occurred while sleeping", e);
             Thread.currentThread().interrupt();
+            log.warn("Error occurred while sleeping", e);
+            return false;
         }
         return true;
     }


[2/4] curator git commit: CURATOR-239 - Interrupting current thread after catching InterruptedException

Posted by ra...@apache.org.
CURATOR-239 - Interrupting current thread after catching InterruptedException


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

Branch: refs/heads/master
Commit: 3e3a810312f996874c327f42c24aa5b10a91161a
Parents: 6e8c108
Author: Leandro Nunes <le...@blip.pt>
Authored: Fri Jul 24 00:18:18 2015 +0100
Committer: Leandro Nunes <le...@blip.pt>
Committed: Fri Jul 24 00:18:18 2015 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/curator/retry/RetryForever.java        | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/3e3a8103/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java b/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java
index 27444b9..89f0276 100644
--- a/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java
+++ b/curator-client/src/main/java/org/apache/curator/retry/RetryForever.java
@@ -52,6 +52,7 @@ public class RetryForever implements RetryPolicy
         catch (InterruptedException e)
         {
             log.warn("Error occurred while sleeping", e);
+            Thread.currentThread().interrupt();
         }
         return true;
     }


[3/4] curator git commit: Merge branch 'CURATOR-239' of github.com:leandronunes85/curator into CURATOR-239

Posted by ra...@apache.org.
Merge branch 'CURATOR-239' of github.com:leandronunes85/curator into CURATOR-239


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

Branch: refs/heads/master
Commit: 35b206307447d9dcc8465c941f644ee9697e4723
Parents: 8fae785 3e3a810
Author: randgalt <ra...@apache.org>
Authored: Mon Aug 31 07:17:23 2015 -0700
Committer: randgalt <ra...@apache.org>
Committed: Mon Aug 31 07:17:23 2015 -0700

----------------------------------------------------------------------
 .../org/apache/curator/retry/RetryForever.java  | 59 ++++++++++++++++++++
 .../java/org/apache/curator/TestRetryLoop.java  | 20 +++++++
 2 files changed, 79 insertions(+)
----------------------------------------------------------------------