-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 도커 컴포즈 사용하도록 롤백 및 database cleaner 실행할때 레디스도 같이 초기화하도록 변경
- Loading branch information
Showing
9 changed files
with
62 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 9 additions & 17 deletions
26
src/test/java/com/gdschongik/gdsc/config/TestRedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,12 @@ | ||
package com.gdschongik.gdsc.config; | ||
|
||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
import com.gdschongik.gdsc.global.config.RedisConfig; | ||
import com.gdschongik.gdsc.global.property.RedisProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
public class TestRedisConfig implements BeforeAllCallback { | ||
private static final String REDIS_IMAGE = "redis:alpine"; | ||
private static final int REDIS_PORT = 6379; | ||
private GenericContainer redis; | ||
|
||
@Override | ||
public void beforeAll(ExtensionContext context) { | ||
redis = new GenericContainer(DockerImageName.parse(REDIS_IMAGE)).withExposedPorts(REDIS_PORT); | ||
redis.start(); | ||
System.setProperty("spring.data.redis.host", redis.getHost()); | ||
System.setProperty("spring.data.redis.port", String.valueOf(redis.getMappedPort(REDIS_PORT))); | ||
} | ||
} | ||
@TestConfiguration | ||
@EnableConfigurationProperties({RedisProperty.class}) | ||
@Import({RedisConfig.class}) | ||
public class TestRedisConfig {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/test/java/com/gdschongik/gdsc/helper/RedisCleaner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.gdschongik.gdsc.helper; | ||
|
||
import com.gdschongik.gdsc.global.property.RedisProperty; | ||
import io.lettuce.core.RedisClient; | ||
import io.lettuce.core.RedisURI; | ||
import io.lettuce.core.api.StatefulRedisConnection; | ||
import io.lettuce.core.api.sync.RedisCommands; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class RedisCleaner implements InitializingBean { | ||
private final RedisProperty redisProperty; | ||
private RedisClient redisClient; | ||
private StatefulRedisConnection<String, String> connection; | ||
private RedisCommands<String, String> commands; | ||
|
||
@Override | ||
public void afterPropertiesSet() { | ||
RedisURI redisUri = RedisURI.Builder.redis(redisProperty.getHost(), redisProperty.getPort()) | ||
.build(); | ||
redisClient = RedisClient.create(redisUri); | ||
connection = redisClient.connect(); | ||
commands = connection.sync(); | ||
} | ||
|
||
public void execute() { | ||
commands.flushdb(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters