Skip to content

Commit

Permalink
Assert for a strictly positive number instead
Browse files Browse the repository at this point in the history
Instead of expecting the provided maxSequences / maxSequenceSize to be a
 value equal or above 128, we should expect a strictly positive number.
We can hardly deduce all the scenarios of our end-users, so expecting
anything else than strictly positive wouldn't be fair.

#2021
  • Loading branch information
smcvb committed Aug 30, 2022
1 parent 9b9458c commit 76177f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.util.stream.Collectors;
import javax.annotation.Nonnull;

import static org.axonframework.common.BuilderUtils.assertThat;
import static org.axonframework.common.BuilderUtils.assertStrictPositive;

/**
* In-memory implementation of the {@link SequencedDeadLetterQueue}.
Expand Down Expand Up @@ -349,16 +349,13 @@ public static class Builder<M extends Message<?>> {
* Sets the maximum number of sequences this {@link SequencedDeadLetterQueue} may contain. This requirement
* reflects itself as the maximum amount of unique "sequence identifiers."
* <p>
* The given {@code maxSequences} is required to be a positive number, higher or equal to {@code 128}. It
* defaults to {@code 1024}.
* The given {@code maxSequences} is required to be a strictly positive number. It defaults to {@code 1024}.
*
* @param maxSequences The maximum amount of sequences for the queue under construction.
* @return The current Builder, for fluent interfacing.
*/
public Builder<M> maxSequences(int maxSequences) {
assertThat(maxSequences,
value -> value >= 128,
"The maximum number of sequences should be larger or equal to 128");
assertStrictPositive(maxSequences, "The maximum number of sequences should be a strictly positive number");
this.maxSequences = maxSequences;
return this;
}
Expand All @@ -367,16 +364,16 @@ public Builder<M> maxSequences(int maxSequences) {
* Sets the maximum amount of {@link DeadLetter dead-letters} per sequence this {@link SequencedDeadLetterQueue}
* can store.
* <p>
* The given {@code maxSequenceSize} is required to be a positive number, higher or equal to {@code 128}. It
* defaults to {@code 1024}.
* The given {@code maxSequenceSize} is required to be a strictly positive number. It defaults to {@code 1024}.
*
* @param maxSequenceSize The maximum amount of {@link DeadLetter dead-letters} per sequence.
* @return The current Builder, for fluent interfacing.
*/
public Builder<M> maxSequenceSize(int maxSequenceSize) {
assertThat(maxSequenceSize,
value -> value >= 128,
"The maximum number of dead-letters in a sequence should be larger or equal to 128");
assertStrictPositive(
maxSequenceSize,
"The maximum number of dead-letters in a sequence should be a strictly positive number"
);
this.maxSequenceSize = maxSequenceSize;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.time.Clock;
import java.time.Instant;
import java.util.stream.IntStream;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -103,13 +102,11 @@ void buildWithNegativeMaxSequencesThrowsAxonConfigurationException() {
}

@Test
void buildWithValueLowerThanMinimumMaxSequencesThrowsAxonConfigurationException() {
IntStream.range(0, 127).forEach(i -> {
InMemorySequencedDeadLetterQueue.Builder<EventMessage<?>> builderTestSubject =
InMemorySequencedDeadLetterQueue.builder();
void buildWithZeroMaxSequencesThrowsAxonConfigurationException() {
InMemorySequencedDeadLetterQueue.Builder<EventMessage<?>> builderTestSubject =
InMemorySequencedDeadLetterQueue.builder();

assertThrows(AxonConfigurationException.class, () -> builderTestSubject.maxSequences(i));
});
assertThrows(AxonConfigurationException.class, () -> builderTestSubject.maxSequences(0));
}

@Test
Expand All @@ -121,12 +118,10 @@ void buildWithNegativeMaxSequenceSizeThrowsAxonConfigurationException() {
}

@Test
void buildWithValueLowerThanMinimumMaxSequenceSizeThrowsAxonConfigurationException() {
IntStream.range(0, 127).forEach(i -> {
InMemorySequencedDeadLetterQueue.Builder<EventMessage<?>> builderTestSubject =
InMemorySequencedDeadLetterQueue.builder();
void buildWithZeroMaxSequenceSizeThrowsAxonConfigurationException() {
InMemorySequencedDeadLetterQueue.Builder<EventMessage<?>> builderTestSubject =
InMemorySequencedDeadLetterQueue.builder();

assertThrows(AxonConfigurationException.class, () -> builderTestSubject.maxSequenceSize(i));
});
assertThrows(AxonConfigurationException.class, () -> builderTestSubject.maxSequenceSize(0));
}
}

0 comments on commit 76177f4

Please sign in to comment.