diff --git a/pom.xml b/pom.xml
index cfa7ade..bc5d8ff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,6 +12,11 @@
compile
+
+
+ localhost:6379,localhost:6380
+
+
@@ -23,6 +28,16 @@
1.6
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.6
+
+
+ ${redis-hosts}
+
+
+
diff --git a/src/test/java/redis/clients/jedis/tests/HostAndPortUtil.java b/src/test/java/redis/clients/jedis/tests/HostAndPortUtil.java
new file mode 100644
index 0000000..a0098dd
--- /dev/null
+++ b/src/test/java/redis/clients/jedis/tests/HostAndPortUtil.java
@@ -0,0 +1,58 @@
+package redis.clients.jedis.tests;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import redis.clients.jedis.Protocol;
+
+public class HostAndPortUtil {
+ private static List hostAndPortList = new ArrayList(2);
+
+ static {
+ final HostAndPort defaulthnp1 = new HostAndPort();
+ defaulthnp1.host = "localhost";
+ defaulthnp1.port = Protocol.DEFAULT_PORT;
+ hostAndPortList.add(defaulthnp1);
+
+ final HostAndPort defaulthnp2 = new HostAndPort();
+ defaulthnp2.host = "localhost";
+ defaulthnp2.port = Protocol.DEFAULT_PORT + 1;
+ hostAndPortList.add(defaulthnp2);
+
+
+ final String envHosts = System.getProperty("redis-hosts");
+ if (null != envHosts && 0 < envHosts.length()) {
+ final String[] hostDefs = envHosts.split(",");
+ if (null != hostDefs && 2 <= hostDefs.length) {
+ hostAndPortList = new ArrayList(hostDefs.length);
+ for(String hostDef : hostDefs) {
+ final String[] hostAndPort = hostDef.split(":");
+ if (null != hostAndPort && 2 == hostAndPort.length) {
+ final HostAndPort hnp = new HostAndPort();
+ hnp.host = hostAndPort[0];
+ try {
+ hnp.port = Integer.parseInt(hostAndPort[1]);
+ } catch(final NumberFormatException nfe){
+ hnp.port = Protocol.DEFAULT_PORT;
+ }
+ hostAndPortList.add(hnp);
+ }
+ }
+ }
+ }
+ final StringBuilder strb = new StringBuilder("Redis hosts to be used : ");
+ for(HostAndPort hnp : hostAndPortList){
+ strb.append('[').append(hnp.host).append(':').append(hnp.port).append(']').append(' ');
+ }
+ System.out.println(strb);
+ }
+
+ public static List getRedisServers() {
+ return hostAndPortList;
+ }
+
+ public static class HostAndPort {
+ public String host;
+ public int port;
+ }
+}
diff --git a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java
index 89c15c9..b7eb7f8 100644
--- a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java
+++ b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java
@@ -8,83 +8,88 @@ import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
-import redis.clients.jedis.Protocol;
+import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
public class JedisPoolTest extends Assert {
- @Test
- public void checkConnections() throws TimeoutException {
- JedisPool pool = new JedisPool("localhost", Protocol.DEFAULT_PORT,
- 2000, "foobared");
- pool.setResourcesNumber(10);
- pool.init();
+ private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
+
+ @Test
+ public void checkConnections() throws TimeoutException {
+ JedisPool pool = new JedisPool(hnp.host, hnp.port, 2000);
+ pool.setResourcesNumber(10);
+ pool.init();
- Jedis jedis = pool.getResource(200);
- jedis.set("foo", "bar");
- assertEquals("bar", jedis.get("foo"));
- pool.returnResource(jedis);
- pool.destroy();
- }
+ Jedis jedis = pool.getResource(200);
+ jedis.auth("foobared");
+ jedis.set("foo", "bar");
+ assertEquals("bar", jedis.get("foo"));
+ pool.returnResource(jedis);
+ pool.destroy();
+ }
- @Test
- public void checkConnectionWithDefaultPort() throws TimeoutException {
- JedisPool pool = new JedisPool("localhost", Protocol.DEFAULT_PORT,
- 2000, "foobared");
- pool.setResourcesNumber(10);
- pool.init();
+ @Test
+ public void checkConnectionWithDefaultPort() throws TimeoutException {
+ JedisPool pool = new JedisPool(hnp.host, hnp.port);
+ pool.setResourcesNumber(10);
+ pool.init();
- Jedis jedis = pool.getResource(200);
- jedis.set("foo", "bar");
- assertEquals("bar", jedis.get("foo"));
- pool.returnResource(jedis);
- pool.destroy();
- }
+ Jedis jedis = pool.getResource(200);
+ jedis.auth("foobared");
+ jedis.set("foo", "bar");
+ assertEquals("bar", jedis.get("foo"));
+ pool.returnResource(jedis);
+ pool.destroy();
+ }
- @Test
- public void checkJedisIsReusedWhenReturned() throws TimeoutException {
- JedisPool pool = new JedisPool("localhost", Protocol.DEFAULT_PORT,
- 2000, "foobared");
- pool.setResourcesNumber(1);
- pool.init();
+ @Test
+ public void checkJedisIsReusedWhenReturned() throws TimeoutException {
+ JedisPool pool = new JedisPool(hnp.host, hnp.port);
+ pool.setResourcesNumber(1);
+ pool.init();
- Jedis jedis = pool.getResource(200);
- jedis.set("foo", "0");
- pool.returnResource(jedis);
+ Jedis jedis = pool.getResource(200);
+ jedis.auth("foobared");
+ jedis.set("foo", "0");
+ pool.returnResource(jedis);
- jedis = pool.getResource(200);
- jedis.incr("foo");
- pool.returnResource(jedis);
- pool.destroy();
- }
+ jedis = pool.getResource(200);
+ jedis.auth("foobared");
+ jedis.incr("foo");
+ pool.returnResource(jedis);
+ pool.destroy();
+ }
- @Test
- public void checkPoolRepairedWhenJedisIsBroken() throws TimeoutException,
- IOException {
- JedisPool pool = new JedisPool("localhost", Protocol.DEFAULT_PORT,
- 2000, "foobared");
- pool.setResourcesNumber(1);
- pool.init();
+ @Test
+ public void checkPoolRepairedWhenJedisIsBroken() throws TimeoutException,
+ IOException {
+ JedisPool pool = new JedisPool(hnp.host, hnp.port);
+ pool.setResourcesNumber(1);
+ pool.init();
- Jedis jedis = pool.getResource(200);
- jedis.quit();
- pool.returnBrokenResource(jedis);
+ Jedis jedis = pool.getResource(200);
+ jedis.auth("foobared");
+ jedis.quit();
+ pool.returnBrokenResource(jedis);
- jedis = pool.getResource(200);
- jedis.incr("foo");
- pool.returnResource(jedis);
- pool.destroy();
- }
+ jedis = pool.getResource(200);
+ jedis.auth("foobared");
+ jedis.incr("foo");
+ pool.returnResource(jedis);
+ pool.destroy();
+ }
- @Test(expected = TimeoutException.class)
- public void checkPoolOverflow() throws TimeoutException {
- JedisPool pool = new JedisPool("localhost", Protocol.DEFAULT_PORT,
- 2000, "foobared");
- pool.setResourcesNumber(1);
- pool.init();
+ @Test(expected = TimeoutException.class)
+ public void checkPoolOverflow() throws TimeoutException {
+ JedisPool pool = new JedisPool(hnp.host, hnp.port);
+ pool.setResourcesNumber(1);
+ pool.init();
- Jedis jedis = pool.getResource(200);
- jedis.set("foo", "0");
+ Jedis jedis = pool.getResource(200);
+ jedis.auth("foobared");
+ jedis.set("foo", "0");
- Jedis newJedis = pool.getResource(200);
- newJedis.incr("foo");
- }
+ Jedis newJedis = pool.getResource(200);
+ newJedis.auth("foobared");
+ newJedis.incr("foo");
+ }
}
\ No newline at end of file
diff --git a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java
index 8816555..68280be 100644
--- a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java
+++ b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java
@@ -6,19 +6,29 @@ import java.util.List;
import junit.framework.Assert;
+import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPipeline;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
public class PipeliningTest extends Assert {
+ private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
+
+ private Jedis jedis;
+
+ @Before
+ public void setUp() throws Exception {
+ jedis = new Jedis(hnp.host, hnp.port, 500);
+ jedis.connect();
+ jedis.auth("foobared");
+ jedis.flushAll();
+ }
+
@Test
public void pipeline() throws UnknownHostException, IOException {
- Jedis jedis = new Jedis("localhost");
- jedis.connect();
- jedis.auth("foobared");
- jedis.flushAll();
-
List