use of redis.clients.jedis.exceptions.JedisConnectionException in project jedis by xetorthio.
the class SSLJedisTest method connectWithShardInfoAndEmptyTrustStore.
/**
* Tests opening an SSL/TLS connection to redis with an empty certificate
* trust store. This test should fail because there is no trust anchor for the
* redis server certificate.
*
* @throws Exception
*/
@Test
public void connectWithShardInfoAndEmptyTrustStore() throws Exception {
final URI uri = URI.create("rediss://localhost:6390");
final SSLSocketFactory sslSocketFactory = createTrustNoOneSslSocketFactory();
JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, null, null);
shardInfo.setPassword("foobared");
Jedis jedis = new Jedis(shardInfo);
try {
jedis.get("foo");
Assert.fail("The code did not throw the expected JedisConnectionException.");
} catch (JedisConnectionException e) {
Assert.assertEquals("Unexpected first inner exception.", SSLException.class, e.getCause().getClass());
Assert.assertEquals("Unexpected second inner exception.", RuntimeException.class, e.getCause().getCause().getClass());
Assert.assertEquals("Unexpected third inner exception.", InvalidAlgorithmParameterException.class, e.getCause().getCause().getCause().getClass());
}
try {
jedis.close();
} catch (Throwable e1) {
// Expected.
}
}
use of redis.clients.jedis.exceptions.JedisConnectionException in project jedis by xetorthio.
the class JedisSentinelPoolTest method returnResourceShouldResetState.
@Test
public void returnResourceShouldResetState() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000, "foobared", 2);
Jedis jedis = pool.getResource();
Jedis jedis2 = null;
try {
jedis.set("hello", "jedis");
Transaction t = jedis.multi();
t.set("hello", "world");
jedis.close();
jedis2 = pool.getResource();
assertTrue(jedis == jedis2);
assertEquals("jedis", jedis2.get("hello"));
} catch (JedisConnectionException e) {
if (jedis2 != null) {
jedis2 = null;
}
} finally {
jedis2.close();
pool.destroy();
}
}
use of redis.clients.jedis.exceptions.JedisConnectionException in project jedis by xetorthio.
the class Protocol method processBulkReply.
private static byte[] processBulkReply(final RedisInputStream is) {
final int len = is.readIntCrLf();
if (len == -1) {
return null;
}
final byte[] read = new byte[len];
int offset = 0;
while (offset < len) {
final int size = is.read(read, offset, (len - offset));
if (size == -1)
throw new JedisConnectionException("It seems like server has closed the connection.");
offset += size;
}
// read 2 more bytes for the command delimiter
is.readByte();
is.readByte();
return read;
}
use of redis.clients.jedis.exceptions.JedisConnectionException in project jedis by xetorthio.
the class Protocol method sendCommand.
private static void sendCommand(final RedisOutputStream os, final byte[] command, final byte[]... args) {
try {
os.write(ASTERISK_BYTE);
os.writeIntCrLf(args.length + 1);
os.write(DOLLAR_BYTE);
os.writeIntCrLf(command.length);
os.write(command);
os.writeCrLf();
for (final byte[] arg : args) {
os.write(DOLLAR_BYTE);
os.writeIntCrLf(arg.length);
os.write(arg);
os.writeCrLf();
}
} catch (IOException e) {
throw new JedisConnectionException(e);
}
}
use of redis.clients.jedis.exceptions.JedisConnectionException in project leopard by tanhaichao.
the class JedisPool method getResource.
@Override
public Jedis getResource() {
long startTime = System.nanoTime();
Jedis resource = null;
try {
resource = super.getResource();
} catch (JedisConnectionException e) {
if (redisConnectionListener != null) {
redisConnectionListener.broken();
}
throw e;
} finally {
if (redisConnectionListener != null) {
redisConnectionListener.open(resource, startTime);
}
}
return resource;
}
Aggregations