Skip to content

Commit

Permalink
Retry strategy validation (dtinit#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
olsona committed Jul 6, 2018
1 parent f85d2d5 commit 30a1a14
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class ExponentialBackoffStrategy implements RetryStrategy {
public ExponentialBackoffStrategy(@JsonProperty("maxAttempts") int maxAttempts,
@JsonProperty("initialIntervalMillis") long initialIntervalMillis,
@JsonProperty("multiplier") double multiplier) {
Preconditions.checkArgument(maxAttempts > 0, "Max attempts should be > 0");
Preconditions.checkArgument(initialIntervalMillis > 0L, "Initial interval should be > 0");
Preconditions.checkArgument(multiplier >= 1, "Multiplier should be >= 1");
this.maxAttempts = maxAttempts;
this.initialIntervalMillis = initialIntervalMillis;
this.multiplier = multiplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.dataportabilityproject.types.transfer.retry;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import java.util.List;

/**
Expand All @@ -42,6 +43,7 @@ public class RetryStrategyLibrary {

public RetryStrategyLibrary(@JsonProperty("strategyMappings") List<RetryMapping> retryMappings,
@JsonProperty("defaultRetryStrategy") RetryStrategy defaultRetryStrategy) {
Preconditions.checkArgument(defaultRetryStrategy != null, "Default retry strategy cannot be null");
this.retryMappings = retryMappings;
this.defaultRetryStrategy = defaultRetryStrategy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class UniformRetryStrategy implements RetryStrategy {

public UniformRetryStrategy(@JsonProperty("maxAttempts") int maxAttempts,
@JsonProperty("intervalMillis") long intervalMillis) {
Preconditions.checkArgument(maxAttempts > 0, "Max attempts should be > 0");
Preconditions.checkArgument(intervalMillis > 0L, "Interval should be > 0");
// TODO: enforce stronger requirements (e.g., interval > 500ms)
this.maxAttempts = maxAttempts;
this.intervalMillis = intervalMillis;
}
Expand Down

0 comments on commit 30a1a14

Please sign in to comment.