Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constructor make timeout customisable #343

Merged
merged 1 commit into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@since 2.0.2

* @since 2.0.2
*/
public TimeoutRetryPolicy(long timeout) {
this.timeout = timeout;
}

/**
* Setter for timeout in milliseconds. Default is {@link #DEFAULT_TIMEOUT}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,15 @@ public void testParent() {
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);
}

}