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,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}.
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments