test #426
@@ -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