From 911a9a14ea3727eede63920234e743396f9393c7 Mon Sep 17 00:00:00 2001 From: He Zean Date: Sat, 11 Jan 2025 05:18:55 +0800 Subject: [PATCH 1/2] Prevent redis pool to initialize in unit test See gh-43774 Signed-off-by: He Zean --- .../data/redis/RedisAutoConfigurationJedisTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java index 517b4d5a3bef..675981ebecd7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java @@ -152,14 +152,14 @@ void testPasswordInUrlStartsWithColon() { @Test void testRedisConfigurationWithPool() { this.contextRunner - .withPropertyValues("spring.data.redis.host:foo", "spring.data.redis.jedis.pool.min-idle:1", + .withPropertyValues("spring.data.redis.host:foo", "spring.data.redis.jedis.pool.min-idle:0", "spring.data.redis.jedis.pool.max-idle:4", "spring.data.redis.jedis.pool.max-active:16", "spring.data.redis.jedis.pool.max-wait:2000", "spring.data.redis.jedis.pool.time-between-eviction-runs:30000") .run((context) -> { JedisConnectionFactory cf = context.getBean(JedisConnectionFactory.class); assertThat(cf.getHostName()).isEqualTo("foo"); - assertThat(cf.getPoolConfig().getMinIdle()).isOne(); + assertThat(cf.getPoolConfig().getMinIdle()).isZero(); assertThat(cf.getPoolConfig().getMaxIdle()).isEqualTo(4); assertThat(cf.getPoolConfig().getMaxTotal()).isEqualTo(16); assertThat(cf.getPoolConfig().getMaxWaitDuration()).isEqualTo(Duration.ofSeconds(2)); From 7b04cddf1d5d8e43bd14f91ab5b06baccc4ff14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Sat, 11 Jan 2025 12:50:39 +0100 Subject: [PATCH 2/2] Polish "Prevent redis pool to initialize in unit test" See gh-43774 --- .../redis/RedisAutoConfigurationJedisTests.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java index 675981ebecd7..b1667d94a073 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -159,11 +159,13 @@ void testRedisConfigurationWithPool() { .run((context) -> { JedisConnectionFactory cf = context.getBean(JedisConnectionFactory.class); assertThat(cf.getHostName()).isEqualTo("foo"); - assertThat(cf.getPoolConfig().getMinIdle()).isZero(); - assertThat(cf.getPoolConfig().getMaxIdle()).isEqualTo(4); - assertThat(cf.getPoolConfig().getMaxTotal()).isEqualTo(16); - assertThat(cf.getPoolConfig().getMaxWaitDuration()).isEqualTo(Duration.ofSeconds(2)); - assertThat(cf.getPoolConfig().getDurationBetweenEvictionRuns()).isEqualTo(Duration.ofSeconds(30)); + assertThat(cf.getPoolConfig()).satisfies((poolConfig) -> { + assertThat(poolConfig.getMinIdle()).isEqualTo(0); + assertThat(poolConfig.getMaxIdle()).isEqualTo(4); + assertThat(poolConfig.getMaxTotal()).isEqualTo(16); + assertThat(poolConfig.getMaxWaitDuration()).isEqualTo(Duration.ofSeconds(2)); + assertThat(poolConfig.getDurationBetweenEvictionRuns()).isEqualTo(Duration.ofSeconds(30)); + }); }); }