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:
Yaourt
2010-09-13 10:55:58 +02:00
parent 9211335f0d
commit d61f4d79d8
5 changed files with 185 additions and 96 deletions

View File

@@ -6,19 +6,45 @@ 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;
public class PipeliningTest 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);
}
private Jedis jedis;
@Before
public void setUp() throws Exception {
jedis = new Jedis(host, 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<Object> results = jedis.pipelined(new JedisPipeline() {
public void execute() {
client.set("foo", "bar");