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:
17
pom.xml
17
pom.xml
@@ -12,6 +12,12 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<redis-host>localhost</redis-host>
|
||||||
|
<redis-port>6379</redis-port>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -23,6 +29,17 @@
|
|||||||
<target>1.6</target>
|
<target>1.6</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<redis-host>${redis-host}</redis-host>
|
||||||
|
<redis-port>${redis-port}</redis-port>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.io.IOException;
|
|||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
@@ -11,9 +12,27 @@ import redis.clients.jedis.JedisPool;
|
|||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
|
|
||||||
public class JedisPoolTest extends Assert {
|
public class JedisPoolTest extends Assert {
|
||||||
|
private static String host = "localhost";
|
||||||
|
private 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) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Redis host to be used : " + host + ":" + port);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkConnections() throws TimeoutException {
|
public void checkConnections() throws TimeoutException {
|
||||||
JedisPool pool = new JedisPool("localhost", Protocol.DEFAULT_PORT, 2000);
|
JedisPool pool = new JedisPool(host, port, 2000);
|
||||||
pool.setResourcesNumber(10);
|
pool.setResourcesNumber(10);
|
||||||
pool.init();
|
pool.init();
|
||||||
|
|
||||||
@@ -27,7 +46,7 @@ public class JedisPoolTest extends Assert {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkConnectionWithDefaultPort() throws TimeoutException {
|
public void checkConnectionWithDefaultPort() throws TimeoutException {
|
||||||
JedisPool pool = new JedisPool("localhost");
|
JedisPool pool = new JedisPool(host, port);
|
||||||
pool.setResourcesNumber(10);
|
pool.setResourcesNumber(10);
|
||||||
pool.init();
|
pool.init();
|
||||||
|
|
||||||
@@ -41,7 +60,7 @@ public class JedisPoolTest extends Assert {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkJedisIsReusedWhenReturned() throws TimeoutException {
|
public void checkJedisIsReusedWhenReturned() throws TimeoutException {
|
||||||
JedisPool pool = new JedisPool("localhost");
|
JedisPool pool = new JedisPool(host, port);
|
||||||
pool.setResourcesNumber(1);
|
pool.setResourcesNumber(1);
|
||||||
pool.init();
|
pool.init();
|
||||||
|
|
||||||
@@ -60,7 +79,7 @@ public class JedisPoolTest extends Assert {
|
|||||||
@Test
|
@Test
|
||||||
public void checkPoolRepairedWhenJedisIsBroken() throws TimeoutException,
|
public void checkPoolRepairedWhenJedisIsBroken() throws TimeoutException,
|
||||||
IOException {
|
IOException {
|
||||||
JedisPool pool = new JedisPool("localhost");
|
JedisPool pool = new JedisPool(host, port);
|
||||||
pool.setResourcesNumber(1);
|
pool.setResourcesNumber(1);
|
||||||
pool.init();
|
pool.init();
|
||||||
|
|
||||||
@@ -78,7 +97,7 @@ public class JedisPoolTest extends Assert {
|
|||||||
|
|
||||||
@Test(expected = TimeoutException.class)
|
@Test(expected = TimeoutException.class)
|
||||||
public void checkPoolOverflow() throws TimeoutException {
|
public void checkPoolOverflow() throws TimeoutException {
|
||||||
JedisPool pool = new JedisPool("localhost");
|
JedisPool pool = new JedisPool(host, port);
|
||||||
pool.setResourcesNumber(1);
|
pool.setResourcesNumber(1);
|
||||||
pool.init();
|
pool.init();
|
||||||
|
|
||||||
|
|||||||
@@ -6,19 +6,45 @@ import java.util.List;
|
|||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisPipeline;
|
import redis.clients.jedis.JedisPipeline;
|
||||||
|
import redis.clients.jedis.Protocol;
|
||||||
|
|
||||||
public class PipeliningTest extends Assert {
|
public class PipeliningTest extends Assert {
|
||||||
@Test
|
private static String host = "localhost";
|
||||||
public void pipeline() throws UnknownHostException, IOException {
|
private static int port = Protocol.DEFAULT_PORT;
|
||||||
Jedis jedis = new Jedis("localhost");
|
|
||||||
|
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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Redis host to be used : " + host + ":" + port);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Jedis jedis;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
jedis = new Jedis(host, port, 500);
|
||||||
jedis.connect();
|
jedis.connect();
|
||||||
jedis.auth("foobared");
|
jedis.auth("foobared");
|
||||||
jedis.flushAll();
|
jedis.flushAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void pipeline() throws UnknownHostException, IOException {
|
||||||
List<Object> results = jedis.pipelined(new JedisPipeline() {
|
List<Object> results = jedis.pipelined(new JedisPipeline() {
|
||||||
public void execute() {
|
public void execute() {
|
||||||
client.set("foo", "bar");
|
client.set("foo", "bar");
|
||||||
|
|||||||
@@ -12,6 +12,23 @@ import redis.clients.jedis.Jedis;
|
|||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
|
|
||||||
public abstract class JedisCommandTestBase extends Assert {
|
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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Redis host to be used : " + host + ":" + port);
|
||||||
|
}
|
||||||
|
|
||||||
protected Jedis jedis;
|
protected Jedis jedis;
|
||||||
|
|
||||||
@@ -21,7 +38,7 @@ public abstract class JedisCommandTestBase extends Assert {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
jedis = new Jedis("localhost", Protocol.DEFAULT_PORT, 500);
|
jedis = new Jedis(host, port, 500);
|
||||||
jedis.connect();
|
jedis.connect();
|
||||||
jedis.auth("foobared");
|
jedis.auth("foobared");
|
||||||
jedis.flushAll();
|
jedis.flushAll();
|
||||||
@@ -33,7 +50,7 @@ public abstract class JedisCommandTestBase extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Jedis createJedis() throws UnknownHostException, IOException {
|
protected Jedis createJedis() throws UnknownHostException, IOException {
|
||||||
Jedis j = new Jedis("localhost");
|
Jedis j = new Jedis(host, port);
|
||||||
j.connect();
|
j.connect();
|
||||||
j.auth("foobared");
|
j.auth("foobared");
|
||||||
j.flushAll();
|
j.flushAll();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.net.UnknownHostException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
@@ -13,6 +14,17 @@ import redis.clients.jedis.Transaction;
|
|||||||
import redis.clients.jedis.TransactionBlock;
|
import redis.clients.jedis.TransactionBlock;
|
||||||
|
|
||||||
public class TransactionCommandsTest extends JedisCommandTestBase {
|
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
|
@Test
|
||||||
public void multi() {
|
public void multi() {
|
||||||
Transaction trans = jedis.multi();
|
Transaction trans = jedis.multi();
|
||||||
@@ -62,7 +74,6 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.watch("mykey");
|
jedis.watch("mykey");
|
||||||
Transaction t = jedis.multi();
|
Transaction t = jedis.multi();
|
||||||
|
|
||||||
Jedis nj = new Jedis("localhost");
|
|
||||||
nj.connect();
|
nj.connect();
|
||||||
nj.auth("foobared");
|
nj.auth("foobared");
|
||||||
nj.set("mykey", "bar");
|
nj.set("mykey", "bar");
|
||||||
@@ -83,7 +94,6 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals("OK", status);
|
assertEquals("OK", status);
|
||||||
Transaction t = jedis.multi();
|
Transaction t = jedis.multi();
|
||||||
|
|
||||||
Jedis nj = new Jedis("localhost");
|
|
||||||
nj.connect();
|
nj.connect();
|
||||||
nj.auth("foobared");
|
nj.auth("foobared");
|
||||||
nj.set("mykey", "bar");
|
nj.set("mykey", "bar");
|
||||||
|
|||||||
Reference in New Issue
Block a user