use of redis.clients.jedis.exceptions.JedisConnectionException in project jedis by xetorthio.
the class SSLJedisTest method connectWithShardInfoAndCustomHostnameVerifierByIpAddress.
/**
* Tests opening an SSL/TLS connection to redis with a custom hostname
* verifier. This test should fail because "127.0.0.1" does not match the
* certificate subject common name and there are no subject alternative names
* in the certificate.
*/
@Test
public void connectWithShardInfoAndCustomHostnameVerifierByIpAddress() {
final URI uri = URI.create("rediss://127.0.0.1:6390");
final SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
final SSLParameters sslParameters = new SSLParameters();
HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, hostnameVerifier);
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("The JedisConnectionException does not contain the expected message.", "The connection to '127.0.0.1' failed ssl/tls hostname verification.", e.getMessage());
}
try {
jedis.close();
} catch (Throwable e1) {
// Expected.
}
}
use of redis.clients.jedis.exceptions.JedisConnectionException in project jedis by xetorthio.
the class ScriptingCommandsTest method scriptExistsWithBrokenConnection.
@Test
public void scriptExistsWithBrokenConnection() {
Jedis deadClient = new Jedis(jedis.getClient().getHost(), jedis.getClient().getPort());
deadClient.auth("foobared");
deadClient.clientSetname("DEAD");
ClientKillerUtil.killClient(deadClient, "DEAD");
// sure, script doesn't exist, but it's just for checking connection
try {
deadClient.scriptExists("abcdefg");
} catch (JedisConnectionException e) {
// ignore it
}
assertEquals(true, deadClient.getClient().isBroken());
deadClient.close();
}
use of redis.clients.jedis.exceptions.JedisConnectionException in project cachecloud by sohutv.
the class RedisInputStream method ensureFill.
/**
* This methods assumes there are required bytes to be read. If we cannot read anymore bytes an
* exception is thrown to quickly ascertain that the stream was smaller than expected.
*/
private void ensureFill() throws JedisConnectionException {
if (count >= limit) {
try {
limit = in.read(buf);
count = 0;
if (limit == -1) {
throw new JedisConnectionException("Unexpected end of stream.");
}
} catch (IOException e) {
throw new JedisConnectionException(e);
}
}
}
use of redis.clients.jedis.exceptions.JedisConnectionException in project cachecloud by sohutv.
the class Connection method disconnect.
public void disconnect() {
if (isConnected()) {
try {
outputStream.flush();
socket.close();
} catch (IOException ex) {
UsefulDataCollector.collectException(ex, getHostPort(), System.currentTimeMillis());
broken = true;
throw new JedisConnectionException(ex);
} finally {
IOUtils.closeQuietly(socket);
}
}
}
use of redis.clients.jedis.exceptions.JedisConnectionException in project cachecloud by sohutv.
the class Connection method readProtocolWithCheckingBroken.
protected Object readProtocolWithCheckingBroken() {
Object o = null;
try {
o = Protocol.read(inputStream);
return o;
} catch (JedisConnectionException exc) {
UsefulDataCollector.collectException(exc, getHostPort(), System.currentTimeMillis());
broken = true;
throw exc;
} finally {
UsefulDataModel costModel = UsefulDataModel.getCostModel(threadLocal);
costModel.setHostPort(getHostPort());
costModel.setEndTime(System.currentTimeMillis());
// 1.上报command + cost给指定
if (o != null) {
if (o instanceof byte[]) {
byte[] bytes = (byte[]) o;
// 2.上报字节大小
costModel.setValueBytesLength(bytes.length);
}
}
// 清除threadLocal
threadLocal.remove();
// 排除掉subscribe问题
if (costModel.getCommand() != null) {
UsefulDataCollector.collectCostAndValueDistribute(costModel);
}
}
}
Aggregations