add JedisDataException and JedisConnectionException
This commit is contained in:
@@ -11,6 +11,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
import redis.clients.util.JedisByteHashMap;
|
import redis.clients.util.JedisByteHashMap;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import static redis.clients.jedis.Protocol.Keyword.UNSUBSCRIBE;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
|
|
||||||
public abstract class BinaryJedisPubSub {
|
public abstract class BinaryJedisPubSub {
|
||||||
private int subscribedChannels = 0;
|
private int subscribedChannels = 0;
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package redis.clients.jedis;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import redis.clients.jedis.Protocol.Command;
|
import redis.clients.jedis.Protocol.Command;
|
||||||
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
import redis.clients.util.RedisInputStream;
|
import redis.clients.util.RedisInputStream;
|
||||||
import redis.clients.util.RedisOutputStream;
|
import redis.clients.util.RedisOutputStream;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
@@ -60,26 +61,14 @@ public class Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Connection sendCommand(final Command cmd, final byte[]... args) {
|
protected Connection sendCommand(final Command cmd, final byte[]... args) {
|
||||||
try {
|
connect();
|
||||||
connect();
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
throw new JedisException("Could not connect to redis-server", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new JedisException("Could not connect to redis-server", e);
|
|
||||||
}
|
|
||||||
protocol.sendCommand(outputStream, cmd, args);
|
protocol.sendCommand(outputStream, cmd, args);
|
||||||
pipelinedCommands++;
|
pipelinedCommands++;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Connection sendCommand(final Command cmd) {
|
protected Connection sendCommand(final Command cmd) {
|
||||||
try {
|
connect();
|
||||||
connect();
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
throw new JedisException("Could not connect to redis-server", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new JedisException("Could not connect to redis-server", e);
|
|
||||||
}
|
|
||||||
protocol.sendCommand(outputStream, cmd, new byte[0][]);
|
protocol.sendCommand(outputStream, cmd, new byte[0][]);
|
||||||
pipelinedCommands++;
|
pipelinedCommands++;
|
||||||
return this;
|
return this;
|
||||||
@@ -110,12 +99,16 @@ public class Connection {
|
|||||||
public Connection() {
|
public Connection() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect() throws UnknownHostException, IOException {
|
public void connect() {
|
||||||
if (!isConnected()) {
|
if (!isConnected()) {
|
||||||
socket = new Socket(host, port);
|
try {
|
||||||
socket.setSoTimeout(timeout);
|
socket = new Socket(host, port);
|
||||||
outputStream = new RedisOutputStream(socket.getOutputStream());
|
socket.setSoTimeout(timeout);
|
||||||
inputStream = new RedisInputStream(socket.getInputStream());
|
outputStream = new RedisOutputStream(socket.getOutputStream());
|
||||||
|
inputStream = new RedisInputStream(socket.getInputStream());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new JedisConnectionException(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +121,7 @@ public class Connection {
|
|||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new JedisException(ex);
|
throw new JedisConnectionException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -12,6 +10,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
|
|
||||||
public class Jedis extends BinaryJedis implements JedisCommands {
|
public class Jedis extends BinaryJedis implements JedisCommands {
|
||||||
public Jedis(final String host) {
|
public Jedis(final String host) {
|
||||||
@@ -1647,19 +1646,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
|||||||
|
|
||||||
private void runChecks() {
|
private void runChecks() {
|
||||||
if (client.isInMulti()) {
|
if (client.isInMulti()) {
|
||||||
throw new JedisException(
|
throw new JedisDataException(
|
||||||
"Cannot use Jedis when in Multi. Please use JedisTransaction instead.");
|
"Cannot use Jedis when in Multi. Please use JedisTransaction instead.");
|
||||||
}
|
}
|
||||||
try {
|
this.connect();
|
||||||
this.connect();
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
throw new JedisException(e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new JedisException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect() throws UnknownHostException, IOException {
|
public void connect() {
|
||||||
if (!client.isConnected()) {
|
if (!client.isConnected()) {
|
||||||
client.connect();
|
client.connect();
|
||||||
if (this.password != null) {
|
if (this.password != null) {
|
||||||
@@ -1668,7 +1661,7 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() throws IOException {
|
public void disconnect() {
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
package redis.clients.jedis;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class JedisException extends RuntimeException {
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = -2946266495682282677L;
|
|
||||||
|
|
||||||
public JedisException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JedisException(IOException e) {
|
|
||||||
super(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JedisException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,6 +10,7 @@ import static redis.clients.jedis.Protocol.Keyword.UNSUBSCRIBE;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
public abstract class JedisPubSub {
|
public abstract class JedisPubSub {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
import redis.clients.util.RedisInputStream;
|
import redis.clients.util.RedisInputStream;
|
||||||
import redis.clients.util.RedisOutputStream;
|
import redis.clients.util.RedisOutputStream;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
@@ -44,13 +46,13 @@ public final class Protocol {
|
|||||||
}
|
}
|
||||||
os.flush();
|
os.flush();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new JedisException(e);
|
throw new JedisConnectionException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processError(final RedisInputStream is) {
|
private void processError(final RedisInputStream is) {
|
||||||
String message = is.readLine();
|
String message = is.readLine();
|
||||||
throw new JedisException(message);
|
throw new JedisDataException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object process(final RedisInputStream is) {
|
private Object process(final RedisInputStream is) {
|
||||||
@@ -67,10 +69,10 @@ public final class Protocol {
|
|||||||
} else if (b == PLUS_BYTE) {
|
} else if (b == PLUS_BYTE) {
|
||||||
return processStatusCodeReply(is);
|
return processStatusCodeReply(is);
|
||||||
} else {
|
} else {
|
||||||
throw new JedisException("Unknown reply: " + (char) b);
|
throw new JedisConnectionException("Unknown reply: " + (char) b);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new JedisException(e);
|
throw new JedisConnectionException(e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -94,7 +96,7 @@ public final class Protocol {
|
|||||||
is.readByte();
|
is.readByte();
|
||||||
is.readByte();
|
is.readByte();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new JedisException(e);
|
throw new JedisConnectionException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return read;
|
return read;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -28,8 +27,7 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
|||||||
super(shards, algo, keyTagPattern);
|
super(shards, algo, keyTagPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void disconnect() {
|
||||||
public void disconnect() throws IOException {
|
|
||||||
for (Jedis jedis : getAllShards()) {
|
for (Jedis jedis : getAllShards()) {
|
||||||
jedis.quit();
|
jedis.quit();
|
||||||
jedis.disconnect();
|
jedis.disconnect();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
|
|
||||||
public abstract class TransactionBlock extends Transaction {
|
public abstract class TransactionBlock extends Transaction {
|
||||||
public TransactionBlock(Client client) {
|
public TransactionBlock(Client client) {
|
||||||
super(client);
|
super(client);
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package redis.clients.jedis.exceptions;
|
||||||
|
|
||||||
|
public class JedisConnectionException extends JedisException {
|
||||||
|
private static final long serialVersionUID = 3878126572474819403L;
|
||||||
|
|
||||||
|
public JedisConnectionException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JedisConnectionException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JedisConnectionException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package redis.clients.jedis.exceptions;
|
||||||
|
|
||||||
|
public class JedisDataException extends JedisException {
|
||||||
|
private static final long serialVersionUID = 3878126572474819403L;
|
||||||
|
|
||||||
|
public JedisDataException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JedisDataException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JedisDataException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package redis.clients.jedis.exceptions;
|
||||||
|
|
||||||
|
|
||||||
|
public class JedisException extends RuntimeException {
|
||||||
|
private static final long serialVersionUID = -2946266495682282677L;
|
||||||
|
|
||||||
|
public JedisException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JedisException(Throwable e) {
|
||||||
|
super(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JedisException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,8 @@ package redis.clients.util;
|
|||||||
import org.apache.commons.pool.PoolableObjectFactory;
|
import org.apache.commons.pool.PoolableObjectFactory;
|
||||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||||
|
|
||||||
import redis.clients.jedis.JedisException;
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
|
|
||||||
public abstract class Pool<T> {
|
public abstract class Pool<T> {
|
||||||
private final GenericObjectPool internalPool;
|
private final GenericObjectPool internalPool;
|
||||||
@@ -18,8 +19,8 @@ public abstract class Pool<T> {
|
|||||||
try {
|
try {
|
||||||
return (T) internalPool.borrowObject();
|
return (T) internalPool.borrowObject();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new JedisException("Could not get a resource from the pool",
|
throw new JedisConnectionException(
|
||||||
e);
|
"Could not get a resource from the pool", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ import java.io.FilterInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import redis.clients.jedis.JedisException;
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
|
|
||||||
public class RedisInputStream extends FilterInputStream {
|
public class RedisInputStream extends FilterInputStream {
|
||||||
|
|
||||||
@@ -87,13 +88,12 @@ public class RedisInputStream extends FilterInputStream {
|
|||||||
}
|
}
|
||||||
String reply = sb.toString();
|
String reply = sb.toString();
|
||||||
if (reply.length() == 0) {
|
if (reply.length() == 0) {
|
||||||
throw new JedisException(
|
throw new JedisConnectionException(
|
||||||
"It seems like server has closed the connection.");
|
"It seems like server has closed the connection.");
|
||||||
}
|
}
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read(byte[] b, int off, int len) throws IOException {
|
public int read(byte[] b, int off, int len) throws IOException {
|
||||||
if (count == limit) {
|
if (count == limit) {
|
||||||
fill();
|
fill();
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package redis.clients.util;
|
|||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
import redis.clients.jedis.JedisException;
|
|
||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The only reason to have this is to be able to compatible with java 1.5 :(
|
* The only reason to have this is to be able to compatible with java 1.5 :(
|
||||||
|
|||||||
@@ -1,38 +1,36 @@
|
|||||||
package redis.clients.jedis.tests;
|
package redis.clients.jedis.tests;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Connection;
|
import redis.clients.jedis.Connection;
|
||||||
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
|
|
||||||
public class ConnectionTest extends Assert {
|
public class ConnectionTest extends Assert {
|
||||||
private Connection client;
|
private Connection client;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
client = new Connection();
|
client = new Connection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = UnknownHostException.class)
|
@Test(expected = JedisConnectionException.class)
|
||||||
public void checkUnkownHost() throws UnknownHostException, IOException {
|
public void checkUnkownHost() {
|
||||||
client.setHost("someunknownhost");
|
client.setHost("someunknownhost");
|
||||||
client.connect();
|
client.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IOException.class)
|
@Test(expected = JedisConnectionException.class)
|
||||||
public void checkWrongPort() throws UnknownHostException, IOException {
|
public void checkWrongPort() {
|
||||||
client.setHost("localhost");
|
client.setHost("localhost");
|
||||||
client.setPort(55665);
|
client.setPort(55665);
|
||||||
client.connect();
|
client.connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,25 +6,25 @@ import java.io.ByteArrayInputStream;
|
|||||||
* Test class the fragment a byte array for testing purpose.
|
* Test class the fragment a byte array for testing purpose.
|
||||||
*/
|
*/
|
||||||
public class FragmentedByteArrayInputStream extends ByteArrayInputStream {
|
public class FragmentedByteArrayInputStream extends ByteArrayInputStream {
|
||||||
private int readMethodCallCount = 0;
|
private int readMethodCallCount = 0;
|
||||||
public FragmentedByteArrayInputStream(final byte[] buf) {
|
|
||||||
super(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public FragmentedByteArrayInputStream(final byte[] buf) {
|
||||||
public synchronized int read(final byte[] b, final int off, final int len) {
|
super(buf);
|
||||||
readMethodCallCount++;
|
}
|
||||||
if (len <= 10) {
|
|
||||||
// if the len <= 10, return as usual ..
|
public synchronized int read(final byte[] b, final int off, final int len) {
|
||||||
return super.read(b, off, len);
|
readMethodCallCount++;
|
||||||
} else {
|
if (len <= 10) {
|
||||||
// else return the first half ..
|
// if the len <= 10, return as usual ..
|
||||||
return super.read(b, off, len / 2);
|
return super.read(b, off, len);
|
||||||
}
|
} else {
|
||||||
}
|
// else return the first half ..
|
||||||
|
return super.read(b, off, len / 2);
|
||||||
public int getReadMethodCallCount() {
|
}
|
||||||
return readMethodCallCount;
|
}
|
||||||
}
|
|
||||||
|
public int getReadMethodCallCount() {
|
||||||
|
return readMethodCallCount;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,53 +6,56 @@ import java.util.List;
|
|||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
|
|
||||||
public class HostAndPortUtil {
|
public class HostAndPortUtil {
|
||||||
private static List<HostAndPort> hostAndPortList = new ArrayList<HostAndPortUtil.HostAndPort>(2);
|
private static List<HostAndPort> hostAndPortList = new ArrayList<HostAndPortUtil.HostAndPort>(
|
||||||
|
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);
|
|
||||||
|
|
||||||
|
static {
|
||||||
final String envHosts = System.getProperty("redis-hosts");
|
final HostAndPort defaulthnp1 = new HostAndPort();
|
||||||
if (null != envHosts && 0 < envHosts.length()) {
|
defaulthnp1.host = "localhost";
|
||||||
final String[] hostDefs = envHosts.split(",");
|
defaulthnp1.port = Protocol.DEFAULT_PORT;
|
||||||
if (null != hostDefs && 2 <= hostDefs.length) {
|
hostAndPortList.add(defaulthnp1);
|
||||||
hostAndPortList = new ArrayList<HostAndPortUtil.HostAndPort>(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<HostAndPort> getRedisServers() {
|
final HostAndPort defaulthnp2 = new HostAndPort();
|
||||||
return hostAndPortList;
|
defaulthnp2.host = "localhost";
|
||||||
}
|
defaulthnp2.port = Protocol.DEFAULT_PORT + 1;
|
||||||
|
hostAndPortList.add(defaulthnp2);
|
||||||
public static class HostAndPort {
|
|
||||||
public String host;
|
final String envHosts = System.getProperty("redis-hosts");
|
||||||
public int port;
|
if (null != envHosts && 0 < envHosts.length()) {
|
||||||
}
|
final String[] hostDefs = envHosts.split(",");
|
||||||
|
if (null != hostDefs && 2 <= hostDefs.length) {
|
||||||
|
hostAndPortList = new ArrayList<HostAndPortUtil.HostAndPort>(
|
||||||
|
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<HostAndPort> getRedisServers() {
|
||||||
|
return hostAndPortList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HostAndPort {
|
||||||
|
public String host;
|
||||||
|
public int port;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ import org.junit.Assert;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisException;
|
|
||||||
import redis.clients.jedis.JedisPool;
|
import redis.clients.jedis.JedisPool;
|
||||||
import redis.clients.jedis.JedisPoolConfig;
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||||
|
|
||||||
public class JedisPoolTest extends Assert {
|
public class JedisPoolTest extends Assert {
|
||||||
private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
|
private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkConnections() throws Exception {
|
public void checkConnections() {
|
||||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host,
|
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host,
|
||||||
hnp.port, 2000);
|
hnp.port, 2000);
|
||||||
Jedis jedis = pool.getResource();
|
Jedis jedis = pool.getResource();
|
||||||
@@ -27,7 +27,7 @@ public class JedisPoolTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkConnectionWithDefaultPort() throws Exception {
|
public void checkConnectionWithDefaultPort() {
|
||||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host,
|
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host,
|
||||||
hnp.port);
|
hnp.port);
|
||||||
Jedis jedis = pool.getResource();
|
Jedis jedis = pool.getResource();
|
||||||
@@ -39,7 +39,7 @@ public class JedisPoolTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkJedisIsReusedWhenReturned() throws Exception {
|
public void checkJedisIsReusedWhenReturned() {
|
||||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host,
|
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host,
|
||||||
hnp.port);
|
hnp.port);
|
||||||
Jedis jedis = pool.getResource();
|
Jedis jedis = pool.getResource();
|
||||||
@@ -55,7 +55,7 @@ public class JedisPoolTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkPoolRepairedWhenJedisIsBroken() throws Exception {
|
public void checkPoolRepairedWhenJedisIsBroken() {
|
||||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host,
|
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host,
|
||||||
hnp.port);
|
hnp.port);
|
||||||
Jedis jedis = pool.getResource();
|
Jedis jedis = pool.getResource();
|
||||||
@@ -70,7 +70,7 @@ public class JedisPoolTest extends Assert {
|
|||||||
pool.destroy();
|
pool.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisConnectionException.class)
|
||||||
public void checkPoolOverflow() {
|
public void checkPoolOverflow() {
|
||||||
Config config = new Config();
|
Config config = new Config();
|
||||||
config.maxActive = 1;
|
config.maxActive = 1;
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import java.util.Map;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisException;
|
|
||||||
import redis.clients.jedis.JedisShardInfo;
|
import redis.clients.jedis.JedisShardInfo;
|
||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
import redis.clients.jedis.tests.commands.JedisCommandTestBase;
|
import redis.clients.jedis.tests.commands.JedisCommandTestBase;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ public class JedisTest extends JedisCommandTestBase {
|
|||||||
jedis.get("foo");
|
jedis.get("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisConnectionException.class)
|
||||||
public void timeoutConnection() throws Exception {
|
public void timeoutConnection() throws Exception {
|
||||||
jedis = new Jedis("localhost", 6379, 15000);
|
jedis = new Jedis("localhost", 6379, 15000);
|
||||||
jedis.auth("foobared");
|
jedis.auth("foobared");
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package redis.clients.jedis.tests;
|
package redis.clients.jedis.tests;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
@@ -9,8 +8,8 @@ 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.PipelineBlock;
|
|
||||||
import redis.clients.jedis.Pipeline;
|
import redis.clients.jedis.Pipeline;
|
||||||
|
import redis.clients.jedis.PipelineBlock;
|
||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||||
|
|
||||||
@@ -28,7 +27,7 @@ public class PipeliningTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pipeline() throws UnknownHostException, IOException {
|
public void pipeline() throws UnsupportedEncodingException {
|
||||||
List<Object> results = jedis.pipelined(new PipelineBlock() {
|
List<Object> results = jedis.pipelined(new PipelineBlock() {
|
||||||
public void execute() {
|
public void execute() {
|
||||||
set("foo", "bar");
|
set("foo", "bar");
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package redis.clients.jedis.tests;
|
package redis.clients.jedis.tests;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -12,10 +10,10 @@ 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.JedisException;
|
|
||||||
import redis.clients.jedis.JedisShardInfo;
|
import redis.clients.jedis.JedisShardInfo;
|
||||||
import redis.clients.jedis.ShardedJedis;
|
import redis.clients.jedis.ShardedJedis;
|
||||||
import redis.clients.jedis.ShardedJedisPool;
|
import redis.clients.jedis.ShardedJedisPool;
|
||||||
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||||
|
|
||||||
public class ShardedJedisPoolTest extends Assert {
|
public class ShardedJedisPoolTest extends Assert {
|
||||||
@@ -27,7 +25,7 @@ public class ShardedJedisPoolTest extends Assert {
|
|||||||
private List<JedisShardInfo> shards;
|
private List<JedisShardInfo> shards;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void startUp() throws UnknownHostException, IOException {
|
public void startUp() {
|
||||||
shards = new ArrayList<JedisShardInfo>();
|
shards = new ArrayList<JedisShardInfo>();
|
||||||
shards.add(new JedisShardInfo(redis1.host, redis1.port));
|
shards.add(new JedisShardInfo(redis1.host, redis1.port));
|
||||||
shards.add(new JedisShardInfo(redis2.host, redis2.port));
|
shards.add(new JedisShardInfo(redis2.host, redis2.port));
|
||||||
@@ -77,7 +75,7 @@ public class ShardedJedisPoolTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkPoolRepairedWhenJedisIsBroken() throws Exception {
|
public void checkPoolRepairedWhenJedisIsBroken() {
|
||||||
ShardedJedisPool pool = new ShardedJedisPool(new Config(), shards);
|
ShardedJedisPool pool = new ShardedJedisPool(new Config(), shards);
|
||||||
ShardedJedis jedis = pool.getResource();
|
ShardedJedis jedis = pool.getResource();
|
||||||
jedis.disconnect();
|
jedis.disconnect();
|
||||||
@@ -89,7 +87,7 @@ public class ShardedJedisPoolTest extends Assert {
|
|||||||
pool.destroy();
|
pool.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisConnectionException.class)
|
||||||
public void checkPoolOverflow() {
|
public void checkPoolOverflow() {
|
||||||
Config config = new Config();
|
Config config = new Config();
|
||||||
config.maxActive = 1;
|
config.maxActive = 1;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package redis.clients.jedis.tests;
|
package redis.clients.jedis.tests;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@ public class ShardedJedisTest extends Assert {
|
|||||||
.get(1);
|
.get(1);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkSharding() throws IOException {
|
public void checkSharding() {
|
||||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||||
shards.add(new JedisShardInfo(redis1.host, redis1.port));
|
shards.add(new JedisShardInfo(redis1.host, redis1.port));
|
||||||
shards.add(new JedisShardInfo(redis2.host, redis2.port));
|
shards.add(new JedisShardInfo(redis2.host, redis2.port));
|
||||||
@@ -35,7 +34,7 @@ public class ShardedJedisTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void trySharding() throws IOException {
|
public void trySharding() {
|
||||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||||
JedisShardInfo si = new JedisShardInfo(redis1.host, redis1.port);
|
JedisShardInfo si = new JedisShardInfo(redis1.host, redis1.port);
|
||||||
si.setPassword("foobared");
|
si.setPassword("foobared");
|
||||||
@@ -62,7 +61,7 @@ public class ShardedJedisTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tryShardingWithMurmure() throws IOException {
|
public void tryShardingWithMurmure() {
|
||||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||||
JedisShardInfo si = new JedisShardInfo(redis1.host, redis1.port);
|
JedisShardInfo si = new JedisShardInfo(redis1.host, redis1.port);
|
||||||
si.setPassword("foobared");
|
si.setPassword("foobared");
|
||||||
@@ -154,7 +153,7 @@ public class ShardedJedisTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMD5Sharding() throws Exception {
|
public void testMD5Sharding() {
|
||||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
|
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
|
||||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
|
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
|
||||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
|
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
|
||||||
@@ -189,7 +188,7 @@ public class ShardedJedisTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMurmurSharding() throws Exception {
|
public void testMurmurSharding() {
|
||||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
|
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
|
||||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
|
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
|
||||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
|
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.JedisException;
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||||
@@ -205,16 +205,16 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
try {
|
try {
|
||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
jedis.rename("foo", "foo");
|
jedis.rename("foo", "foo");
|
||||||
fail("JedisException expected");
|
fail("JedisDataException expected");
|
||||||
} catch (final JedisException e) {
|
} catch (final JedisDataException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary
|
// Binary
|
||||||
try {
|
try {
|
||||||
jedis.set(bfoo, bbar);
|
jedis.set(bfoo, bbar);
|
||||||
jedis.rename(bfoo, bfoo);
|
jedis.rename(bfoo, bfoo);
|
||||||
fail("JedisException expected");
|
fail("JedisDataException expected");
|
||||||
} catch (final JedisException e) {
|
} catch (final JedisDataException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import java.util.List;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.JedisException;
|
|
||||||
import redis.clients.jedis.Protocol.Keyword;
|
import redis.clients.jedis.Protocol.Keyword;
|
||||||
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
|
|
||||||
public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
||||||
byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
@@ -113,7 +113,7 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertTrue(Arrays.equals(bfoo, jedis.get(bbar)));
|
assertTrue(Arrays.equals(bfoo, jedis.get(bbar)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisDataException.class)
|
||||||
public void incrWrongValue() {
|
public void incrWrongValue() {
|
||||||
jedis.set(bfoo, binaryValue);
|
jedis.set(bfoo, binaryValue);
|
||||||
jedis.incr(bfoo);
|
jedis.incr(bfoo);
|
||||||
@@ -127,7 +127,7 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(2, value);
|
assertEquals(2, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisDataException.class)
|
||||||
public void incrByWrongValue() {
|
public void incrByWrongValue() {
|
||||||
jedis.set(bfoo, binaryValue);
|
jedis.set(bfoo, binaryValue);
|
||||||
jedis.incrBy(bfoo, 2);
|
jedis.incrBy(bfoo, 2);
|
||||||
@@ -141,7 +141,7 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(4, value);
|
assertEquals(4, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisDataException.class)
|
||||||
public void decrWrongValue() {
|
public void decrWrongValue() {
|
||||||
jedis.set(bfoo, binaryValue);
|
jedis.set(bfoo, binaryValue);
|
||||||
jedis.decr(bfoo);
|
jedis.decr(bfoo);
|
||||||
@@ -155,7 +155,7 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(-2, value);
|
assertEquals(-2, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisDataException.class)
|
||||||
public void decrByWrongValue() {
|
public void decrByWrongValue() {
|
||||||
jedis.set(bfoo, binaryValue);
|
jedis.set(bfoo, binaryValue);
|
||||||
jedis.decrBy(bfoo, 2);
|
jedis.decrBy(bfoo, 2);
|
||||||
|
|||||||
@@ -5,93 +5,92 @@ import java.util.List;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.DebugParams;
|
import redis.clients.jedis.DebugParams;
|
||||||
import redis.clients.jedis.JedisException;
|
|
||||||
import redis.clients.jedis.JedisMonitor;
|
import redis.clients.jedis.JedisMonitor;
|
||||||
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
|
|
||||||
public class ControlCommandsTest extends JedisCommandTestBase {
|
public class ControlCommandsTest extends JedisCommandTestBase {
|
||||||
@Test
|
@Test
|
||||||
public void save() {
|
public void save() {
|
||||||
String status = jedis.save();
|
String status = jedis.save();
|
||||||
assertEquals("OK", status);
|
assertEquals("OK", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bgsave() {
|
public void bgsave() {
|
||||||
try {
|
try {
|
||||||
String status = jedis.bgsave();
|
String status = jedis.bgsave();
|
||||||
assertEquals("Background saving started", status);
|
assertEquals("Background saving started", status);
|
||||||
} catch (JedisException e) {
|
} catch (JedisDataException e) {
|
||||||
assertTrue(
|
assertTrue("ERR Background save already in progress"
|
||||||
"ERR Background save already in progress"
|
.equalsIgnoreCase(e.getMessage()));
|
||||||
.equalsIgnoreCase(e.getMessage()));
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bgrewriteaof() {
|
public void bgrewriteaof() {
|
||||||
String status = jedis.bgrewriteaof();
|
String status = jedis.bgrewriteaof();
|
||||||
assertEquals("Background append only file rewriting started", status);
|
assertEquals("Background append only file rewriting started", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lastsave() throws InterruptedException {
|
public void lastsave() throws InterruptedException {
|
||||||
long before = jedis.lastsave();
|
long before = jedis.lastsave();
|
||||||
String st = "";
|
String st = "";
|
||||||
while (!st.equals("OK")) {
|
while (!st.equals("OK")) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
st = jedis.save();
|
st = jedis.save();
|
||||||
} catch (JedisException e) {
|
} catch (JedisDataException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long after = jedis.lastsave();
|
long after = jedis.lastsave();
|
||||||
assertTrue((after - before) > 0);
|
assertTrue((after - before) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void info() {
|
public void info() {
|
||||||
String info = jedis.info();
|
String info = jedis.info();
|
||||||
assertNotNull(info);
|
assertNotNull(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void monitor() {
|
public void monitor() {
|
||||||
jedis.monitor(new JedisMonitor() {
|
jedis.monitor(new JedisMonitor() {
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(String command) {
|
public void onCommand(String command) {
|
||||||
assertTrue(command.contains("OK"));
|
assertTrue(command.contains("OK"));
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void configGet() {
|
public void configGet() {
|
||||||
List<String> info = jedis.configGet("m*");
|
List<String> info = jedis.configGet("m*");
|
||||||
assertNotNull(info);
|
assertNotNull(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void configSet() {
|
public void configSet() {
|
||||||
List<String> info = jedis.configGet("maxmemory");
|
List<String> info = jedis.configGet("maxmemory");
|
||||||
String memory = info.get(1);
|
String memory = info.get(1);
|
||||||
String status = jedis.configSet("maxmemory", "200");
|
String status = jedis.configSet("maxmemory", "200");
|
||||||
assertEquals("OK", status);
|
assertEquals("OK", status);
|
||||||
jedis.configSet("maxmemory", memory);
|
jedis.configSet("maxmemory", memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sync() {
|
public void sync() {
|
||||||
jedis.sync();
|
jedis.sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void debug() {
|
public void debug() {
|
||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
String resp = jedis.debug(DebugParams.OBJECT("foo"));
|
String resp = jedis.debug(DebugParams.OBJECT("foo"));
|
||||||
assertNotNull(resp);
|
assertNotNull(resp);
|
||||||
resp = jedis.debug(DebugParams.RELOAD());
|
resp = jedis.debug(DebugParams.RELOAD());
|
||||||
assertNotNull(resp);
|
assertNotNull(resp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package redis.clients.jedis.tests.commands;
|
package redis.clients.jedis.tests.commands;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -33,11 +31,11 @@ public abstract class JedisCommandTestBase extends JedisTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() {
|
||||||
jedis.disconnect();
|
jedis.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Jedis createJedis() throws UnknownHostException, IOException {
|
protected Jedis createJedis() {
|
||||||
Jedis j = new Jedis(hnp.host, hnp.port);
|
Jedis j = new Jedis(hnp.host, hnp.port);
|
||||||
j.connect();
|
j.connect();
|
||||||
j.auth("foobared");
|
j.auth("foobared");
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package redis.clients.jedis.tests.commands;
|
package redis.clients.jedis.tests.commands;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -10,7 +8,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import redis.clients.jedis.Client;
|
import redis.clients.jedis.Client;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisException;
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
|
|
||||||
public class ListCommandsTest extends JedisCommandTestBase {
|
public class ListCommandsTest extends JedisCommandTestBase {
|
||||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
@@ -76,16 +74,16 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
try {
|
try {
|
||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
jedis.llen("foo");
|
jedis.llen("foo");
|
||||||
fail("JedisException expected");
|
fail("JedisDataException expected");
|
||||||
} catch (final JedisException e) {
|
} catch (final JedisDataException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary
|
// Binary
|
||||||
try {
|
try {
|
||||||
jedis.set(bfoo, bbar);
|
jedis.set(bfoo, bbar);
|
||||||
jedis.llen(bfoo);
|
jedis.llen(bfoo);
|
||||||
fail("JedisException expected");
|
fail("JedisDataException expected");
|
||||||
} catch (final JedisException e) {
|
} catch (final JedisDataException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -592,10 +590,6 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
j.lpush("foo", "a");
|
j.lpush("foo", "a");
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})).start();
|
})).start();
|
||||||
@@ -614,10 +608,6 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
j.lpush("foo", "a");
|
j.lpush("foo", "a");
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})).start();
|
})).start();
|
||||||
|
|||||||
@@ -8,14 +8,13 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import redis.clients.jedis.BinaryJedisPubSub;
|
import redis.clients.jedis.BinaryJedisPubSub;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisException;
|
|
||||||
import redis.clients.jedis.JedisPubSub;
|
import redis.clients.jedis.JedisPubSub;
|
||||||
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||||
@Test
|
@Test
|
||||||
public void subscribe() throws UnknownHostException, IOException,
|
public void subscribe() throws InterruptedException {
|
||||||
InterruptedException {
|
|
||||||
Thread t = new Thread(new Runnable() {
|
Thread t = new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@@ -498,7 +497,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
}, "foo");
|
}, "foo");
|
||||||
} catch (NullPointerException ex) {
|
} catch (NullPointerException ex) {
|
||||||
fail();
|
fail();
|
||||||
} catch (JedisException ex) {
|
} catch (JedisDataException ex) {
|
||||||
// this is OK because we are not sending AUTH command
|
// this is OK because we are not sending AUTH command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.JedisException;
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
|
|
||||||
public class StringValuesCommandsTest extends JedisCommandTestBase {
|
public class StringValuesCommandsTest extends JedisCommandTestBase {
|
||||||
@Test
|
@Test
|
||||||
@@ -95,7 +95,7 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals("foo", jedis.get("bar"));
|
assertEquals("foo", jedis.get("bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisDataException.class)
|
||||||
public void incrWrongValue() {
|
public void incrWrongValue() {
|
||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
jedis.incr("foo");
|
jedis.incr("foo");
|
||||||
@@ -109,7 +109,7 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(2, value);
|
assertEquals(2, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisDataException.class)
|
||||||
public void incrByWrongValue() {
|
public void incrByWrongValue() {
|
||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
jedis.incrBy("foo", 2);
|
jedis.incrBy("foo", 2);
|
||||||
@@ -123,7 +123,7 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(4, value);
|
assertEquals(4, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisDataException.class)
|
||||||
public void decrWrongValue() {
|
public void decrWrongValue() {
|
||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
jedis.decr("foo");
|
jedis.decr("foo");
|
||||||
@@ -137,7 +137,7 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(-2, value);
|
assertEquals(-2, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisDataException.class)
|
||||||
public void decrByWrongValue() {
|
public void decrByWrongValue() {
|
||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
jedis.decrBy("foo", 2);
|
jedis.decrBy("foo", 2);
|
||||||
@@ -184,7 +184,7 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
Integer.MAX_VALUE));
|
Integer.MAX_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisDataException.class)
|
||||||
public void incrReallyLargeNumbers() {
|
public void incrReallyLargeNumbers() {
|
||||||
jedis.set("foo", Long.toString(Long.MAX_VALUE));
|
jedis.set("foo", Long.toString(Long.MAX_VALUE));
|
||||||
long value = jedis.incr("foo");
|
long value = jedis.incr("foo");
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ 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.JedisException;
|
|
||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
import redis.clients.jedis.Transaction;
|
import redis.clients.jedis.Transaction;
|
||||||
import redis.clients.jedis.TransactionBlock;
|
import redis.clients.jedis.TransactionBlock;
|
||||||
import redis.clients.jedis.Protocol.Keyword;
|
import redis.clients.jedis.Protocol.Keyword;
|
||||||
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
|
|
||||||
public class TransactionCommandsTest extends JedisCommandTestBase {
|
public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
@@ -27,7 +27,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
Jedis nj;
|
Jedis nj;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
public void multiBlock() {
|
public void multiBlock() {
|
||||||
List<Object> response = jedis.multi(new TransactionBlock() {
|
List<Object> response = jedis.multi(new TransactionBlock() {
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
String status = sadd("foo", "a");
|
String status = sadd("foo", "a");
|
||||||
assertEquals(Keyword.QUEUED.name(), status);
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
// Binary
|
// Binary
|
||||||
response = jedis.multi(new TransactionBlock() {
|
response = jedis.multi(new TransactionBlock() {
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
String status = sadd(bfoo, ba);
|
String status = sadd(bfoo, ba);
|
||||||
assertEquals(Keyword.QUEUED.name(), status);
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
(byte[]) resp.get(0));
|
(byte[]) resp.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisDataException.class)
|
||||||
public void validateWhenInMulti() {
|
public void validateWhenInMulti() {
|
||||||
jedis.multi();
|
jedis.multi();
|
||||||
jedis.ping();
|
jedis.ping();
|
||||||
|
|||||||
Reference in New Issue
Block a user