Skip to content

Commit dc17163

Browse files
mp911dechristophstrobl
authored andcommitted
Use JUnit 5.13 @ParametrizedClass.
Migrate to JUnit's class parametrization and remove our own ParameterizedRedisTest infrastructure. Class parametrization considers closeable arguments and closes these. Therefore, ManagedJedisConnectionFactory and ManagedLettuceConnectionFactory are now no longer Closable but closed through the ShutdownQueue on JVM exit so that we don't need to guard these from Class parametrization cleanup. Also, we register extensions with the launcher value store to keep instances as long as possible. Exclude commons-logging from beanutils so that we use the version managed by Spring that considers SLF4j loggers.
1 parent baa5cf2 commit dc17163

File tree

93 files changed

+1572
-2455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1572
-2455
lines changed

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<multithreadedtc>1.01</multithreadedtc>
2929
<netty>4.1.121.Final</netty>
3030
<java-module-name>spring.data.redis</java-module-name>
31-
<junit5>5.12.2</junit5>
3231
</properties>
3332

3433
<scm>
@@ -154,6 +153,12 @@
154153
<artifactId>commons-beanutils</artifactId>
155154
<version>${beanutils}</version>
156155
<optional>true</optional>
156+
<exclusions>
157+
<exclusion>
158+
<groupId>commons-logging</groupId>
159+
<artifactId>commons-logging</artifactId>
160+
</exclusion>
161+
</exclusions>
157162
</dependency>
158163

159164
<!-- Pool -->

src/test/java/org/springframework/data/redis/cache/CacheTestParams.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.springframework.data.redis.test.XstreamOxmSerializerSingleton;
3838
import org.springframework.data.redis.test.condition.RedisDetector;
3939
import org.springframework.data.redis.test.extension.RedisCluster;
40-
import org.springframework.data.redis.test.extension.RedisStanalone;
40+
import org.springframework.data.redis.test.extension.RedisStandalone;
4141

