File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
main/java/org/springframework/retry/policy
test/java/org/springframework/retry/policy Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,22 @@ 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+ * Creates a new instance with the timeout set to {@link #DEFAULT_TIMEOUT}.
42+ */
43+ public TimeoutRetryPolicy () {
44+ this (DEFAULT_TIMEOUT );
45+ }
46+
47+ /**
48+ * Creates a new instance with a configurable timeout.
49+ * @param timeout timeout in milliseconds
50+ */
51+ public TimeoutRetryPolicy (long timeout ) {
52+ this .timeout = timeout ;
53+ }
3954
4055 /**
4156 * Setter for timeout in milliseconds. Default is {@link #DEFAULT_TIMEOUT}.
Original file line number Diff line number Diff line change 2121import org .springframework .retry .RetryContext ;
2222
2323import static org .assertj .core .api .Assertions .assertThat ;
24+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
2425
2526public class TimeoutRetryPolicyTests {
2627
@@ -57,4 +58,15 @@ public void testParent() {
5758 assertThat (child .getParent ()).isSameAs (context );
5859 }
5960
61+ @ Test
62+ public void testConstructorWithCustomTimeout () throws Exception {
63+ TimeoutRetryPolicy policy = new TimeoutRetryPolicy (100 );
64+ RetryContext context = policy .open (null );
65+ policy .registerThrowable (context , new Exception ());
66+ assertThat (policy .canRetry (context )).isTrue ();
67+ Thread .sleep (200 );
68+ assertThat (policy .canRetry (context )).isFalse ();
69+ policy .close (context );
70+ }
71+
6072}
You can’t perform that action at this time.
0 commit comments