Switch Redis samples to Testcontainers.

This commit is contained in:
Christoph Strobl
2024-08-22 07:21:45 +02:00
parent 7f3d39ddd9
commit dd846bd9e0
19 changed files with 107 additions and 88 deletions

View File

@@ -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"));
}
}

View File

@@ -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;

View File

@@ -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();