Allow to execute tests against a remote server.
Update Maven pom to use "redis-host" and "redis-port" env. properties. Default values point to localhost:6379. Tests updated to use this properties and also defaulted to localhost:6379.
This commit is contained in:
@@ -12,31 +12,48 @@ import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Protocol;
|
||||
|
||||
public abstract class JedisCommandTestBase extends Assert {
|
||||
protected static String host = "localhost";
|
||||
protected static int port = Protocol.DEFAULT_PORT;
|
||||
static {
|
||||
final String envHost = System.getProperty("redis-host");
|
||||
final String envPort = System.getProperty("redis-port");
|
||||
if (null != envHost && 0 < envHost.length()) {
|
||||
host = envHost;
|
||||
}
|
||||
if (null != envPort && 0 < envPort.length()) {
|
||||
try {
|
||||
port = Integer.parseInt(envPort);
|
||||
} catch (final NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected Jedis jedis;
|
||||
System.out.println("Redis host to be used : " + host + ":" + port);
|
||||
}
|
||||
|
||||
public JedisCommandTestBase() {
|
||||
super();
|
||||
}
|
||||
protected Jedis jedis;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
jedis = new Jedis("localhost", Protocol.DEFAULT_PORT, 500);
|
||||
jedis.connect();
|
||||
jedis.auth("foobared");
|
||||
jedis.flushAll();
|
||||
}
|
||||
public JedisCommandTestBase() {
|
||||
super();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
jedis.disconnect();
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
jedis = new Jedis(host, port, 500);
|
||||
jedis.connect();
|
||||
jedis.auth("foobared");
|
||||
jedis.flushAll();
|
||||
}
|
||||
|
||||
protected Jedis createJedis() throws UnknownHostException, IOException {
|
||||
Jedis j = new Jedis("localhost");
|
||||
j.connect();
|
||||
j.auth("foobared");
|
||||
j.flushAll();
|
||||
return j;
|
||||
}
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
jedis.disconnect();
|
||||
}
|
||||
|
||||
protected Jedis createJedis() throws UnknownHostException, IOException {
|
||||
Jedis j = new Jedis(host, port);
|
||||
j.connect();
|
||||
j.auth("foobared");
|
||||
j.flushAll();
|
||||
return j;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user