diff --git a/kork-jedis-test/kork-jedis-test.gradle b/kork-jedis-test/kork-jedis-test.gradle index f47572afd..68aa64cef 100644 --- a/kork-jedis-test/kork-jedis-test.gradle +++ b/kork-jedis-test/kork-jedis-test.gradle @@ -4,5 +4,5 @@ dependencies { api(platform(project(":spinnaker-dependencies"))) api "redis.clients:jedis" - api "io.spinnaker.embedded-redis:embedded-redis" + implementation "org.testcontainers:testcontainers" } diff --git a/kork-jedis-test/src/main/java/com/netflix/spinnaker/kork/jedis/EmbeddedRedis.java b/kork-jedis-test/src/main/java/com/netflix/spinnaker/kork/jedis/EmbeddedRedis.java index 2f6c4fd48..b98400382 100644 --- a/kork-jedis-test/src/main/java/com/netflix/spinnaker/kork/jedis/EmbeddedRedis.java +++ b/kork-jedis-test/src/main/java/com/netflix/spinnaker/kork/jedis/EmbeddedRedis.java @@ -1,32 +1,23 @@ package com.netflix.spinnaker.kork.jedis; -import java.io.IOException; -import java.net.ServerSocket; -import java.net.URI; -import java.net.URISyntaxException; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.utility.DockerImageName; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; -import redis.clients.jedis.util.Pool; -import redis.embedded.RedisServer; public class EmbeddedRedis implements AutoCloseable { - private final URI connection; - private final RedisServer redisServer; + private static final int REDIS_PORT = 6379; - private Pool jedis; + private final GenericContainer redisContainer; - private EmbeddedRedis(int port) throws IOException, URISyntaxException { - this.connection = URI.create(String.format("redis://127.0.0.1:%d/0", port)); - this.redisServer = - RedisServer.builder() - .port(port) - .setting("bind 127.0.0.1") - .setting("appendonly no") - .setting("save \"\"") - .setting("databases 1") - .build(); - this.redisServer.start(); + private JedisPool jedis; + + private EmbeddedRedis() { + redisContainer = + new GenericContainer<>(DockerImageName.parse("library/redis:5-alpine")) + .withExposedPorts(REDIS_PORT); + redisContainer.start(); } @Override @@ -35,20 +26,20 @@ public void close() { } public void destroy() { - try { - this.redisServer.stop(); - } catch (Exception e) { - throw new RuntimeException(e); - } + redisContainer.stop(); + } + + public String getHost() { + return redisContainer.getHost(); } public int getPort() { - return redisServer.ports().get(0); + return redisContainer.getMappedPort(REDIS_PORT); } - public Pool getPool() { + public JedisPool getPool() { if (jedis == null) { - jedis = new JedisPool(connection); + jedis = new JedisPool(getHost(), getPort()); } return jedis; } @@ -58,13 +49,6 @@ public Jedis getJedis() { } public static EmbeddedRedis embed() { - try { - ServerSocket serverSocket = new ServerSocket(0); - int port = serverSocket.getLocalPort(); - serverSocket.close(); - return new EmbeddedRedis(port); - } catch (IOException | URISyntaxException e) { - throw new RuntimeException("Failed to create embedded Redis", e); - } + return new EmbeddedRedis(); } } diff --git a/spinnaker-dependencies/spinnaker-dependencies.gradle b/spinnaker-dependencies/spinnaker-dependencies.gradle index 317a82101..f2f55178d 100644 --- a/spinnaker-dependencies/spinnaker-dependencies.gradle +++ b/spinnaker-dependencies/spinnaker-dependencies.gradle @@ -15,10 +15,6 @@ ext { jooq : "3.13.6", jsch : "0.1.54", jschAgentProxy : "0.0.9", - // spring boot 2.5.14 specifies logback 1.2.11, but a rosco test hung with - // 1.2.11 from https://jira.qos.ch/browse/LOGBACK-1623 so pinning it to 1.2.12 - // until spring boot upgrade 2.5.15 or above. - logback : "1.2.12", protobuf : "3.21.12", okhttp : "2.7.5", // CVE-2016-2402 okhttp3 : "4.9.3", @@ -28,7 +24,7 @@ ext { spectator : "1.0.6", spek : "1.1.5", spek2 : "2.0.9", - springBoot : "2.5.14", + springBoot : "2.5.15", springCloud : "2020.0.6", springfoxSwagger : "2.9.2", swagger : "1.5.20", //this should stay in sync with what springfoxSwagger expects @@ -58,7 +54,6 @@ dependencies { //kotlinVersion comes from gradle.properties since we have kotlin code in // this project and need to configure gradle plugins etc. api(platform("org.jetbrains.kotlin:kotlin-bom:$kotlinVersion")) - api(platform("com.fasterxml.jackson:jackson-bom:2.12.7.20221012")) api(platform("io.zipkin.brave:brave-bom:${versions.brave}")) api(platform("org.springframework.boot:spring-boot-dependencies:${versions.springBoot}")) api(platform("com.amazonaws:aws-java-sdk-bom:${versions.aws}")) @@ -75,24 +70,6 @@ dependencies { constraints { api("cglib:cglib-nodep:3.3.0") - //A bug is reported in 1.2.11 and fixed in 1.2.12. - //So pinning the version to 1.2.12 until spring boot upgrade to 2.5.15 or above. - //[https://jira.qos.ch/browse/LOGBACK-1623] - api("ch.qos.logback:logback-core"){ - version { - strictly "${versions.logback}" - } - } - api("ch.qos.logback:logback-classic"){ - version { - strictly "${versions.logback}" - } - } - api("ch.qos.logback:logback-access"){ - version { - strictly "${versions.logback}" - } - } api("com.amazonaws:aws-java-sdk:${versions.aws}") api("com.google.api-client:google-api-client:1.30.10") // TODO: Track update for CVE-2020-7692, reanalysis pending. api("com.google.apis:google-api-services-admin-directory:directory_v1-rev105-1.25.0") @@ -125,7 +102,6 @@ dependencies { api("com.netflix.spectator:spectator-web-spring:${versions.spectator}") api("com.netflix.spectator:spectator-reg-micrometer:${versions.spectator}") api("com.nimbusds:nimbus-jose-jwt:7.9") - api("io.spinnaker.embedded-redis:embedded-redis:0.9.0") api("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0") api("com.nhaarman:mockito-kotlin:1.6.0") api("com.ninja-squad:springmockk:2.0.3")