Skip to content

Commit

Permalink
Remove maxSequences and maxSequenceSize
Browse files Browse the repository at this point in the history
Remove maxSequences and maxSequenceSize from the
SequencedDeadLetterQueue. The other size operations cover sufficiently
for monitoring at this time.

#2021
  • Loading branch information
smcvb committed Aug 31, 2022
1 parent eb8a155 commit 491941c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,6 @@ public long amountOfSequences() {
return deadLetters.size();
}

@Override
public long maxSequences() {
return maxSequences;
}

@Override
public long maxSequenceSize() {
return maxSequenceSize;
}

@Override
public boolean process(@Nonnull Predicate<DeadLetter<? extends M>> sequenceFilter,
@Nonnull Function<DeadLetter<? extends M>, EnqueueDecision<M>> processingTask) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,11 @@ void requeue(@Nonnull DeadLetter<? extends M> letter,
/**
* Validates whether this queue is full for the given {@code sequenceIdentifier}.
* <p>
* This method returns {@code true} either when {@link #maxSequences()} is reached or when the
* {@link #maxSequenceSize()} is reached. The former dictates no new identifiable sequences can be introduced. The
* latter that the sequence of the given {@code sequenceIdentifier} is full.
* This method returns {@code true} either when the maximum amount of sequences or the maximum sequence size is
* reached.
*
* @param sequenceIdentifier The identifier of the sequence to validate for.
* @return {@code true} either when {@link #maxSequences()} is reached or when the {@link #maxSequenceSize()} is
* reached. Returns {@code false} otherwise.
* @return {@code true} either when the limit of this queue is reached. Returns {@code false} otherwise.
*/
boolean isFull(@Nonnull Object sequenceIdentifier);

Expand All @@ -153,8 +151,8 @@ void requeue(@Nonnull DeadLetter<? extends M> letter,
* Returns the number of dead-letters for the sequence matching the given {@code sequenceIdentifier} contained in
* this queue.
* <p>
* Note that there's a window of opportunity where the size might exceed the {@link #maxSequenceSize()} value to
* accompany concurrent usage.
* Note that there's a window of opportunity where the size might exceed the maximum sequence size to accompany
* concurrent usage.
*
* @param sequenceIdentifier The identifier of the sequence to retrieve the size from.
* @return The number of dead-letters for the sequence matching the given {@code sequenceIdentifier}.
Expand All @@ -164,35 +162,13 @@ void requeue(@Nonnull DeadLetter<? extends M> letter,
/**
* Returns the number of unique sequences contained in this queue.
* <p>
* Note that there's a window of opportunity where the size might exceed the {@link #maxSequences()} value to
* Note that there's a window of opportunity where the size might exceed the maximum amount of sequences to
* accompany concurrent usage of this dead letter queue.
*
* @return The number of unique sequences contained in this queue.
*/
long amountOfSequences();

/**
* The maximum number of distinct sequences this dead letter queue can hold. This comes down to the maximum number
* of unique "sequence identifiers" stored.
* <p>
* Note that there's a window of opportunity where the queue might exceed the {@code maxSequences} value to
* accompany concurrent usage of this dead letter queue.
*
* @return The maximum number of distinct sequences this dead letter queue can hold.
*/
long maxSequences();

/**
* The maximum number of letters a single sequence can contain. A single sequence is referenced based on it's
* "sequence identifier".
* <p>
* Note that there's a window of opportunity where the queue might exceed the {@code maxSequenceSize} value to
* accompany concurrent usage.
*
* @return The maximum number of letters a single sequence can contain.
*/
long maxSequenceSize();

/**
* Process a sequence of enqueued {@link DeadLetter dead-letters} through the given {@code processingTask} matching
* the {@code sequenceFilter}. Will pick the oldest available sequence based on the {@link DeadLetter#lastTouched()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,24 @@
*/
class InMemorySequencedDeadLetterQueueTest extends SequencedDeadLetterQueueTest<EventMessage<?>> {

private static final int MAX_SEQUENCES_AND_SEQUENCE_SIZE = 128;

@Override
SequencedDeadLetterQueue<EventMessage<?>> buildTestSubject() {
return InMemorySequencedDeadLetterQueue.defaultQueue();
return InMemorySequencedDeadLetterQueue.<EventMessage<?>>builder()
.maxSequences(MAX_SEQUENCES_AND_SEQUENCE_SIZE)
.maxSequenceSize(MAX_SEQUENCES_AND_SEQUENCE_SIZE)
.build();
}

@Override
long maxSequences() {
return MAX_SEQUENCES_AND_SEQUENCE_SIZE;
}

@Override
long maxSequenceSize() {
return MAX_SEQUENCES_AND_SEQUENCE_SIZE;
}

@Override
Expand Down Expand Up @@ -64,30 +79,6 @@ void setClock(Clock clock) {
GenericDeadLetter.clock = clock;
}

@Test
void maxSequencesReturnsConfiguredValue() {
int expectedMaxSequences = 128;

InMemorySequencedDeadLetterQueue<EventMessage<?>> testSubject =
InMemorySequencedDeadLetterQueue.<EventMessage<?>>builder()
.maxSequences(expectedMaxSequences)
.build();

assertEquals(expectedMaxSequences, testSubject.maxSequences());
}

@Test
void maxSequenceSizeReturnsConfiguredValue() {
int expectedMaxSequenceSize = 128;

InMemorySequencedDeadLetterQueue<EventMessage<?>> testSubject =
InMemorySequencedDeadLetterQueue.<EventMessage<?>>builder()
.maxSequenceSize(expectedMaxSequenceSize)
.build();

assertEquals(expectedMaxSequenceSize, testSubject.maxSequenceSize());
}

@Test
void buildDefaultQueue() {
assertDoesNotThrow(() -> InMemorySequencedDeadLetterQueue.defaultQueue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ void setUp() {
*/
abstract SequencedDeadLetterQueue<M> buildTestSubject();

/**
* Return the configured maximum amount of sequences for the {@link #buildTestSubject() test subject}.
*
* @return The configured maximum amount of sequences for the {@link #buildTestSubject() test subject}.
*/
abstract long maxSequences();

/**
* Return the configured maximum size of a sequence for the {@link #buildTestSubject() test subject}.
*
* @return The configured maximum size of a sequence for the {@link #buildTestSubject() test subject}.
*/
abstract long maxSequenceSize();

@Test
void enqueueAddsDeadLetter() {
Object testId = generateId();
Expand All @@ -76,7 +90,7 @@ void enqueueAddsDeadLetter() {

@Test
void enqueueThrowsDeadLetterQueueOverflowExceptionWhenMaxSequencesIsReached() {
long maxSequences = testSubject.maxSequences();
long maxSequences = this.maxSequences();
assertTrue(maxSequences > 0);

for (int i = 0; i < maxSequences; i++) {
Expand All @@ -92,7 +106,7 @@ void enqueueThrowsDeadLetterQueueOverflowExceptionWhenMaxSequencesIsReached() {
void enqueueThrowsDeadLetterQueueOverflowExceptionWhenMaxSequenceSizeIsReached() {
Object testId = generateId();

long maxSequenceSize = testSubject.maxSequenceSize();
long maxSequenceSize = this.maxSequenceSize();
assertTrue(maxSequenceSize > 0);

for (int i = 0; i < maxSequenceSize; i++) {
Expand All @@ -107,7 +121,7 @@ void enqueueThrowsDeadLetterQueueOverflowExceptionWhenMaxSequenceSizeIsReached()
void enqueueIfPresentThrowsDeadLetterQueueOverflowExceptionForFullQueue() {
Object testId = generateId();

long maxSequenceSize = testSubject.maxSequenceSize();
long maxSequenceSize = this.maxSequenceSize();
assertTrue(maxSequenceSize > 0);

for (int i = 0; i < maxSequenceSize; i++) {
Expand Down Expand Up @@ -339,7 +353,7 @@ void deadLettersInvocationReturnsAllEnqueuedDeadLetters() {
void isFullReturnsTrueAfterMaximumAmountOfSequencesIsReached() {
assertFalse(testSubject.isFull(generateId()));

long maxSequences = testSubject.maxSequences();
long maxSequences = this.maxSequences();
assertTrue(maxSequences > 0);

for (int i = 0; i < maxSequences; i++) {
Expand All @@ -355,7 +369,7 @@ void isFullReturnsTrueAfterMaximumSequenceSizeIsReached() {

assertFalse(testSubject.isFull(testId));

long maxSequenceSize = testSubject.maxSequenceSize();
long maxSequenceSize = this.maxSequenceSize();
assertTrue(maxSequenceSize > 0);

for (int i = 0; i < maxSequenceSize; i++) {
Expand Down

0 comments on commit 491941c

Please sign in to comment.