test(user-creator-chat): Redis 통합 테스트 컨텍스트를 축소한다
embedded Redis 포트를 테스트 설정과 공유하도록 공개한다. Redis 통합 테스트 전용 Bean만 로드하도록 TestConfiguration을 추가한다. UserCreatorChat Redis 통합 테스트가 필요한 클래스만 로드하게 제한한다.
This commit is contained in:
@@ -5,13 +5,16 @@ import org.springframework.context.ConfigurableApplicationContext
|
|||||||
import redis.embedded.RedisServer
|
import redis.embedded.RedisServer
|
||||||
|
|
||||||
class EmbeddedRedisInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {
|
class EmbeddedRedisInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||||
|
companion object {
|
||||||
|
const val PORT = 16379
|
||||||
|
}
|
||||||
|
|
||||||
override fun initialize(applicationContext: ConfigurableApplicationContext) {
|
override fun initialize(applicationContext: ConfigurableApplicationContext) {
|
||||||
EmbeddedRedisHolder.start()
|
EmbeddedRedisHolder.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private object EmbeddedRedisHolder {
|
private object EmbeddedRedisHolder {
|
||||||
private const val PORT = 16379
|
|
||||||
private var redisServer: RedisServer? = null
|
private var redisServer: RedisServer? = null
|
||||||
private var shutdownHookRegistered = false
|
private var shutdownHookRegistered = false
|
||||||
|
|
||||||
@@ -22,7 +25,7 @@ private object EmbeddedRedisHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
redisServer = RedisServer.newRedisServer()
|
redisServer = RedisServer.newRedisServer()
|
||||||
.port(PORT)
|
.port(EmbeddedRedisInitializer.PORT)
|
||||||
.setting("bind 127.0.0.1")
|
.setting("bind 127.0.0.1")
|
||||||
.setting("daemonize no")
|
.setting("daemonize no")
|
||||||
.setting("appendonly no")
|
.setting("appendonly no")
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package kr.co.vividnext.sodalive.support
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||||
|
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
||||||
|
import org.springframework.boot.test.context.TestConfiguration
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory
|
||||||
|
import org.springframework.data.redis.connection.RedisStandaloneConfiguration
|
||||||
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate
|
||||||
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer
|
||||||
|
|
||||||
|
@TestConfiguration
|
||||||
|
class EmbeddedRedisTestConfiguration {
|
||||||
|
@Bean
|
||||||
|
fun redisConnectionFactory(): RedisConnectionFactory {
|
||||||
|
return LettuceConnectionFactory(RedisStandaloneConfiguration("127.0.0.1", EmbeddedRedisInitializer.PORT))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun stringRedisTemplate(redisConnectionFactory: RedisConnectionFactory): StringRedisTemplate {
|
||||||
|
return StringRedisTemplate(redisConnectionFactory)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun redisMessageListenerContainer(redisConnectionFactory: RedisConnectionFactory): RedisMessageListenerContainer {
|
||||||
|
val container = RedisMessageListenerContainer()
|
||||||
|
container.setConnectionFactory(redisConnectionFactory)
|
||||||
|
return container
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun objectMapper(): ObjectMapper {
|
||||||
|
return ObjectMapper()
|
||||||
|
.registerModule(KotlinModule.Builder().build())
|
||||||
|
.registerModule(JavaTimeModule())
|
||||||
|
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.v2.usercreatorchat.websocket
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import kr.co.vividnext.sodalive.support.EmbeddedRedisInitializer
|
import kr.co.vividnext.sodalive.support.EmbeddedRedisInitializer
|
||||||
|
import kr.co.vividnext.sodalive.support.EmbeddedRedisTestConfiguration
|
||||||
import org.junit.jupiter.api.AfterEach
|
import org.junit.jupiter.api.AfterEach
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Assertions.assertFalse
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
@@ -22,7 +23,15 @@ import java.time.Instant
|
|||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest(
|
||||||
|
classes = [
|
||||||
|
EmbeddedRedisTestConfiguration::class,
|
||||||
|
UserCreatorChatPresenceService::class,
|
||||||
|
UserCreatorChatWebSocketSessionRegistry::class,
|
||||||
|
UserCreatorChatRoomMessageBroker::class,
|
||||||
|
UserCreatorChatWebSocketServerIdConfig::class
|
||||||
|
]
|
||||||
|
)
|
||||||
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
|
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
|
||||||
@TestPropertySource(properties = ["user-creator-chat.websocket.server-id=redis-test-server"])
|
@TestPropertySource(properties = ["user-creator-chat.websocket.server-id=redis-test-server"])
|
||||||
class UserCreatorChatRedisIntegrationTest {
|
class UserCreatorChatRedisIntegrationTest {
|
||||||
|
|||||||
Reference in New Issue
Block a user