* JAVA-20164 Upgrade java hibernate specific modules to JDK 11 * JAVA-20164 Migrating java-jpa-2 * JAVA-20164 Migrating jnosql-artemis * JAVA-20164 Migrating querydsl * JAVA-20164 Migrating r2dbc * JAVA-20164 Migrating redis * JAVA-20164 Fixing test JPATextUnitTest#givenExam_whenSaveExam_thenReturnExpectedExam * JAVA-20164 Fixing givenIdentityStrategy_whenCommitTransction_thenReturnPrimaryKey * JAVA-20164 Changes after review * JAVA-20164 Migrating java-cassandra to jdk8 * JAVA-20164 Fix legacy mode error * Update pom.xml --------- Co-authored-by: timis1 <noreplay@yahoo.com> Co-authored-by: Dhawal Kapil <dhawalkapil@gmail.com>
84 lines
2.4 KiB
Java
84 lines
2.4 KiB
Java
package com.baeldung;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.net.ServerSocket;
|
|
import java.nio.charset.Charset;
|
|
|
|
import org.junit.AfterClass;
|
|
import org.junit.BeforeClass;
|
|
import org.junit.Test;
|
|
import org.redisson.Redisson;
|
|
import org.redisson.api.RedissonClient;
|
|
import org.redisson.config.Config;
|
|
|
|
import com.google.common.io.Files;
|
|
|
|
import redis.embedded.RedisServer;
|
|
|
|
/**
|
|
* Created by johnson on 3/9/17.
|
|
*/
|
|
public class RedissonConfigurationIntegrationTest {
|
|
private static RedisServer redisServer;
|
|
private static RedissonClient client;
|
|
private static int port;
|
|
|
|
@BeforeClass
|
|
public static void setUp() throws IOException {
|
|
|
|
// Take an available port
|
|
ServerSocket s = new ServerSocket(0);
|
|
port = s.getLocalPort();
|
|
s.close();
|
|
|
|
redisServer = RedisServer.builder()
|
|
.port(port)
|
|
.setting("maxheap 128M")
|
|
.build();
|
|
redisServer.start();
|
|
}
|
|
|
|
@AfterClass
|
|
public static void destroy() {
|
|
redisServer.stop();
|
|
if (client != null) {
|
|
client.shutdown();
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void givenJavaConfig_thenRedissonConnectToRedis() {
|
|
Config config = new Config();
|
|
config.useSingleServer()
|
|
.setAddress(String.format("redis://127.0.0.1:%s", port));
|
|
|
|
client = Redisson.create(config);
|
|
|
|
assert(client != null && client.getKeys().count() >= 0);
|
|
}
|
|
|
|
@Test
|
|
public void givenJSONFileConfig_thenRedissonConnectToRedis() throws IOException {
|
|
|
|
File configFile = new File(getClass().getClassLoader().getResource("singleNodeConfig.json").getFile());
|
|
String configContent = Files.toString(configFile, Charset.defaultCharset()).replace("6379", String.valueOf(port));
|
|
|
|
Config config = Config.fromJSON(configContent);
|
|
client = Redisson.create(config);
|
|
|
|
assert(client != null && client.getKeys().count() >= 0);
|
|
}
|
|
|
|
@Test
|
|
public void givenYAMLFileConfig_thenRedissonConnectToRedis() throws IOException {
|
|
|
|
File configFile = new File(getClass().getClassLoader().getResource("singleNodeConfig.yaml").getFile());
|
|
String configContent = Files.toString(configFile, Charset.defaultCharset()).replace("6379", String.valueOf(port));
|
|
|
|
Config config = Config.fromYAML(configContent);
|
|
client = Redisson.create(config);
|
|
|
|
assert(client != null && client.getKeys().count() >= 0);
|
|
}
|
|
} |