Switch Redis samples to Testcontainers.
This commit is contained in:
@@ -15,9 +15,13 @@
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-data-redis-example-utils</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-testcontainers</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
package example.springdata.redis;
|
||||
|
||||
import jakarta.annotation.PreDestroy;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.redis.testcontainers.RedisContainer;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
@@ -27,12 +27,9 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
@SpringBootApplication
|
||||
public class RedisTestConfiguration {
|
||||
|
||||
@Autowired RedisConnectionFactory factory;
|
||||
|
||||
/**
|
||||
* Clear database before shut down.
|
||||
*/
|
||||
public @PreDestroy void flushTestDb() {
|
||||
factory.getConnection().flushDb();
|
||||
@Bean
|
||||
@ServiceConnection(name = "redis")
|
||||
RedisContainer redisContainer() {
|
||||
return new RedisContainer(DockerImageName.parse("redis:7"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,10 @@
|
||||
*/
|
||||
package example.springdata.redis.commands;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.redis.test.condition.EnabledOnCommand;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.geo.Circle;
|
||||
@@ -37,7 +34,6 @@ import org.springframework.data.redis.core.RedisOperations;
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@SpringBootTest
|
||||
@EnabledOnCommand("GEOADD")
|
||||
class GeoOperationsTests {
|
||||
|
||||
@Autowired RedisOperations<String, String> operations;
|
||||
|
||||
@@ -15,13 +15,10 @@
|
||||
*/
|
||||
package example.springdata.redis.commands;
|
||||
|
||||
import example.springdata.redis.test.condition.EnabledOnRedisAvailable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
@@ -36,7 +33,6 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@DataRedisTest
|
||||
@EnabledOnRedisAvailable
|
||||
class KeyOperationsTests {
|
||||
|
||||
private static final String PREFIX = KeyOperationsTests.class.getSimpleName();
|
||||
|
||||
@@ -33,19 +33,19 @@
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.redis</groupId>
|
||||
<artifactId>testcontainers-redis</artifactId>
|
||||
<version>2.2.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.kstyrc</groupId>
|
||||
<artifactId>embedded-redis</artifactId>
|
||||
<version>0.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -16,9 +16,13 @@
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-data-redis-example-utils</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-testcontainers</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -15,10 +15,22 @@
|
||||
*/
|
||||
package example.springdata.redis;
|
||||
|
||||
import com.redis.testcontainers.RedisContainer;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class RedisTestConfiguration {}
|
||||
public class RedisTestConfiguration {
|
||||
|
||||
@Bean
|
||||
@ServiceConnection(name = "redis")
|
||||
RedisContainer redisContainer() {
|
||||
return new RedisContainer(DockerImageName.parse("redis:7"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,9 +41,13 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-data-redis-example-utils</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-testcontainers</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -15,28 +15,30 @@
|
||||
*/
|
||||
package example.springdata.redis;
|
||||
|
||||
import jakarta.annotation.PreDestroy;
|
||||
|
||||
import com.redis.testcontainers.RedisContainer;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext.RedisSerializationContextBuilder;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class RedisTestConfiguration {
|
||||
|
||||
@Bean
|
||||
public LettuceConnectionFactory redisConnectionFactory() {
|
||||
return new LettuceConnectionFactory();
|
||||
@ServiceConnection(name = "redis")
|
||||
RedisContainer redisContainer() {
|
||||
return new RedisContainer(DockerImageName.parse("redis:7"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,10 +74,4 @@ public class RedisTestConfiguration {
|
||||
return new ReactiveRedisTemplate<>(connectionFactory, serializationContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear database before shut down.
|
||||
*/
|
||||
public @PreDestroy void flushTestDb() {
|
||||
redisConnectionFactory().getConnection().flushDb();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,19 +15,14 @@
|
||||
*/
|
||||
package example.springdata.redis.commands;
|
||||
|
||||
import example.springdata.redis.RedisTestConfiguration;
|
||||
import example.springdata.redis.test.condition.EnabledOnRedisAvailable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import example.springdata.redis.RedisTestConfiguration;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection;
|
||||
@@ -36,6 +31,8 @@ import org.springframework.data.redis.connection.ReactiveStringCommands.SetComma
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.data.redis.util.ByteUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
/**
|
||||
* Show usage of reactive operations on Redis keys using low level API provided by
|
||||
@@ -44,7 +41,6 @@ import org.springframework.data.redis.util.ByteUtils;
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@SpringBootTest(classes = RedisTestConfiguration.class)
|
||||
@EnabledOnRedisAvailable
|
||||
class KeyCommandsTests {
|
||||
|
||||
private static final String PREFIX = KeyCommandsTests.class.getSimpleName();
|
||||
|
||||
@@ -18,7 +18,6 @@ package example.springdata.redis.operations;
|
||||
import example.springdata.redis.EmailAddress;
|
||||
import example.springdata.redis.Person;
|
||||
import example.springdata.redis.RedisTestConfiguration;
|
||||
import example.springdata.redis.test.condition.EnabledOnRedisAvailable;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
@@ -39,7 +38,6 @@ import org.springframework.data.redis.util.ByteUtils;
|
||||
*/
|
||||
@Slf4j
|
||||
@SpringBootTest(classes = RedisTestConfiguration.class)
|
||||
@EnabledOnRedisAvailable
|
||||
class JacksonJsonTests {
|
||||
|
||||
@Autowired ReactiveRedisOperations<String, Person> typedOperations;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package example.springdata.redis.operations;
|
||||
|
||||
import example.springdata.redis.RedisTestConfiguration;
|
||||
import example.springdata.redis.test.condition.EnabledOnRedisAvailable;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
@@ -38,7 +37,6 @@ import org.springframework.data.redis.core.ReactiveRedisOperations;
|
||||
*/
|
||||
@Slf4j
|
||||
@SpringBootTest(classes = RedisTestConfiguration.class)
|
||||
@EnabledOnRedisAvailable
|
||||
class ListOperationsTests {
|
||||
|
||||
@Autowired ReactiveRedisOperations<String, String> operations;
|
||||
|
||||
@@ -18,7 +18,6 @@ package example.springdata.redis.operations;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.redis.RedisTestConfiguration;
|
||||
import example.springdata.redis.test.condition.EnabledOnRedisAvailable;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
@@ -39,7 +38,6 @@ import org.springframework.data.redis.core.ReactiveRedisOperations;
|
||||
*/
|
||||
@Slf4j
|
||||
@SpringBootTest(classes = RedisTestConfiguration.class)
|
||||
@EnabledOnRedisAvailable
|
||||
class ValueOperationsTests {
|
||||
|
||||
@Autowired ReactiveRedisOperations<String, String> operations;
|
||||
|
||||
@@ -15,15 +15,13 @@
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-data-redis-example-utils</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-testcontainers</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.kstyrc</groupId>
|
||||
<artifactId>embedded-redis</artifactId>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package example.springdata.redis.repositories;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.redis.test.condition.EnabledOnRedisAvailable;
|
||||
import com.redis.testcontainers.RedisContainer;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -40,16 +41,23 @@ import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.core.RedisOperations;
|
||||
import org.springframework.data.redis.core.index.GeoIndexed;
|
||||
import org.springframework.data.redis.core.index.Indexed;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Testcontainers
|
||||
@DataRedisTest
|
||||
@EnabledOnRedisAvailable
|
||||
class PersonRepositoryTests {
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
static RedisContainer redis = new RedisContainer(DockerImageName.parse("redis:7"));
|
||||
|
||||
/** {@link Charset} for String conversion **/
|
||||
private static final Charset CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
|
||||
@@ -22,9 +22,13 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-data-redis-example-utils</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-testcontainers</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -18,8 +18,12 @@ package example.springdata.redis.reactive;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.redis.connection.stream.StreamOffset.*;
|
||||
|
||||
import com.redis.testcontainers.RedisContainer;
|
||||
import example.springdata.redis.SensorData;
|
||||
import example.springdata.redis.test.condition.EnabledOnCommand;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.time.Duration;
|
||||
@@ -43,11 +47,15 @@ import org.springframework.data.redis.stream.StreamReceiver;
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@Testcontainers
|
||||
@DataRedisTest
|
||||
@EnabledOnCommand("XADD")
|
||||
@ImportAutoConfiguration(RedisReactiveAutoConfiguration.class)
|
||||
class ReactiveStreamApiTests {
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
static RedisContainer redis = new RedisContainer(DockerImageName.parse("redis:7"));
|
||||
|
||||
@Autowired ReactiveStringRedisTemplate template;
|
||||
@Autowired StreamReceiver<String, MapRecord<String, String, String>> streamReceiver;
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ package example.springdata.redis.sync;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.redis.connection.stream.StreamOffset.*;
|
||||
|
||||
import com.redis.testcontainers.RedisContainer;
|
||||
import example.springdata.redis.SensorData;
|
||||
import example.springdata.redis.test.condition.EnabledOnCommand;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
import org.springframework.data.redis.connection.stream.ReadOffset;
|
||||
@@ -36,15 +37,22 @@ import org.springframework.data.redis.connection.stream.StreamOffset;
|
||||
import org.springframework.data.redis.core.StreamOperations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Testcontainers
|
||||
@DataRedisTest
|
||||
@EnabledOnCommand("XADD")
|
||||
class SyncStreamApiTests {
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
static RedisContainer redis = new RedisContainer(DockerImageName.parse("redis:7"));
|
||||
|
||||
@Autowired StringRedisTemplate template;
|
||||
@Autowired StreamMessageListenerContainer<String, MapRecord<String, String, String>> messageListenerContainer;
|
||||
|
||||
|
||||
@@ -25,12 +25,6 @@
|
||||
<artifactId>lettuce-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.kstyrc</groupId>
|
||||
<artifactId>embedded-redis</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user