Skip to content

Commit

Permalink
Reject ChronoUnit.FOREVER as a demand pacer request delay value
Browse files Browse the repository at this point in the history
  • Loading branch information
jponge committed Mar 17, 2022
1 parent e9ee3f4 commit b939caa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static io.smallrye.mutiny.helpers.ParameterValidation.validate;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import io.smallrye.common.annotation.Experimental;
import io.smallrye.mutiny.Multi;
Expand Down Expand Up @@ -39,6 +40,9 @@ class Request {
public Request(long demand, Duration delay) {
this.demand = positive(demand, "demand");
this.delay = validate(delay, "delay");
if (delay == ChronoUnit.FOREVER.getDuration()) {
throw new IllegalArgumentException("ChronoUnit.FOREVER is not a correct delay value");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -36,4 +37,11 @@ void rejectNegativeDuration() {
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("`delay` must be greater than zero");
}

@Test
void rejectDurationOfForever() {
assertThatThrownBy(() -> new DemandPacer.Request(100L, ChronoUnit.FOREVER.getDuration()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("ChronoUnit.FOREVER is not a correct delay value");
}
}

0 comments on commit b939caa

Please sign in to comment.