Skip to content

Commit 38eb85c

Browse files
committed
Test fixing run_it
1 parent d3d9a27 commit 38eb85c

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ val springWebVersion = "6.1.4"
5454

5555
// Implementation
5656
val kotlinJvmTarget = 21
57-
val cosmotechApiCommonVersion = "1.0.1-SNAPSHOT"
57+
val cosmotechApiCommonVersion = "1.0.0"
5858
val cosmotechApiAzureVersion = "1.0.0"
5959
val jedisVersion = "4.4.6"
6060
val springOauthVersion = "6.2.2"

run/src/integrationTest/kotlin/com/cosmotech/run/service/CsmRunTestBase.kt

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ package com.cosmotech.run.service
44

55
import com.cosmotech.api.tests.CsmRedisTestBase
66
import com.rabbitmq.client.ConnectionFactory.DEFAULT_AMQP_PORT
7+
import com.redis.om.spring.annotations.EnableRedisDocumentRepositories
8+
import com.redis.testcontainers.RedisServer
9+
import com.redis.testcontainers.RedisStackContainer
10+
import com.redis.testcontainers.junit.AbstractTestcontainersRedisTestBase
711
import org.junit.jupiter.api.AfterAll
812
import org.junit.jupiter.api.BeforeAll
913
import org.junit.jupiter.api.TestInstance
14+
import org.slf4j.LoggerFactory
1015
import org.springframework.test.context.DynamicPropertyRegistry
1116
import org.springframework.test.context.DynamicPropertySource
1217
import org.testcontainers.containers.PostgreSQLContainer
@@ -18,12 +23,17 @@ import org.testcontainers.utility.MountableFile
1823

1924
@Testcontainers
2025
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
21-
open class CsmRunTestBase : CsmRedisTestBase() {
26+
@EnableRedisDocumentRepositories(basePackages = ["com.cosmotech"])
27+
open class CsmRunTestBase : AbstractTestcontainersRedisTestBase() {
2228

2329
companion object {
2430
private const val ADMIN_USER_CREDENTIALS = "adminusertest"
2531
private const val READER_USER_CREDENTIALS = "readusertest"
2632
private const val WRITER_USER_CREDENTIALS = "writeusertest"
33+
private const val DEFAULT_REDIS_PORT = 6379
34+
private const val REDIS_STACK_LASTEST_TAG_WITH_GRAPH = "6.2.6-v9"
35+
36+
private val logger = LoggerFactory.getLogger(CsmRunTestBase::class.java)
2737

2838
var postgres: PostgreSQLContainer<*> =
2939
PostgreSQLContainer("postgres:alpine3.19")
@@ -33,7 +43,12 @@ open class CsmRunTestBase : CsmRedisTestBase() {
3343
var rabbit: RabbitMQContainer =
3444
RabbitMQContainer(DockerImageName.parse("rabbitmq:3.7.25-management-alpine"))
3545

46+
var redisStackServer =
47+
RedisStackContainer(
48+
RedisStackContainer.DEFAULT_IMAGE_NAME.withTag(REDIS_STACK_LASTEST_TAG_WITH_GRAPH))
49+
3650
init {
51+
redisStackServer.start()
3752
rabbit.start()
3853
postgres.start()
3954
}
@@ -42,9 +57,26 @@ open class CsmRunTestBase : CsmRedisTestBase() {
4257
@DynamicPropertySource
4358
fun connectionProperties(registry: DynamicPropertyRegistry) {
4459
initPostgresConfiguration(registry)
60+
initRedisConfiguration(registry)
4561
initRabbitMQConfiguration(registry)
4662
}
4763

64+
private fun initRedisConfiguration(registry: DynamicPropertyRegistry) {
65+
logger.error("Override properties to connect to Testcontainers:")
66+
val containerIp =
67+
redisStackServer.containerInfo.networkSettings.networks.entries
68+
.elementAt(0)
69+
.value
70+
.ipAddress
71+
logger.error(
72+
"* Test-Container 'Redis': spring.data.redis.host = {} ; spring.data.redis.port = {}",
73+
containerIp,
74+
DEFAULT_REDIS_PORT)
75+
76+
registry.add("spring.data.redis.host") { containerIp }
77+
registry.add("spring.data.redis.port") { DEFAULT_REDIS_PORT }
78+
}
79+
4880
private fun initRabbitMQConfiguration(registry: DynamicPropertyRegistry) {
4981
registry.add("spring.rabbitmq.host") { rabbit.host }
5082
registry.add("spring.rabbitmq.port") { rabbit.getMappedPort(DEFAULT_AMQP_PORT) }
@@ -86,6 +118,7 @@ open class CsmRunTestBase : CsmRedisTestBase() {
86118

87119
@BeforeAll
88120
fun beforeAll() {
121+
redisStackServer.start()
89122
rabbit.start()
90123
postgres.start()
91124
}
@@ -95,4 +128,8 @@ open class CsmRunTestBase : CsmRedisTestBase() {
95128
rabbit.stop()
96129
postgres.stop()
97130
}
131+
132+
override fun redisServers(): MutableCollection<RedisServer> {
133+
return mutableListOf(CsmRedisTestBase.redisStackServer)
134+
}
98135
}

0 commit comments

Comments
 (0)