Skip to content

Commit

Permalink
test: 레디스 테스트 컨테이너 설정 추가
Browse files Browse the repository at this point in the history
테스트 컨테이너 설정을 추가하고 통합 테스트에 적용함.
  • Loading branch information
hseong3243 committed Aug 16, 2024
1 parent 53048a2 commit e00be9f
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class LettuceConfig {

@Bean
public LettuceConnectionFactory lettuceConnectionFactory() {
return new LettuceConnectionFactory();
return new LettuceConnectionFactory(host, port);
}

@Bean
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;

@SpringBootTest(
properties = {
"spring.data.redis.lettuce.host=localhost",
"spring.data.redis.lettuce.port=6379"
})
class LettuceConfigTest {
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
class LettuceConfigTest extends TestContainerStarter {

@Autowired private StringRedisTemplate lettuceRedisTemplate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;

@SpringBootTest(
properties = {
"spring.data.redis.redisson.host=localhost",
"spring.data.redis.redisson.port=6379"
})
class RedissonConfigTest {
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
class RedissonConfigTest extends TestContainerStarter {

@Autowired private RedissonClient redissonClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

import com.thirdparty.ticketing.domain.waiting.WaitingMember;
import com.thirdparty.ticketing.global.waiting.room.RedisRunningRoom;
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
class RedisRunningRoomTest {
class RedisRunningRoomTest extends TestContainerStarter {

@Autowired private RedisRunningRoom runningRoom;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

import com.thirdparty.ticketing.domain.waiting.WaitingMember;
import com.thirdparty.ticketing.global.waiting.room.RedisWaitingCounter;
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
class RedisWaitingCounterTest {
class RedisWaitingCounterTest extends TestContainerStarter {

@Autowired private RedisWaitingCounter waitingCounter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.thirdparty.ticketing.domain.waiting.WaitingMember;
import com.thirdparty.ticketing.global.waiting.room.RedisWaitingLine;
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
class RedisWaitingLineTest {
class RedisWaitingLineTest extends TestContainerStarter {

private static final String WAITING_LINE_KEY = "waiting_line:";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

import com.thirdparty.ticketing.domain.waiting.WaitingMember;
import com.thirdparty.ticketing.global.waiting.manager.RedisWaitingManager;
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
class RedisWaitingManagerTest {
class RedisWaitingManagerTest extends TestContainerStarter {

@Autowired private RedisWaitingManager waitingManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.thirdparty.ticketing.domain.waiting.WaitingMember;
import com.thirdparty.ticketing.global.waiting.room.RedisWaitingRoom;
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
class RedisWaitingRoomTest {
class RedisWaitingRoomTest extends TestContainerStarter {

@Autowired private RedisWaitingRoom waitingRoom;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.thirdparty.ticketing.support;

import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Testcontainers;

@Testcontainers
public class TestContainerStarter {

private static final String REDIS_IMAGE = "redis:7.4.0";
private static final int REDIS_PORT = 6379;
private static final GenericContainer<?> REDIS;

static {
REDIS = new GenericContainer<>(REDIS_IMAGE).withExposedPorts(REDIS_PORT).withReuse(true);
REDIS.start();
}

@DynamicPropertySource
private static void registerRedisProperties(DynamicPropertyRegistry registry) {
registry.add("spring.data.redis.lettuce.host", REDIS::getHost);
registry.add(
"spring.data.redis.lettuce.port", () -> REDIS.getMappedPort(REDIS_PORT).toString());
registry.add("spring.data.redis.redisson.host", REDIS::getHost);
registry.add(
"spring.data.redis.redisson.port",
() -> REDIS.getMappedPort(REDIS_PORT).toString());
}
}

0 comments on commit e00be9f

Please sign in to comment.