HADOOP-12386. RetryPolicies.RETRY_FOREVER should be able to specify a retry interval. (Sunil G via wangda)

(cherry picked from commit 6b97fa6652)
This commit is contained in:
Wangda Tan 2015-09-17 17:46:28 -07:00
parent f27f1ef44c
commit 1f75e951f5
3 changed files with 27 additions and 2 deletions

View File

@ -563,6 +563,9 @@ Release 2.8.0 - UNRELEASED
HADOOP-12087. [JDK8] Fix javadoc errors caused by incorrect or illegal HADOOP-12087. [JDK8] Fix javadoc errors caused by incorrect or illegal
tags. (Akira AJISAKA via stevel). tags. (Akira AJISAKA via stevel).
HADOOP-12386. RetryPolicies.RETRY_FOREVER should be able to specify a
retry interval. (Sunil G via wangda)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString() HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString()

View File

@ -63,6 +63,17 @@ public class RetryPolicies {
*/ */
public static final RetryPolicy RETRY_FOREVER = new RetryForever(); public static final RetryPolicy RETRY_FOREVER = new RetryForever();
/**
* <p>
* Keep trying forever with a fixed time between attempts.
* </p>
*/
public static final RetryPolicy retryForeverWithFixedSleep(long sleepTime,
TimeUnit timeUnit) {
return new RetryUpToMaximumCountWithFixedSleep(Integer.MAX_VALUE,
sleepTime, timeUnit);
}
/** /**
* <p> * <p>
* Keep trying a limited number of times, waiting a fixed time between attempts, * Keep trying a limited number of times, waiting a fixed time between attempts,

View File

@ -25,6 +25,7 @@ import static org.apache.hadoop.io.retry.RetryPolicies.retryByRemoteException;
import static org.apache.hadoop.io.retry.RetryPolicies.retryUpToMaximumCountWithFixedSleep; import static org.apache.hadoop.io.retry.RetryPolicies.retryUpToMaximumCountWithFixedSleep;
import static org.apache.hadoop.io.retry.RetryPolicies.retryUpToMaximumCountWithProportionalSleep; import static org.apache.hadoop.io.retry.RetryPolicies.retryUpToMaximumCountWithProportionalSleep;
import static org.apache.hadoop.io.retry.RetryPolicies.retryUpToMaximumTimeWithFixedSleep; import static org.apache.hadoop.io.retry.RetryPolicies.retryUpToMaximumTimeWithFixedSleep;
import static org.apache.hadoop.io.retry.RetryPolicies.retryForeverWithFixedSleep;
import static org.apache.hadoop.io.retry.RetryPolicies.exponentialBackoffRetry; import static org.apache.hadoop.io.retry.RetryPolicies.exponentialBackoffRetry;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -111,6 +112,16 @@ public class TestRetryProxy {
unreliable.failsTenTimesThenSucceeds(); unreliable.failsTenTimesThenSucceeds();
} }
@Test
public void testRetryForeverWithFixedSleep() throws UnreliableException {
UnreliableInterface unreliable = (UnreliableInterface) RetryProxy.create(
UnreliableInterface.class, unreliableImpl,
retryForeverWithFixedSleep(1, TimeUnit.MILLISECONDS));
unreliable.alwaysSucceeds();
unreliable.failsOnceThenSucceeds();
unreliable.failsTenTimesThenSucceeds();
}
@Test @Test
public void testRetryUpToMaximumCountWithFixedSleep() throws UnreliableException { public void testRetryUpToMaximumCountWithFixedSleep() throws UnreliableException {
UnreliableInterface unreliable = (UnreliableInterface) UnreliableInterface unreliable = (UnreliableInterface)