Skip to content

Commit acbbf90

Browse files
Fix maxMessagesPerPoll validation message in AbstractContainerOptions (#1480) (#1509)
The message is used when validating `maxMessagesPerPoll`, but incorrectly refers to `messagesPerPoll`. Fixes gh-1466 (cherry picked from commit b3562aa) Co-authored-by: Richard Fearn <[email protected]>
1 parent d5c0b6e commit acbbf90

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

spring-cloud-aws-sqs/src/main/java/io/awspring/cloud/sqs/listener/AbstractContainerOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2022 the original author or authors.
2+
* Copyright 2013-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -101,7 +101,7 @@ protected AbstractContainerOptions(Builder<?, ?> builder) {
101101
this.observationRegistry = builder.observationRegistry;
102102
this.observationConvention = builder.observationConvention;
103103
Assert.isTrue(this.maxMessagesPerPoll <= this.maxConcurrentMessages, String.format(
104-
"messagesPerPoll should be less than or equal to maxConcurrentMessages. Values provided: %s and %s respectively",
104+
"maxMessagesPerPoll should be less than or equal to maxConcurrentMessages. Values provided: %s and %s respectively",
105105
this.maxMessagesPerPoll, this.maxConcurrentMessages));
106106
}
107107

spring-cloud-aws-sqs/src/test/java/io/awspring/cloud/sqs/listener/ContainerOptionsTests.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2022 the original author or authors.
2+
* Copyright 2013-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616
package io.awspring.cloud.sqs.listener;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.assertj.core.api.Assertions.catchThrowable;
1920
import static org.mockito.Mockito.mock;
2021

2122
import io.awspring.cloud.sqs.listener.acknowledgement.AcknowledgementOrdering;
@@ -29,6 +30,8 @@
2930
import java.util.List;
3031
import java.util.stream.Collectors;
3132
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.params.ParameterizedTest;
34+
import org.junit.jupiter.params.provider.ValueSource;
3235
import org.springframework.core.task.TaskExecutor;
3336
import org.springframework.retry.backoff.BackOffPolicy;
3437
import org.springframework.retry.backoff.BackOffPolicyBuilder;
@@ -39,6 +42,7 @@
3942
* Tests for {@link SqsContainerOptions}.
4043
*
4144
* @author Tomaz Fernandes
45+
* @author Richard Fearn
4246
*/
4347
class ContainerOptionsTests {
4448

@@ -143,6 +147,30 @@ void shouldDefaultToNoopObservationRegistry() {
143147
assertThat(options.getObservationRegistry().isNoop()).isTrue();
144148
}
145149

150+
@ParameterizedTest
151+
@ValueSource(ints = { 4, 5 })
152+
void shouldAcceptValidMaxMessagesPerPoll(final int maxMessagesPerPoll) {
153+
154+
final SqsContainerOptions options = SqsContainerOptions.builder()
155+
.maxMessagesPerPoll(maxMessagesPerPoll)
156+
.maxConcurrentMessages(5)
157+
.build();
158+
159+
assertThat(options.getMaxMessagesPerPoll()).isEqualTo(maxMessagesPerPoll);
160+
assertThat(options.getMaxConcurrentMessages()).isEqualTo(5);
161+
}
162+
163+
@Test
164+
void shouldRejectInvalidMaxMessagesPerPoll() {
165+
166+
final Throwable exception = catchThrowable(
167+
() -> SqsContainerOptions.builder().maxMessagesPerPoll(6).maxConcurrentMessages(5).build());
168+
169+
assertThat(exception).isInstanceOf(IllegalArgumentException.class)
170+
.hasMessage("maxMessagesPerPoll should be less than or equal to maxConcurrentMessages. "
171+
+ "Values provided: 6 and 5 respectively");
172+
}
173+
146174
private SqsContainerOptions createConfiguredOptions() {
147175
return createConfiguredBuilder().build();
148176
}

0 commit comments

Comments
 (0)