This file contains hidden or 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
| @Tag("system") | |
| @Testcontainers | |
| @ActiveProfiles("docker") | |
| @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | |
| class EmployeesWithDockerEndpoint { | |
| // Tests | |
| } |
This file contains hidden or 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
| @Configuration | |
| @Profile("docker") | |
| class DockerConfig { | |
| companion object { | |
| val mock: GenericContainer<Nothing> = GenericContainer<Nothing>("postgres").also { | |
| it.withExposedPorts(5432) | |
| it.portBindings.add("55432:5432") | |
| it.addEnv("POSTGRES_USER", "test") | |
| it.addEnv("POSTGRES_PASSWORD", "test") | |
| it.withCopyFileToContainer( |
This file contains hidden or 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
| @Tag("integration") | |
| @Testcontainers | |
| @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | |
| class EmployeesWithDockerEndpoint { | |
| companion object { | |
| @Container | |
| val mock: GenericContainer<Nothing> = GenericContainer<Nothing>("iundarigun/mock-ws").also { | |
| it.withExposedPorts(1899) | |
| it.portBindings.add("18899:1899") |
This file contains hidden or 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
| @Testcontainers | |
| @Tag("unit") | |
| class DockerContainerTest { | |
| private val log = LoggerFactory.getLogger(javaClass) | |
| companion object { | |
| @Container | |
| val mock: GenericContainer<Nothing> = GenericContainer<Nothing>("iundarigun/mock-ws").also { | |
| it.withExposedPorts(1899) |
This file contains hidden or 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
| version: '3' | |
| services: | |
| rabbitmq1: | |
| image: rabbitmq:3-management | |
| container_name: rabbitmq1 | |
| hostname: rabbitmq1 | |
| network_mode: "bridge" | |
| environment: | |
| - RABBITMQ_ERLANG_COOKIE=docker-compose-rabbitmq-cluster | |
| ports: |
This file contains hidden or 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
| @Configuration | |
| class RedisConfiguration( | |
| @Value("\${spring.redis.host:}") | |
| private val masterHost: String, | |
| @Value("\${spring.redis.port:}") | |
| private val masterPort: Int, | |
| @Value("\${spring.redis.password:}") | |
| private val masterPassword: String, | |
| @Value("\${spring.redis-slave.host:}") | |
| private val slaveHost: String, |
This file contains hidden or 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
| @Repository | |
| class RedisRepository( | |
| private val redisMasterTemplate: StringRedisTemplate, | |
| private val redisSlaveTemplate: StringRedisTemplate | |
| ) { | |
| private val suffixKey = "devcave:masterslave:" | |
| fun setValue(key: String, value: String) { | |
| redisMasterTemplate.opsForValue().set(suffixKey + key, value) | |
| } |
This file contains hidden or 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
| @Import(RedisTestConfiguration::class) | |
| @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | |
| class ApplicationControllerTest { | |
| // Some variables | |
| @Test | |
| fun `findAll with some instance expired`() { | |
| val app = "APP1" | |
| val instance1 = InstanceDefinition( | |
| UUID.randomUUID().toString(), |
This file contains hidden or 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
| @TestConfiguration | |
| class RedisTestConfiguration( | |
| @Value("\${spring.redis.port}") | |
| private val redisPort: Int | |
| ) { | |
| private val redisServer: RedisServer = RedisServer(redisPort) | |
| @PostConstruct | |
| fun postConstruct() { | |
| redisServer.start() |
This file contains hidden or 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
| fun findInstancesByApplicationIdLua(applicationId: String): List<String> { | |
| val appKey = "$applicationPrefixKey:$applicationId" | |
| val instanceKey = "$instancePrefixKey:$applicationId" | |
| val redisScript = RedisScript.of( | |
| javaClass.getResource("/scripts/validation.lua").readText(), | |
| List::class.java) | |
| return redisTemplate.execute(redisScript, mutableListOf(appKey, instanceKey)).let { | |
| it as List<String> | |
| } | |
| } |