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;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
@@ -13,6 +14,17 @@ import redis.clients.jedis.Transaction;
|
||||
import redis.clients.jedis.TransactionBlock;
|
||||
|
||||
public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
Jedis nj;
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
nj = new Jedis(host, port, 500);
|
||||
nj.connect();
|
||||
nj.auth("foobared");
|
||||
nj.flushAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multi() {
|
||||
Transaction trans = jedis.multi();
|
||||
@@ -62,7 +74,6 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
jedis.watch("mykey");
|
||||
Transaction t = jedis.multi();
|
||||
|
||||
Jedis nj = new Jedis("localhost");
|
||||
nj.connect();
|
||||
nj.auth("foobared");
|
||||
nj.set("mykey", "bar");
|
||||
@@ -83,7 +94,6 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals("OK", status);
|
||||
Transaction t = jedis.multi();
|
||||
|
||||
Jedis nj = new Jedis("localhost");
|
||||
nj.connect();
|
||||
nj.auth("foobared");
|
||||
nj.set("mykey", "bar");
|
||||
|
||||
Reference in New Issue
Block a user