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

Fix StopStrategies&StopStrategies will throw unformatted message #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/main/java/com/github/rholder/retry/StopStrategies.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static final class StopAfterAttemptStrategy implements StopStrategy {
private final int maxAttemptNumber;

public StopAfterAttemptStrategy(int maxAttemptNumber) {
Preconditions.checkArgument(maxAttemptNumber >= 1, "maxAttemptNumber must be >= 1 but is %d", maxAttemptNumber);
Preconditions.checkArgument(maxAttemptNumber >= 1, "maxAttemptNumber must be >= 1 but is %s", maxAttemptNumber);
this.maxAttemptNumber = maxAttemptNumber;
}

Expand All @@ -115,7 +115,7 @@ private static final class StopAfterDelayStrategy implements StopStrategy {
private final long maxDelay;

public StopAfterDelayStrategy(long maxDelay) {
Preconditions.checkArgument(maxDelay >= 0L, "maxDelay must be >= 0 but is %d", maxDelay);
Preconditions.checkArgument(maxDelay >= 0L, "maxDelay must be >= 0 but is %s", maxDelay);
this.maxDelay = maxDelay;
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/github/rholder/retry/WaitStrategies.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private static final class FixedWaitStrategy implements WaitStrategy {
private final long sleepTime;

public FixedWaitStrategy(long sleepTime) {
Preconditions.checkArgument(sleepTime >= 0L, "sleepTime must be >= 0 but is %d", sleepTime);
Preconditions.checkArgument(sleepTime >= 0L, "sleepTime must be >= 0 but is %s", sleepTime);
this.sleepTime = sleepTime;
}

Expand All @@ -251,8 +251,8 @@ private static final class RandomWaitStrategy implements WaitStrategy {
private final long maximum;

public RandomWaitStrategy(long minimum, long maximum) {
Preconditions.checkArgument(minimum >= 0, "minimum must be >= 0 but is %d", minimum);
Preconditions.checkArgument(maximum > minimum, "maximum must be > minimum but maximum is %d and minimum is", maximum, minimum);
Preconditions.checkArgument(minimum >= 0, "minimum must be >= 0 but is %s", minimum);
Preconditions.checkArgument(maximum > minimum, "maximum must be > minimum but maximum is %s and minimum is", maximum, minimum);

this.minimum = minimum;
this.maximum = maximum;
Expand All @@ -272,7 +272,7 @@ private static final class IncrementingWaitStrategy implements WaitStrategy {

public IncrementingWaitStrategy(long initialSleepTime,
long increment) {
Preconditions.checkArgument(initialSleepTime >= 0L, "initialSleepTime must be >= 0 but is %d", initialSleepTime);
Preconditions.checkArgument(initialSleepTime >= 0L, "initialSleepTime must be >= 0 but is %s", initialSleepTime);
this.initialSleepTime = initialSleepTime;
this.increment = increment;
}
Expand All @@ -291,9 +291,9 @@ private static final class ExponentialWaitStrategy implements WaitStrategy {

public ExponentialWaitStrategy(long multiplier,
long maximumWait) {
Preconditions.checkArgument(multiplier > 0L, "multiplier must be > 0 but is %d", multiplier);
Preconditions.checkArgument(maximumWait >= 0L, "maximumWait must be >= 0 but is %d", maximumWait);
Preconditions.checkArgument(multiplier < maximumWait, "multiplier must be < maximumWait but is %d", multiplier);
Preconditions.checkArgument(multiplier > 0L, "multiplier must be > 0 but is %s", multiplier);
Preconditions.checkArgument(maximumWait >= 0L, "maximumWait must be >= 0 but is %s", maximumWait);
Preconditions.checkArgument(multiplier < maximumWait, "multiplier must be < maximumWait but is %s", multiplier);
this.multiplier = multiplier;
this.maximumWait = maximumWait;
}
Expand All @@ -315,9 +315,9 @@ private static final class FibonacciWaitStrategy implements WaitStrategy {
private final long maximumWait;

public FibonacciWaitStrategy(long multiplier, long maximumWait) {
Preconditions.checkArgument(multiplier > 0L, "multiplier must be > 0 but is %d", multiplier);
Preconditions.checkArgument(maximumWait >= 0L, "maximumWait must be >= 0 but is %d", maximumWait);
Preconditions.checkArgument(multiplier < maximumWait, "multiplier must be < maximumWait but is %d", multiplier);
Preconditions.checkArgument(multiplier > 0L, "multiplier must be > 0 but is %s", multiplier);
Preconditions.checkArgument(maximumWait >= 0L, "maximumWait must be >= 0 but is %s", maximumWait);
Preconditions.checkArgument(multiplier < maximumWait, "multiplier must be < maximumWait but is %s", multiplier);
this.multiplier = multiplier;
this.maximumWait = maximumWait;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ public void testStopAfterDelayWithTimeUnit() {
public Attempt<Boolean> failedAttempt(long attemptNumber, long delaySinceFirstAttempt) {
return new Retryer.ExceptionAttempt<Boolean>(new RuntimeException(), attemptNumber, delaySinceFirstAttempt);
}

@Test(expected = IllegalArgumentException.class)
public void testStopWithIllegalArgumentException(){
StopStrategies.stopAfterAttempt(0);
}
}