|
|
|
@ -1,12 +1,10 @@
|
|
|
|
|
package org.redisson.config;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
|
|
|
|
|
import mockit.Mock;
|
|
|
|
|
import mockit.MockUp;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.URI;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
|
@ -17,7 +15,7 @@ public class ConfigSupportTest {
|
|
|
|
|
mockHostEnv("1.1.1.1");
|
|
|
|
|
SingleServerConfig config = mkConfig("127.0.0.1");
|
|
|
|
|
|
|
|
|
|
assertEquals(URI.create("redis://127.0.0.1"), config.getAddress());
|
|
|
|
|
assertEquals("redis://127.0.0.1", config.getAddress());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -25,13 +23,23 @@ public class ConfigSupportTest {
|
|
|
|
|
mockHostEnv("1.1.1.1");
|
|
|
|
|
SingleServerConfig config = mkConfig("${REDIS_URI}");
|
|
|
|
|
|
|
|
|
|
assertEquals(URI.create("redis://1.1.1.1"), config.getAddress());
|
|
|
|
|
assertEquals("redis://1.1.1.1", config.getAddress());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = InvalidFormatException.class)
|
|
|
|
|
@Test
|
|
|
|
|
public void testParsingEnv2() throws IOException {
|
|
|
|
|
mockHostPortEnv("1.1.1.1", "6379");
|
|
|
|
|
SingleServerConfig config = mkConfig("${REDIS_HOST}:${REDIS_PORT}");
|
|
|
|
|
|
|
|
|
|
assertEquals("redis://1.1.1.1:6379", config.getAddress());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testParsingEnv_envMissing() throws IOException {
|
|
|
|
|
mockHostEnv(null);
|
|
|
|
|
mkConfig("${REDIS_URI}");
|
|
|
|
|
final SingleServerConfig config = mkConfig("${REDIS_URI}");
|
|
|
|
|
|
|
|
|
|
assertEquals("redis://${REDIS_URI}", config.getAddress());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -39,7 +47,15 @@ public class ConfigSupportTest {
|
|
|
|
|
mockHostEnv("11.0.0.1");
|
|
|
|
|
SingleServerConfig config = mkConfig("${REDIS_URI:-10.0.0.1}");
|
|
|
|
|
|
|
|
|
|
assertEquals(URI.create("redis://11.0.0.1"), config.getAddress());
|
|
|
|
|
assertEquals("redis://11.0.0.1", config.getAddress());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testParsingDefault_envPresent2() throws IOException {
|
|
|
|
|
mockHostPortEnv("11.0.0.1", "1234");
|
|
|
|
|
SingleServerConfig config = mkConfig("${REDIS_HOST:-127.0.0.1}:${REDIS_PORT:-6379}");
|
|
|
|
|
|
|
|
|
|
assertEquals("redis://11.0.0.1:1234", config.getAddress());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -47,7 +63,15 @@ public class ConfigSupportTest {
|
|
|
|
|
mockHostEnv(null);
|
|
|
|
|
SingleServerConfig config = mkConfig("${REDIS_URI:-10.0.0.1}");
|
|
|
|
|
|
|
|
|
|
assertEquals(URI.create("redis://10.0.0.1"), config.getAddress());
|
|
|
|
|
assertEquals("redis://10.0.0.1", config.getAddress());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testParsingDefault_envMissing2() throws IOException {
|
|
|
|
|
mockHostPortEnv(null, null);
|
|
|
|
|
SingleServerConfig config = mkConfig("${REDIS_HOST:-127.0.0.1}:${REDIS_PORT:-6379}");
|
|
|
|
|
|
|
|
|
|
assertEquals("redis://127.0.0.1:6379", config.getAddress());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SingleServerConfig mkConfig(String authorityValue) throws IOException {
|
|
|
|
@ -64,4 +88,20 @@ public class ConfigSupportTest {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mockHostPortEnv(String host, String port) {
|
|
|
|
|
new MockUp<System>() {
|
|
|
|
|
@Mock
|
|
|
|
|
String getenv(String name) {
|
|
|
|
|
switch (name) {
|
|
|
|
|
case "REDIS_HOST":
|
|
|
|
|
return host;
|
|
|
|
|
case "REDIS_PORT":
|
|
|
|
|
return port;
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|