Add TimeoutRetryPolicy(long timeout) ctor

This commit is contained in:
Andreas Ahlenstorf
2023-05-24 15:35:45 +02:00
committed by GitHub
parent e6091f790c
commit 95464af8c2
2 changed files with 28 additions and 1 deletions

View File

@@ -35,7 +35,23 @@ public class TimeoutRetryPolicy implements RetryPolicy {
*/
public static final long DEFAULT_TIMEOUT = 1000;
private long timeout = DEFAULT_TIMEOUT;
private long timeout;
/**
* Create a new instance with the timeout set to {@link #DEFAULT_TIMEOUT}.
*/
public TimeoutRetryPolicy() {
this(DEFAULT_TIMEOUT);
}
/**
* Create a new instance with a configurable timeout.
* @param timeout timeout in milliseconds
* @since 2.0.2
*/
public TimeoutRetryPolicy(long timeout) {
this.timeout = timeout;
}
/**
* Setter for timeout in milliseconds. Default is {@link #DEFAULT_TIMEOUT}.

View File

@@ -57,4 +57,15 @@ public class TimeoutRetryPolicyTests {
assertThat(child.getParent()).isSameAs(context);
}
@Test
public void testConstructorWithCustomTimeout() throws Exception {
TimeoutRetryPolicy policy = new TimeoutRetryPolicy(100);
RetryContext context = policy.open(null);
policy.registerThrowable(context, new Exception());
assertThat(policy.canRetry(context)).isTrue();
Thread.sleep(200);
assertThat(policy.canRetry(context)).isFalse();
policy.close(context);
}
}