Optimize Redis integration tests

This commit ensures that Redis Testcontainers used for integration testing are managed by Spring to ensure proper ordering on shutdown.

Previously, Redis Testcontainer was closed before LettuceConnectionFactory which caused pending commands to hang and added a lot of wait to project build.

Closes gh-1086
This commit is contained in:
Vedran Pavic
2018-06-01 11:50:01 +02:00
parent f55b793185
commit 63f105082a
13 changed files with 159 additions and 228 deletions

View File

@@ -16,8 +16,6 @@
package org.springframework.session.data.redis;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.testcontainers.containers.GenericContainer;
import org.springframework.context.annotation.Bean;
@@ -33,25 +31,21 @@ public abstract class AbstractRedisITests {
private static final String DOCKER_IMAGE = "redis:4.0.9";
private static GenericContainer container = new GenericContainer(DOCKER_IMAGE)
.withExposedPorts(6379);
@BeforeClass
public static void setUpClass() {
container.start();
}
@AfterClass
public static void tearDownClass() {
container.stop();
}
protected static class BaseConfig {
@Bean
public GenericContainer redisContainer() {
GenericContainer redisContainer = new GenericContainer(DOCKER_IMAGE)
.withExposedPorts(6379);
redisContainer.start();
return redisContainer;
}
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(
container.getContainerIpAddress(), container.getFirstMappedPort());
redisContainer().getContainerIpAddress(),
redisContainer().getFirstMappedPort());
return new LettuceConnectionFactory(configuration);
}