|
1 | 1 | /* |
2 | | - * Copyright 2013-2022 the original author or authors. |
| 2 | + * Copyright 2013-2025 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
16 | 16 | package io.awspring.cloud.sqs.listener; |
17 | 17 |
|
18 | 18 | import static org.assertj.core.api.Assertions.assertThat; |
| 19 | +import static org.assertj.core.api.Assertions.catchThrowable; |
19 | 20 | import static org.mockito.Mockito.mock; |
20 | 21 |
|
21 | 22 | import io.awspring.cloud.sqs.listener.acknowledgement.AcknowledgementOrdering; |
|
29 | 30 | import java.util.List; |
30 | 31 | import java.util.stream.Collectors; |
31 | 32 | import org.junit.jupiter.api.Test; |
| 33 | +import org.junit.jupiter.params.ParameterizedTest; |
| 34 | +import org.junit.jupiter.params.provider.ValueSource; |
32 | 35 | import org.springframework.core.task.TaskExecutor; |
33 | 36 | import org.springframework.retry.backoff.BackOffPolicy; |
34 | 37 | import org.springframework.retry.backoff.BackOffPolicyBuilder; |
|
39 | 42 | * Tests for {@link SqsContainerOptions}. |
40 | 43 | * |
41 | 44 | * @author Tomaz Fernandes |
| 45 | + * @author Richard Fearn |
42 | 46 | */ |
43 | 47 | class ContainerOptionsTests { |
44 | 48 |
|
@@ -143,6 +147,30 @@ void shouldDefaultToNoopObservationRegistry() { |
143 | 147 | assertThat(options.getObservationRegistry().isNoop()).isTrue(); |
144 | 148 | } |
145 | 149 |
|
| 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 | + |
146 | 174 | private SqsContainerOptions createConfiguredOptions() { |
147 | 175 | return createConfiguredBuilder().build(); |
148 | 176 | } |
|
0 commit comments