Skip to content

Commit 95464af

Browse files
authored
Add TimeoutRetryPolicy(long timeout) ctor
1 parent e6091f7 commit 95464af

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/main/java/org/springframework/retry/policy/TimeoutRetryPolicy.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,23 @@ public class TimeoutRetryPolicy implements RetryPolicy {
3535
*/
3636
public static final long DEFAULT_TIMEOUT = 1000;
3737

38-
private long timeout = DEFAULT_TIMEOUT;
38+
private long timeout;
39+
40+
/**
41+
* Create a new instance with the timeout set to {@link #DEFAULT_TIMEOUT}.
42+
*/
43+
public TimeoutRetryPolicy() {
44+
this(DEFAULT_TIMEOUT);
45+
}
46+
47+
/**
48+
* Create a new instance with a configurable timeout.
49+
* @param timeout timeout in milliseconds
50+
* @since 2.0.2
51+
*/
52+
public TimeoutRetryPolicy(long timeout) {
53+
this.timeout = timeout;
54+
}
3955

4056
/**
4157
* Setter for timeout in milliseconds. Default is {@link #DEFAULT_TIMEOUT}.

src/test/java/org/springframework/retry/policy/TimeoutRetryPolicyTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,15 @@ public void testParent() {
5757
assertThat(child.getParent()).isSameAs(context);
5858
}
5959

60+
@Test
61+
public void testConstructorWithCustomTimeout() throws Exception {
62+
TimeoutRetryPolicy policy = new TimeoutRetryPolicy(100);
63+
RetryContext context = policy.open(null);
64+
policy.registerThrowable(context, new Exception());
65+
assertThat(policy.canRetry(context)).isTrue();
66+
Thread.sleep(200);
67+
assertThat(policy.canRetry(context)).isFalse();
68+
policy.close(context);
69+
}
70+
6071
}

0 commit comments

Comments
 (0)