|
12 | 12 | import org.junit.jupiter.api.DisplayName; |
13 | 13 | import org.junit.jupiter.api.Nested; |
14 | 14 | import org.junit.jupiter.api.Test; |
| 15 | +import org.junit.jupiter.params.ParameterizedTest; |
| 16 | +import org.junit.jupiter.params.provider.Arguments; |
| 17 | +import org.junit.jupiter.params.provider.MethodSource; |
15 | 18 |
|
16 | 19 | import java.util.Map; |
| 20 | +import java.util.function.Consumer; |
| 21 | +import java.util.stream.Stream; |
17 | 22 |
|
18 | 23 | import static org.assertj.core.api.Assertions.assertThat; |
19 | 24 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
@@ -285,28 +290,34 @@ void shouldRejectSentinelDurationsAboveRedissonIntegerLimit() { |
285 | 290 | .containsExactlyInAnyOrder("connectTimeout", "timeout", "scanInterval"); |
286 | 291 | } |
287 | 292 |
|
288 | | - @Test |
289 | | - @DisplayName("Should reject Sentinel duration overflow during direct builds") |
290 | | - void shouldRejectSentinelDurationOverflowDuringDirectBuilds() { |
291 | | - var oversizedDuration = Duration.milliseconds((long) Integer.MAX_VALUE + 1); |
| 293 | + @ParameterizedTest(name = "Should reject {0} overflow during direct builds") |
| 294 | + @MethodSource("sentinelDurationSetters") |
| 295 | + void shouldRejectSentinelDurationOverflowDuringDirectBuilds( |
| 296 | + String propertyName, Consumer<RedisConfig.SentinelConfig> setOversizedDuration) { |
| 297 | + var redisConfig = newSentinelConfig("redis://localhost:26379/0"); |
| 298 | + setOversizedDuration.accept(redisConfig.getSentinel()); |
292 | 299 |
|
293 | | - var connectTimeoutConfig = newSentinelConfig("redis://localhost:26379/0"); |
294 | | - connectTimeoutConfig.getSentinel().setConnectTimeout(oversizedDuration); |
295 | | - assertThatThrownBy(connectTimeoutConfig::build) |
| 300 | + assertThatThrownBy(redisConfig::build) |
| 301 | + .as("overflow for %s", propertyName) |
296 | 302 | .isInstanceOf(ArithmeticException.class) |
297 | 303 | .hasMessage("integer overflow"); |
| 304 | + } |
298 | 305 |
|
299 | | - var timeoutConfig = newSentinelConfig("redis://localhost:26379/0"); |
300 | | - timeoutConfig.getSentinel().setTimeout(oversizedDuration); |
301 | | - assertThatThrownBy(timeoutConfig::build) |
302 | | - .isInstanceOf(ArithmeticException.class) |
303 | | - .hasMessage("integer overflow"); |
| 306 | + private static Stream<Arguments> sentinelDurationSetters() { |
| 307 | + var oversizedDuration = Duration.milliseconds((long) Integer.MAX_VALUE + 1); |
304 | 308 |
|
305 | | - var scanIntervalConfig = newSentinelConfig("redis://localhost:26379/0"); |
306 | | - scanIntervalConfig.getSentinel().setScanInterval(oversizedDuration); |
307 | | - assertThatThrownBy(scanIntervalConfig::build) |
308 | | - .isInstanceOf(ArithmeticException.class) |
309 | | - .hasMessage("integer overflow"); |
| 309 | + return Stream.of( |
| 310 | + Arguments.of( |
| 311 | + "connectTimeout", |
| 312 | + (Consumer<RedisConfig.SentinelConfig>) sentinel -> sentinel |
| 313 | + .setConnectTimeout(oversizedDuration)), |
| 314 | + Arguments.of( |
| 315 | + "timeout", |
| 316 | + (Consumer<RedisConfig.SentinelConfig>) sentinel -> sentinel.setTimeout(oversizedDuration)), |
| 317 | + Arguments.of( |
| 318 | + "scanInterval", |
| 319 | + (Consumer<RedisConfig.SentinelConfig>) sentinel -> sentinel |
| 320 | + .setScanInterval(oversizedDuration))); |
310 | 321 | } |
311 | 322 | } |
312 | 323 |
|
|
0 commit comments