From 4c5759ddefb3faea575876f55df8fcab49054b48 Mon Sep 17 00:00:00 2001 From: jruaux Date: Thu, 29 Feb 2024 09:19:35 -0800 Subject: [PATCH] deps: Upgraded to latest testcontainers-redis --- .../java/com/redis/enterprise/Database.java | 4 ++ .../redis/enterprise/ContainerAdminTests.java | 8 +-- .../TestRedisEnterpriseContainer.java | 62 +++++++++++++++++++ gradle.properties | 2 +- 4 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 core/redis-enterprise-admin/src/test/java/com/redis/enterprise/TestRedisEnterpriseContainer.java diff --git a/core/redis-enterprise-admin/src/main/java/com/redis/enterprise/Database.java b/core/redis-enterprise-admin/src/main/java/com/redis/enterprise/Database.java index 162f2b9..e3c695f 100644 --- a/core/redis-enterprise-admin/src/main/java/com/redis/enterprise/Database.java +++ b/core/redis-enterprise-admin/src/main/java/com/redis/enterprise/Database.java @@ -348,6 +348,10 @@ public Builder memory(long memory) { return this; } + public Builder memoryMB(long memory) { + return memory(memory * MB_TO_BYTES); + } + public Builder port(Integer port) { this.port = port; return this; diff --git a/core/redis-enterprise-admin/src/test/java/com/redis/enterprise/ContainerAdminTests.java b/core/redis-enterprise-admin/src/test/java/com/redis/enterprise/ContainerAdminTests.java index 635535e..a08391b 100644 --- a/core/redis-enterprise-admin/src/test/java/com/redis/enterprise/ContainerAdminTests.java +++ b/core/redis-enterprise-admin/src/test/java/com/redis/enterprise/ContainerAdminTests.java @@ -5,20 +5,18 @@ import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import com.redis.testcontainers.RedisEnterpriseContainer; - @Testcontainers @EnabledOnOs(value = OS.LINUX) class ContainerAdminTests extends AbstractAdminTests { @Container - private static RedisEnterpriseContainer server = new RedisEnterpriseContainer( - RedisEnterpriseContainer.DEFAULT_IMAGE_NAME.withTag(RedisEnterpriseContainer.DEFAULT_TAG)); + private static TestRedisEnterpriseContainer container = new TestRedisEnterpriseContainer( + TestRedisEnterpriseContainer.DEFAULT_IMAGE_NAME.withTag(TestRedisEnterpriseContainer.DEFAULT_TAG)); @Override protected Admin admin() { Admin admin = new Admin(); - admin.withHost(server.getHost()); + admin.withHost(container.getHost()); return admin; } diff --git a/core/redis-enterprise-admin/src/test/java/com/redis/enterprise/TestRedisEnterpriseContainer.java b/core/redis-enterprise-admin/src/test/java/com/redis/enterprise/TestRedisEnterpriseContainer.java new file mode 100644 index 0000000..6042407 --- /dev/null +++ b/core/redis-enterprise-admin/src/test/java/com/redis/enterprise/TestRedisEnterpriseContainer.java @@ -0,0 +1,62 @@ +package com.redis.enterprise; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.utility.DockerImageName; + +import com.redis.testcontainers.AbstractRedisEnterpriseContainer; + +public class TestRedisEnterpriseContainer extends AbstractRedisEnterpriseContainer { + + private final Admin admin = new Admin(); + private Database database = Database.builder().shardCount(2).port(12000).ossCluster(true) + .modules(RedisModule.SEARCH, RedisModule.JSON, RedisModule.TIMESERIES, RedisModule.BLOOM).build(); + + private static final Logger log = LoggerFactory.getLogger(TestRedisEnterpriseContainer.class); + + public TestRedisEnterpriseContainer(String dockerImageName) { + super(dockerImageName); + } + + public TestRedisEnterpriseContainer(DockerImageName dockerImageName) { + super(dockerImageName); + } + + @Override + protected String getAdminUserName() { + return admin.getUserName(); + } + + @Override + protected String getAdminPassword() { + return admin.getPassword(); + } + + @Override + public int getRedisPort() { + return database.getPort(); + } + + @Override + public boolean isRedisCluster() { + return database.isOssCluster(); + } + + @Override + protected void doStart() { + admin.withHost(getHost()); + addFixedExposedPort(admin.getPort(), admin.getPort()); + addFixedExposedPort(database.getPort(), database.getPort()); + super.doStart(); + } + + @Override + protected void createCluster() throws Exception { + log.info("Waiting for cluster bootstrap"); + admin.waitForBoostrap(); + super.createCluster(); + Database response = admin.createDatabase(database); + log.info("Created database {} with UID {}", response.getName(), response.getUid()); + } + +} diff --git a/gradle.properties b/gradle.properties index c073e4d..21ef964 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ springBootVersion = 3.2.3 jacocoVersion = 0.8.11 lettucemodVersion = 3.7.3 -testcontainersRedisVersion = 2.1.0 +testcontainersRedisVersion = 2.1.1 org.gradle.daemon = false org.gradle.caching = false