diff --git a/pom.xml b/pom.xml index 5bedada..a51a107 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,8 @@ 5.0.2 6.2.3.RELEASE 6.5.0.202303070854-r + 1.19.2 + 1.7.0 21 UTF-8 @@ -147,6 +149,12 @@ + + com.redis + testcontainers-redis + ${testcontainers-redis.version} + test + org.junit.jupiter junit-jupiter-api @@ -165,6 +173,12 @@ ${junit.version} test + + org.testcontainers + testcontainers + ${testcontainers.version} + test + diff --git a/redis/pom.xml b/redis/pom.xml index 0d3a7ac..2d77611 100644 --- a/redis/pom.xml +++ b/redis/pom.xml @@ -23,5 +23,17 @@ ${lettuce-core.version} compile + + org.testcontainers + testcontainers + 1.19.2 + test + + + com.redis + testcontainers-redis + 1.7.0 + test + diff --git a/redis/src/main/java/com/manorrock/eagle/redis/RedisKeyValueStore.java b/redis/src/main/java/com/manorrock/eagle/redis/RedisKeyValueStore.java index a8eab8c..c99dfe2 100644 --- a/redis/src/main/java/com/manorrock/eagle/redis/RedisKeyValueStore.java +++ b/redis/src/main/java/com/manorrock/eagle/redis/RedisKeyValueStore.java @@ -118,4 +118,9 @@ public Map getDelegate() { public void put(K key, V value) { connection.sync().set(key, value); } + + @Override + public byte[] toUnderlyingKey(K key) { + return key.toString().getBytes(); + } } diff --git a/redis/src/test/java/com/manorrock/eagle/redis/RedisKeyValueStoreTest.java b/redis/src/test/java/com/manorrock/eagle/redis/RedisKeyValueStoreTest.java index d49d8fe..a376053 100644 --- a/redis/src/test/java/com/manorrock/eagle/redis/RedisKeyValueStoreTest.java +++ b/redis/src/test/java/com/manorrock/eagle/redis/RedisKeyValueStoreTest.java @@ -29,13 +29,12 @@ */ package com.manorrock.eagle.redis; +import com.redis.testcontainers.RedisContainer; import io.lettuce.core.RedisURI; -import java.io.FileInputStream; -import java.io.IOException; import java.net.URI; -import java.util.Properties; -import static java.util.logging.Level.WARNING; import java.util.logging.Logger; +import org.junit.ClassRule; +import org.junit.jupiter.api.AfterAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import org.junit.jupiter.api.BeforeAll; @@ -49,10 +48,11 @@ public class RedisKeyValueStoreTest { /** - * Stores the logger. + * Stores the Redis container. */ - private static final Logger LOGGER - = Logger.getLogger(RedisKeyValueStoreTest.class.getPackage().getName()); + @ClassRule + public static RedisContainer redis = new RedisContainer( + RedisContainer.DEFAULT_IMAGE_NAME.withTag(RedisContainer.DEFAULT_TAG)); /** * Stores the URI. @@ -60,20 +60,22 @@ public class RedisKeyValueStoreTest { private static URI uri; /** - * Verify if we can test Redis. + * Cleanup after running. + */ + @AfterAll + public static void afterAll() { + redis.stop(); + } + + /** + * Setup before running. + * + * @throws Exception when a serious error occurs. */ @BeforeAll - public static void setUpClass() { - try { - Properties properties = new Properties(); - properties.load(new FileInputStream("redis.properties")); - uri = RedisURI.Builder.redis(properties.getProperty("host")) - .withPort(Integer.parseInt(properties.getProperty("port"))) - .withSsl(false) - .withPassword(properties.getProperty("password").toCharArray()).build().toURI(); - } catch (IOException ioe) { - LOGGER.log(WARNING, "An exception occurred", ioe); - } + public static void beforeAll() throws Exception { + redis.start(); + uri = new URI(redis.getRedisURI()); } /**