4242
/**
4343
* @author Christoph Strobl
@@ -55,12 +55,12 @@ private static Collection<RedisConnectionFactory> connectionFactories() {
5555

5656
// Jedis Standalone
5757
JedisConnectionFactory jedisConnectionFactory = JedisConnectionFactoryExtension
58-
.getConnectionFactory(RedisStanalone.class);
58+
.getConnectionFactory(RedisStandalone.class);
5959
factoryList.add(jedisConnectionFactory);
6060

6161
// Lettuce Standalone
6262
LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension
63-
.getConnectionFactory(RedisStanalone.class);
63+
.getConnectionFactory(RedisStandalone.class);
6464
factoryList.add(lettuceConnectionFactory);
6565

6666
if (clusterAvailable()) {

src/test/java/org/springframework/data/redis/cache/DefaultRedisCacheWriterTests.java

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
import org.jspecify.annotations.Nullable;
3636
import org.junit.jupiter.api.BeforeEach;
3737
import org.junit.jupiter.api.Disabled;
38+
import org.junit.jupiter.api.Test;
39+
import org.junit.jupiter.params.ParameterizedClass;
40+
import org.junit.jupiter.params.provider.MethodSource;
3841

3942
import org.springframework.data.redis.connection.RedisConnection;
4043
import org.springframework.data.redis.connection.RedisConnectionFactory;
@@ -43,8 +46,6 @@
4346
import org.springframework.data.redis.test.condition.EnabledOnRedisDriver;
4447
import org.springframework.data.redis.test.condition.EnabledOnRedisDriver.DriverQualifier;
4548
import org.springframework.data.redis.test.condition.RedisDriver;
46-
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
47-
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
4849

4950
/**
5051
* Integration tests for {@link DefaultRedisCacheWriter}.
@@ -53,6 +54,7 @@
5354
* @author Mark Paluch
5455
* @author ChanYoung Joung
5556
*/
57+
@ParameterizedClass
5658
@MethodSource("testParams")
5759
public class DefaultRedisCacheWriterTests {
5860

@@ -79,7 +81,8 @@ void setUp() {
7981
doWithConnection(RedisConnection::flushAll);
8082
}
8183

82-
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
84+
@Test
85+
// DATAREDIS-481, DATAREDIS-1082
8386
void putShouldAddEternalEntry() {
8487

8588
RedisCacheWriter writer = nonLockingRedisCacheWriter(connectionFactory)
@@ -96,7 +99,7 @@ void putShouldAddEternalEntry() {
9699
assertThat(writer.getCacheStatistics(CACHE_NAME).getLockWaitDuration(TimeUnit.NANOSECONDS)).isZero();
97100
}
98101

99-
@ParameterizedRedisTest // DATAREDIS-481
102+
@Test // DATAREDIS-481
100103
void putShouldAddExpiringEntry() {
101104

102105
nonLockingRedisCacheWriter(connectionFactory).put(CACHE_NAME, binaryCacheKey, binaryCacheValue,
@@ -108,7 +111,7 @@ void putShouldAddExpiringEntry() {
108111
});
109112
}
110113

111-
@ParameterizedRedisTest // DATAREDIS-481
114+
@Test // DATAREDIS-481
112115
void putShouldOverwriteExistingEternalEntry() {
113116

114117
doWithConnection(connection -> connection.set(binaryCacheKey, "foo".getBytes()));
@@ -121,7 +124,7 @@ void putShouldOverwriteExistingEternalEntry() {
121124
});
122125
}
123126

124-
@ParameterizedRedisTest // DATAREDIS-481
127+
@Test // DATAREDIS-481
125128
void putShouldOverwriteExistingExpiringEntryAndResetTtl() {
126129

127130
doWithConnection(connection -> connection.set(binaryCacheKey, "foo".getBytes(),
@@ -136,7 +139,7 @@ void putShouldOverwriteExistingExpiringEntryAndResetTtl() {
136139
});
137140
}
138141

139-
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
142+
@Test // DATAREDIS-481, DATAREDIS-1082
140143
void getShouldReturnValue() {
141144

142145
doWithConnection(connection -> connection.set(binaryCacheKey, binaryCacheValue));
@@ -150,12 +153,12 @@ void getShouldReturnValue() {
150153
assertThat(writer.getCacheStatistics(CACHE_NAME).getMisses()).isZero();
151154
}
152155

153-
@ParameterizedRedisTest // DATAREDIS-481
156+
@Test // DATAREDIS-481
154157
void getShouldReturnNullWhenKeyDoesNotExist() {
155158
assertThat(nonLockingRedisCacheWriter(connectionFactory).get(CACHE_NAME, binaryCacheKey)).isNull();
156159
}
157160

158-
@ParameterizedRedisTest // GH-2650
161+
@Test // GH-2650
159162
@EnabledOnRedisDriver(RedisDriver.LETTUCE)
160163
void cacheHitRetrieveShouldIncrementStatistics() throws ExecutionException, InterruptedException {
161164

@@ -170,7 +173,7 @@ void cacheHitRetrieveShouldIncrementStatistics() throws ExecutionException, Inte
170173
assertThat(writer.getCacheStatistics(CACHE_NAME).getHits()).isOne();
171174
}
172175

173-
@ParameterizedRedisTest // GH-2650
176+
@Test // GH-2650
174177
@EnabledOnRedisDriver(RedisDriver.LETTUCE)
175178
void storeShouldIncrementStatistics() throws ExecutionException, InterruptedException {
176179

@@ -182,7 +185,7 @@ void storeShouldIncrementStatistics() throws ExecutionException, InterruptedExce
182185
assertThat(writer.getCacheStatistics(CACHE_NAME).getPuts()).isOne();
183186
}
184187

185-
@ParameterizedRedisTest // GH-2650
188+
@Test // GH-2650
186189
@EnabledOnRedisDriver(RedisDriver.LETTUCE)
187190
void cacheMissRetrieveWithLoaderAsyncShouldIncrementStatistics() throws ExecutionException, InterruptedException {
188191

@@ -195,7 +198,7 @@ void cacheMissRetrieveWithLoaderAsyncShouldIncrementStatistics() throws Executio
195198
assertThat(writer.getCacheStatistics(CACHE_NAME).getMisses()).isOne();
196199
}
197200

198-
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
201+
@Test // DATAREDIS-481, DATAREDIS-1082
199202
void putIfAbsentShouldAddEternalEntryWhenKeyDoesNotExist() {
200203

201204
RedisCacheWriter writer = nonLockingRedisCacheWriter(connectionFactory)
@@ -210,7 +213,7 @@ void putIfAbsentShouldAddEternalEntryWhenKeyDoesNotExist() {
210213
assertThat(writer.getCacheStatistics(CACHE_NAME).getPuts()).isOne();
211214
}
212215

213-
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
216+
@Test // DATAREDIS-481, DATAREDIS-1082
214217
void putIfAbsentShouldNotAddEternalEntryWhenKeyAlreadyExist() {
215218

216219
doWithConnection(connection -> connection.set(binaryCacheKey, binaryCacheValue));
@@ -228,7 +231,7 @@ void putIfAbsentShouldNotAddEternalEntryWhenKeyAlreadyExist() {
228231
assertThat(writer.getCacheStatistics(CACHE_NAME).getPuts()).isZero();
229232
}
230233

231-
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
234+
@Test // DATAREDIS-481, DATAREDIS-1082
232235
void putIfAbsentShouldAddExpiringEntryWhenKeyDoesNotExist() {
233236

234237
RedisCacheWriter writer = nonLockingRedisCacheWriter(connectionFactory)
@@ -243,7 +246,7 @@ void putIfAbsentShouldAddExpiringEntryWhenKeyDoesNotExist() {
243246
assertThat(writer.getCacheStatistics(CACHE_NAME).getPuts()).isOne();
244247
}
245248

246-
@ParameterizedRedisTest // GH-2890
249+
@Test // GH-2890
247250
void getWithValueLoaderShouldStoreCacheValue() {
248251

249252
RedisCacheWriter writer = nonLockingRedisCacheWriter(connectionFactory)
@@ -259,7 +262,7 @@ void getWithValueLoaderShouldStoreCacheValue() {
259262
assertThat(writer.getCacheStatistics(CACHE_NAME).getPuts()).isOne();
260263
}
261264

262-
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
265+
@Test // DATAREDIS-481, DATAREDIS-1082
263266
void removeShouldDeleteEntry() {
264267

265268
doWithConnection(connection -> connection.set(binaryCacheKey, binaryCacheValue));
@@ -274,7 +277,7 @@ void removeShouldDeleteEntry() {
274277
assertThat(writer.getCacheStatistics(CACHE_NAME).getDeletes()).isOne();
275278
}
276279

277-
@ParameterizedRedisTest // DATAREDIS-418, DATAREDIS-1082
280+
@Test // DATAREDIS-418, DATAREDIS-1082
278281
void cleanShouldRemoveAllKeysByPattern() {
279282

280283
doWithConnection(connection -> {
@@ -295,7 +298,7 @@ void cleanShouldRemoveAllKeysByPattern() {
295298
assertThat(writer.getCacheStatistics(CACHE_NAME).getDeletes()).isOne();
296299
}
297300

298-
@ParameterizedRedisTest // DATAREDIS-481
301+
@Test // DATAREDIS-481
299302
void nonLockingCacheWriterShouldIgnoreExistingLock() {
300303

301304
((DefaultRedisCacheWriter) lockingRedisCacheWriter(connectionFactory)).lock(CACHE_NAME);
@@ -307,7 +310,7 @@ void nonLockingCacheWriterShouldIgnoreExistingLock() {
307310
});
308311
}
309312

310-
@ParameterizedRedisTest // DATAREDIS-481
313+
@Test // DATAREDIS-481
311314
void lockingCacheWriterShouldIgnoreExistingLockOnDifferenceCache() {
312315

313316
((DefaultRedisCacheWriter) lockingRedisCacheWriter(connectionFactory)).lock(CACHE_NAME);
@@ -320,7 +323,7 @@ void lockingCacheWriterShouldIgnoreExistingLockOnDifferenceCache() {
320323
});
321324
}
322325

323-
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
326+
@Test // DATAREDIS-481, DATAREDIS-1082
324327
void lockingCacheWriterShouldWaitForLockRelease() throws InterruptedException {
325328

326329
DefaultRedisCacheWriter writer = (DefaultRedisCacheWriter) lockingRedisCacheWriter(connectionFactory)
@@ -362,7 +365,7 @@ void lockingCacheWriterShouldWaitForLockRelease() throws InterruptedException {
362365
}
363366
}
364367

365-
@ParameterizedRedisTest // DATAREDIS-481
368+
@Test // DATAREDIS-481
366369
void lockingCacheWriterShouldExitWhenInterruptedWaitForLockRelease() throws InterruptedException {
367370

368371
DefaultRedisCacheWriter cw = (DefaultRedisCacheWriter) lockingRedisCacheWriter(connectionFactory);
@@ -403,7 +406,7 @@ boolean doCheckLock(String name, RedisConnection connection) {
403406
assertThat(exceptionRef.get()).hasRootCauseInstanceOf(InterruptedException.class);
404407
}
405408

406-
@ParameterizedRedisTest // GH-2300
409+
@Test // GH-2300
407410
void lockingCacheWriterShouldUsePersistentLocks() {
408411

409412
DefaultRedisCacheWriter writer = (DefaultRedisCacheWriter) lockingRedisCacheWriter(connectionFactory,
@@ -417,7 +420,7 @@ void lockingCacheWriterShouldUsePersistentLocks() {
417420
});
418421
}
419422

420-
@ParameterizedRedisTest // GH-2300
423+
@Test // GH-2300
421424
void lockingCacheWriterShouldApplyLockTtl() {
422425

423426
DefaultRedisCacheWriter writer = (DefaultRedisCacheWriter) lockingRedisCacheWriter(connectionFactory,
@@ -431,7 +434,7 @@ void lockingCacheWriterShouldApplyLockTtl() {
431434
});
432435
}
433436

434-
@ParameterizedRedisTest // DATAREDIS-1082
437+
@Test // DATAREDIS-1082
435438
void noOpStatisticsCollectorReturnsEmptyStatsInstance() {
436439

437440
DefaultRedisCacheWriter cw = (DefaultRedisCacheWriter) lockingRedisCacheWriter(connectionFactory);
@@ -443,7 +446,7 @@ void noOpStatisticsCollectorReturnsEmptyStatsInstance() {
443446
assertThat(stats.getPuts()).isZero();
444447
}
445448

446-
@ParameterizedRedisTest // GH-1686
449+
@Test // GH-1686
447450
@Disabled("Occasional failures on CI but not locally")
448451
void doLockShouldGetLock() throws InterruptedException {
449452

0 commit comments

Comments
 (0)