Update the way the Redis host(s) can be configured for the tests.

There is now a single property : redis-hosts.
This property must contain at least 2 host definitions of the form "host:port" (comma separated).
Sharding tests need 2 hosts ...

If this is not the case, the default value used is "localhost:6379,localhost:6380".
Tests that required one host are using the first definition.
This commit is contained in:
Yaourt
2010-09-15 10:49:36 +02:00
27 changed files with 2051 additions and 420 deletions

View File

@@ -219,4 +219,20 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
jedis.select(1);
assertEquals(0, jedis.dbSize());
}
@Test
public void persist() {
jedis.setex("foo", 60 * 60, "bar");
assertTrue(jedis.ttl("foo") > 0);
int status = jedis.persist("foo");
assertEquals(1, status);
assertEquals(-1, jedis.ttl("foo"));
}
@Test
public void echo() {
String result = jedis.echo("hello world");
assertEquals("hello world", result);
}
}

View File

@@ -16,8 +16,13 @@ public class ControlCommandsTest extends JedisCommandTestBase {
@Test
public void bgsave() {
String status = jedis.bgsave();
assertEquals("Background saving started", status);
try {
String status = jedis.bgsave();
assertEquals("Background saving started", status);
} catch (JedisException e) {
assertEquals("ERR background save already in progress", e
.getMessage());
}
}
@Test
@@ -72,4 +77,10 @@ public class ControlCommandsTest extends JedisCommandTestBase {
assertEquals("OK", status);
jedis.configSet("maxmemory", memory);
}
@Test
public void sync() {
jedis.sync();
}
}

View File

@@ -9,26 +9,11 @@ import org.junit.After;
import org.junit.Before;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.tests.HostAndPortUtil;
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
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 static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
protected Jedis jedis;
@@ -38,7 +23,7 @@ public abstract class JedisCommandTestBase extends Assert {
@Before
public void setUp() throws Exception {
jedis = new Jedis(host, port, 500);
jedis = new Jedis(hnp.host, hnp.port, 500);
jedis.connect();
jedis.auth("foobared");
jedis.flushAll();
@@ -50,7 +35,7 @@ public abstract class JedisCommandTestBase extends Assert {
}
protected Jedis createJedis() throws UnknownHostException, IOException {
Jedis j = new Jedis(host, port);
Jedis j = new Jedis(hnp.host, hnp.port);
j.connect();
j.auth("foobared");
j.flushAll();

View File

@@ -249,6 +249,25 @@ public class ListCommandsTest extends JedisCommandTestBase {
assertEquals(2, result.size());
assertEquals("foo", result.get(0));
assertEquals("bar", result.get(1));
}
@Test
public void lpushx() {
int status = jedis.lpushx("foo", "bar");
assertEquals(0, status);
jedis.lpush("foo", "a");
status = jedis.lpushx("foo", "b");
assertEquals(2, status);
}
@Test
public void rpushx() {
int status = jedis.rpushx("foo", "bar");
assertEquals(0, status);
jedis.lpush("foo", "a");
status = jedis.rpushx("foo", "b");
assertEquals(2, status);
}
}

View File

@@ -169,4 +169,10 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
assertEquals("This is a string", jedis.substr("s", 0, -1));
assertEquals(" string", jedis.substr("s", 9, 100000));
}
@Test
public void strlen() {
jedis.set("s", "This is a string");
assertEquals("This is a string".length(), jedis.strlen("s"));
}
}

View File

@@ -19,7 +19,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
public void setUp() throws Exception {
super.setUp();
nj = new Jedis(host, port, 500);
nj = new Jedis(hnp.host, hnp.port, 500);
nj.connect();
nj.auth("foobared");
nj.flushAll();