Skip to content

Commit

Permalink
replace embeddedRedis with testcontainer
Browse files Browse the repository at this point in the history
Co-authored-by: Ahmet Kilic <[email protected]>,
Co-authored-by: Riko Stave <[email protected]>
  • Loading branch information
rikostave1234 committed Jan 3, 2024
1 parent 8f49908 commit cd85b19
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ext {
awsSdkVersion = "2.22.9"
springBootVersion = "3.1.3"
edisonVersion = "3.1.7"
testcontainersVersion = "1.19.3"
}


Expand Down Expand Up @@ -69,6 +70,7 @@ subprojects {
implementation(platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}"))

testImplementation(platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}"))
testImplementation(platform("org.testcontainers:testcontainers-bom:${testcontainersVersion}"))

implementation(platform("software.amazon.awssdk:bom:${awsSdkVersion}"))

Expand Down
4 changes: 2 additions & 2 deletions synapse-redis/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ dependencies {

testImplementation project(':synapse-testsupport:')

testImplementation 'com.github.kstyrc:embedded-redis:0.6'

testImplementation 'junit:junit'
testImplementation 'org.hamcrest:hamcrest-all:1.3'
testImplementation "org.springframework.boot:spring-boot-starter-test"
Expand All @@ -26,6 +24,8 @@ dependencies {
testImplementation "org.mockito:mockito-core"
testImplementation "ch.qos.logback:logback-core"
testImplementation "ch.qos.logback:logback-classic"
testImplementation "org.testcontainers:testcontainers"
testImplementation "com.redis:testcontainers-redis:2.0.1"
}

apply plugin: 'maven-publish'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
basePackages = {"de.otto.synapse.leaderelection"})
@SpringBootTest(
properties = {
"spring.redis.server=localhost",
"spring.redis.port=6379"
"spring.data.redis.host=localhost",
"spring.data.redis.port=6379"
},
classes = {
RedisLeaderElectionTest.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
basePackages = {"de.otto.synapse.messagestore.redis"})
@SpringBootTest(
properties = {
"spring.redis.server=localhost",
"spring.redis.port=6080"
"spring.data.redis.host=localhost",
"spring.data.redis.port=6080"
},
classes = {
RedisIndexedMessageStoreIntegrationTest.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
basePackages = {"de.otto.synapse.messagestore.redis"})
@SpringBootTest(
properties = {
"spring.redis.server=localhost",
"spring.redis.port=6079"
"spring.data.redis.host=localhost",
"spring.data.redis.port=6079"
},
classes = {
RedisRingBufferMessageStoreIntegrationTest.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
basePackages = {"de.otto.synapse.redis.playground"})
@SpringBootTest(
properties = {
"spring.redis.server=localhost",
"spring.redis.port=6479"
"spring.data.redis.host=localhost",
"spring.data.redis.port=6479"
},
classes = {
RedisPlayground.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package de.otto.synapse.testsupport.redis;

import com.redis.testcontainers.RedisContainer;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import redis.embedded.RedisServer;
import org.testcontainers.utility.DockerImageName;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import java.io.IOException;
import java.util.List;

import static org.slf4j.LoggerFactory.getLogger;

Expand All @@ -16,21 +17,21 @@ public class EmbeddedRedis {

private static final Logger LOG = getLogger(EmbeddedRedis.class);

@Value("${spring.redis.port}")
@Value("${spring.data.redis.port}")
private int redisPort;

private RedisServer redisServer;
private RedisContainer redisContainer;

@PostConstruct
public void startRedis() throws IOException {
LOG.info("Starting embedded Redis server on port {}", redisPort);
redisServer = new RedisServer(redisPort);
redisServer.start();
public void startRedis() {
LOG.info("Starting embedded Redis server on port {}.", redisPort);
redisContainer = new RedisContainer(DockerImageName.parse("redis:7"));
redisContainer.setPortBindings(List.of(String.format("%d:6379", redisPort)));
redisContainer.start();
}

@PreDestroy
public void stopRedis() {
LOG.info("Stopping embedded Redis server.");
redisServer.stop();
redisContainer.stop();
}
}

0 comments on commit cd85b19

Please sign in to comment.