add JedisDataException and JedisConnectionException

This commit is contained in:
Jonathan Leibiusky
2011-01-30 17:46:17 -03:00
parent b4ad7697b7
commit 2a4a43f4cd
31 changed files with 269 additions and 263 deletions

View File

@@ -6,7 +6,7 @@ import java.util.Set;
import org.junit.Test;
import redis.clients.jedis.JedisException;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.util.SafeEncoder;
public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
@@ -205,16 +205,16 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
try {
jedis.set("foo", "bar");
jedis.rename("foo", "foo");
fail("JedisException expected");
} catch (final JedisException e) {
fail("JedisDataException expected");
} catch (final JedisDataException e) {
}
// Binary
try {
jedis.set(bfoo, bbar);
jedis.rename(bfoo, bfoo);
fail("JedisException expected");
} catch (final JedisException e) {
fail("JedisDataException expected");
} catch (final JedisDataException e) {
}
}

View File

@@ -7,8 +7,8 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.JedisException;
import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.exceptions.JedisDataException;
public class BinaryValuesCommandsTest extends JedisCommandTestBase {
byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
@@ -113,7 +113,7 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
assertTrue(Arrays.equals(bfoo, jedis.get(bbar)));
}
@Test(expected = JedisException.class)
@Test(expected = JedisDataException.class)
public void incrWrongValue() {
jedis.set(bfoo, binaryValue);
jedis.incr(bfoo);
@@ -127,7 +127,7 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
assertEquals(2, value);
}
@Test(expected = JedisException.class)
@Test(expected = JedisDataException.class)
public void incrByWrongValue() {
jedis.set(bfoo, binaryValue);
jedis.incrBy(bfoo, 2);
@@ -141,7 +141,7 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
assertEquals(4, value);
}
@Test(expected = JedisException.class)
@Test(expected = JedisDataException.class)
public void decrWrongValue() {
jedis.set(bfoo, binaryValue);
jedis.decr(bfoo);
@@ -155,7 +155,7 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
assertEquals(-2, value);
}
@Test(expected = JedisException.class)
@Test(expected = JedisDataException.class)
public void decrByWrongValue() {
jedis.set(bfoo, binaryValue);
jedis.decrBy(bfoo, 2);

View File

@@ -5,93 +5,92 @@ import java.util.List;
import org.junit.Test;
import redis.clients.jedis.DebugParams;
import redis.clients.jedis.JedisException;
import redis.clients.jedis.JedisMonitor;
import redis.clients.jedis.exceptions.JedisDataException;
public class ControlCommandsTest extends JedisCommandTestBase {
@Test
public void save() {
String status = jedis.save();
assertEquals("OK", status);
String status = jedis.save();
assertEquals("OK", status);
}
@Test
public void bgsave() {
try {
String status = jedis.bgsave();
assertEquals("Background saving started", status);
} catch (JedisException e) {
assertTrue(
"ERR Background save already in progress"
.equalsIgnoreCase(e.getMessage()));
}
try {
String status = jedis.bgsave();
assertEquals("Background saving started", status);
} catch (JedisDataException e) {
assertTrue("ERR Background save already in progress"
.equalsIgnoreCase(e.getMessage()));
}
}
@Test
public void bgrewriteaof() {
String status = jedis.bgrewriteaof();
assertEquals("Background append only file rewriting started", status);
String status = jedis.bgrewriteaof();
assertEquals("Background append only file rewriting started", status);
}
@Test
public void lastsave() throws InterruptedException {
long before = jedis.lastsave();
String st = "";
while (!st.equals("OK")) {
try {
Thread.sleep(1000);
st = jedis.save();
} catch (JedisException e) {
long before = jedis.lastsave();
String st = "";
while (!st.equals("OK")) {
try {
Thread.sleep(1000);
st = jedis.save();
} catch (JedisDataException e) {
}
}
long after = jedis.lastsave();
assertTrue((after - before) > 0);
}
}
long after = jedis.lastsave();
assertTrue((after - before) > 0);
}
@Test
public void info() {
String info = jedis.info();
assertNotNull(info);
String info = jedis.info();
assertNotNull(info);
}
@Test
public void monitor() {
jedis.monitor(new JedisMonitor() {
@Override
public void onCommand(String command) {
assertTrue(command.contains("OK"));
client.disconnect();
}
});
jedis.monitor(new JedisMonitor() {
@Override
public void onCommand(String command) {
assertTrue(command.contains("OK"));
client.disconnect();
}
});
}
@Test
public void configGet() {
List<String> info = jedis.configGet("m*");
assertNotNull(info);
List<String> info = jedis.configGet("m*");
assertNotNull(info);
}
@Test
public void configSet() {
List<String> info = jedis.configGet("maxmemory");
String memory = info.get(1);
String status = jedis.configSet("maxmemory", "200");
assertEquals("OK", status);
jedis.configSet("maxmemory", memory);
List<String> info = jedis.configGet("maxmemory");
String memory = info.get(1);
String status = jedis.configSet("maxmemory", "200");
assertEquals("OK", status);
jedis.configSet("maxmemory", memory);
}
@Test
public void sync() {
jedis.sync();
jedis.sync();
}
@Test
public void debug() {
jedis.set("foo", "bar");
String resp = jedis.debug(DebugParams.OBJECT("foo"));
assertNotNull(resp);
resp = jedis.debug(DebugParams.RELOAD());
assertNotNull(resp);
String resp = jedis.debug(DebugParams.OBJECT("foo"));
assertNotNull(resp);
resp = jedis.debug(DebugParams.RELOAD());
assertNotNull(resp);
}
}

View File

@@ -1,7 +1,5 @@
package redis.clients.jedis.tests.commands;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -33,11 +31,11 @@ public abstract class JedisCommandTestBase extends JedisTestBase {
}
@After
public void tearDown() throws Exception {
public void tearDown() {
jedis.disconnect();
}
protected Jedis createJedis() throws UnknownHostException, IOException {
protected Jedis createJedis() {
Jedis j = new Jedis(hnp.host, hnp.port);
j.connect();
j.auth("foobared");

View File

@@ -1,7 +1,5 @@
package redis.clients.jedis.tests.commands;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -10,7 +8,7 @@ import org.junit.Test;
import redis.clients.jedis.Client;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisException;
import redis.clients.jedis.exceptions.JedisDataException;
public class ListCommandsTest extends JedisCommandTestBase {
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
@@ -76,16 +74,16 @@ public class ListCommandsTest extends JedisCommandTestBase {
try {
jedis.set("foo", "bar");
jedis.llen("foo");
fail("JedisException expected");
} catch (final JedisException e) {
fail("JedisDataException expected");
} catch (final JedisDataException e) {
}
// Binary
try {
jedis.set(bfoo, bbar);
jedis.llen(bfoo);
fail("JedisException expected");
} catch (final JedisException e) {
fail("JedisDataException expected");
} catch (final JedisDataException e) {
}
}
@@ -592,10 +590,6 @@ public class ListCommandsTest extends JedisCommandTestBase {
j.lpush("foo", "a");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
})).start();
@@ -614,10 +608,6 @@ public class ListCommandsTest extends JedisCommandTestBase {
j.lpush("foo", "a");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
})).start();

View File

@@ -8,14 +8,13 @@ import org.junit.Test;
import redis.clients.jedis.BinaryJedisPubSub;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisException;
import redis.clients.jedis.JedisPubSub;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.util.SafeEncoder;
public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
@Test
public void subscribe() throws UnknownHostException, IOException,
InterruptedException {
public void subscribe() throws InterruptedException {
Thread t = new Thread(new Runnable() {
public void run() {
try {
@@ -498,7 +497,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
}, "foo");
} catch (NullPointerException ex) {
fail();
} catch (JedisException ex) {
} catch (JedisDataException ex) {
// this is OK because we are not sending AUTH command
}
}

View File

@@ -5,7 +5,7 @@ import java.util.List;
import org.junit.Test;
import redis.clients.jedis.JedisException;
import redis.clients.jedis.exceptions.JedisDataException;
public class StringValuesCommandsTest extends JedisCommandTestBase {
@Test
@@ -95,7 +95,7 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
assertEquals("foo", jedis.get("bar"));
}
@Test(expected = JedisException.class)
@Test(expected = JedisDataException.class)
public void incrWrongValue() {
jedis.set("foo", "bar");
jedis.incr("foo");
@@ -109,7 +109,7 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
assertEquals(2, value);
}
@Test(expected = JedisException.class)
@Test(expected = JedisDataException.class)
public void incrByWrongValue() {
jedis.set("foo", "bar");
jedis.incrBy("foo", 2);
@@ -123,7 +123,7 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
assertEquals(4, value);
}
@Test(expected = JedisException.class)
@Test(expected = JedisDataException.class)
public void decrWrongValue() {
jedis.set("foo", "bar");
jedis.decr("foo");
@@ -137,7 +137,7 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
assertEquals(-2, value);
}
@Test(expected = JedisException.class)
@Test(expected = JedisDataException.class)
public void decrByWrongValue() {
jedis.set("foo", "bar");
jedis.decrBy("foo", 2);
@@ -184,7 +184,7 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
Integer.MAX_VALUE));
}
@Test(expected = JedisException.class)
@Test(expected = JedisDataException.class)
public void incrReallyLargeNumbers() {
jedis.set("foo", Long.toString(Long.MAX_VALUE));
long value = jedis.incr("foo");

View File

@@ -10,11 +10,11 @@ import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisException;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.Transaction;
import redis.clients.jedis.TransactionBlock;
import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.exceptions.JedisDataException;
public class TransactionCommandsTest extends JedisCommandTestBase {
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
@@ -27,7 +27,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
Jedis nj;
@Override
@Before
@Before
public void setUp() throws Exception {
super.setUp();
@@ -84,7 +84,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
public void multiBlock() {
List<Object> response = jedis.multi(new TransactionBlock() {
@Override
public void execute() {
public void execute() {
String status = sadd("foo", "a");
assertEquals(Keyword.QUEUED.name(), status);
@@ -105,7 +105,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
// Binary
response = jedis.multi(new TransactionBlock() {
@Override
public void execute() {
public void execute() {
String status = sadd(bfoo, ba);
assertEquals(Keyword.QUEUED.name(), status);
@@ -195,7 +195,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
(byte[]) resp.get(0));
}
@Test(expected = JedisException.class)
@Test(expected = JedisDataException.class)
public void validateWhenInMulti() {
jedis.multi();
jedis.ping();