Search in sources :

Example 11 with JedisConnectionException

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.
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) SSLParameters(javax.net.ssl.SSLParameters) JedisShardInfo(redis.clients.jedis.JedisShardInfo) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) URI(java.net.URI) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) HostnameVerifier(javax.net.ssl.HostnameVerifier) Test(org.junit.Test)

Example 12 with JedisConnectionException

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();
}
Also used : BinaryJedis(redis.clients.jedis.BinaryJedis) Jedis(redis.clients.jedis.Jedis) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Test(org.junit.Test)

Example 13 with JedisConnectionException

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);
        }
    }
}
Also used : JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException)

Example 14 with JedisConnectionException

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);
        }
    }
}
Also used : IOException(java.io.IOException) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException)

Example 15 with JedisConnectionException

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);
        }
    }
}
Also used : UsefulDataModel(com.sohu.tv.jedis.stat.model.UsefulDataModel) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException)

Aggregations

JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)35 Jedis (redis.clients.jedis.Jedis)15 IOException (java.io.IOException)8 Logger (org.apache.log4j.Logger)8 Test (org.junit.Test)7 JedisDataException (redis.clients.jedis.exceptions.JedisDataException)5 URI (java.net.URI)3 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)3 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)3 JedisShardInfo (redis.clients.jedis.JedisShardInfo)3 UsefulDataModel (com.sohu.tv.jedis.stat.model.UsefulDataModel)2 InetSocketAddress (java.net.InetSocketAddress)2 Socket (java.net.Socket)2 SSLParameters (javax.net.ssl.SSLParameters)2 BinaryJedis (redis.clients.jedis.BinaryJedis)2 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)2 Transaction (redis.clients.jedis.Transaction)2 RedisInputStream (redis.clients.util.RedisInputStream)2 RedisOutputStream (redis.clients.util.RedisOutputStream)2 ServerInfo (beans.dbaccess.ServerInfo)1