Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #203 - Add Testcontainers setup for Redis #204

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<hazelcast.version>5.0.2</hazelcast.version>
<lettuce-core.version>6.2.3.RELEASE</lettuce-core.version>
<org.eclipse.jgit.version>6.5.0.202303070854-r</org.eclipse.jgit.version>
<testcontainers.version>1.19.2</testcontainers.version>
<testcontainers-redis.version>1.7.0</testcontainers-redis.version>
<!-- other -->
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -147,6 +149,12 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.redis</groupId>
<artifactId>testcontainers-redis</artifactId>
<version>${testcontainers-redis.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -165,6 +173,12 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<developers>
<developer>
Expand Down
12 changes: 12 additions & 0 deletions redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,17 @@
<version>${lettuce-core.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.19.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.redis</groupId>
<artifactId>testcontainers-redis</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,9 @@ public Map<String, Object> getDelegate() {
public void put(K key, V value) {
connection.sync().set(key, value);
}

@Override
public byte[] toUnderlyingKey(K key) {
return key.toString().getBytes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,31 +48,34 @@
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.
*/
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());
}

/**
Expand Down