Search in sources :

Example 1 with JedisClusterOperationException

use of redis.clients.jedis.exceptions.JedisClusterOperationException in project jedis by xetorthio.

the class SSLACLJedisClusterTest method connectToNodesFailsWithSSLParametersAndNoHostMapping.

@Test
public void connectToNodesFailsWithSSLParametersAndNoHostMapping() {
    final SSLParameters sslParameters = new SSLParameters();
    sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
    try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true).sslParameters(sslParameters).hostAndPortMapper(portMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
        jc.get("foo");
        Assert.fail("It should fail after all cluster attempts.");
    // } catch (JedisClusterMaxAttemptsException e) {
    } catch (JedisClusterOperationException e) {
        // initial connection to localhost works, but subsequent connections to nodes use 127.0.0.1
        // and fail hostname verification
        assertEquals("No more cluster attempts left.", e.getMessage());
    }
}
Also used : JedisClusterOperationException(redis.clients.jedis.exceptions.JedisClusterOperationException) SSLParameters(javax.net.ssl.SSLParameters) Test(org.junit.Test)

Example 2 with JedisClusterOperationException

use of redis.clients.jedis.exceptions.JedisClusterOperationException in project jedis by xetorthio.

the class SSLACLJedisClusterTest method connectByIpAddressFailsWithSSLParameters.

@Test
public void connectByIpAddressFailsWithSSLParameters() {
    final SSLParameters sslParameters = new SSLParameters();
    sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
    try (JedisCluster jc = new JedisCluster(new HostAndPort("127.0.0.1", 8379), DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true).sslParameters(sslParameters).hostAndPortMapper(hostAndPortMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
    // jc.get("key");
    // Assert.fail("There should be no reachable node in cluster.");
    // //    } catch (JedisNoReachableClusterNodeException e) {
    } catch (JedisClusterOperationException e) {
        // assertEquals("No reachable node in cluster.", e.getMessage());
        assertEquals("Could not initialize cluster slots cache.", e.getMessage());
    }
}
Also used : JedisClusterOperationException(redis.clients.jedis.exceptions.JedisClusterOperationException) SSLParameters(javax.net.ssl.SSLParameters) Test(org.junit.Test)

Example 3 with JedisClusterOperationException

use of redis.clients.jedis.exceptions.JedisClusterOperationException in project jedis by xetorthio.

the class SSLJedisClusterTest method connectWithCustomHostNameVerifier.

@Test
public void connectWithCustomHostNameVerifier() {
    HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
    HostnameVerifier localhostVerifier = new LocalhostVerifier();
    try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), DefaultJedisClientConfig.builder().password("cluster").ssl(true).hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
        jc.get("foo");
        Assert.fail("It should fail after all cluster attempts.");
    // } catch (JedisClusterMaxAttemptsException e) {
    } catch (JedisClusterOperationException e) {
        // initial connection made with 'localhost' but subsequent connections to nodes use 127.0.0.1
        // which causes custom hostname verification to fail
        assertEquals("No more cluster attempts left.", e.getMessage());
    }
    try (JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 8379), DefaultJedisClientConfig.builder().password("cluster").ssl(true).hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
    // jc2.get("foo");
    // Assert.fail("There should be no reachable node in cluster.");
    // //    } catch (JedisNoReachableClusterNodeException e) {
    } catch (JedisClusterOperationException e) {
        // JedisNoReachableClusterNodeException exception occurs from not being able to connect
        // since the socket factory fails the hostname verification
        // assertEquals("No reachable node in cluster.", e.getMessage());
        assertEquals("Could not initialize cluster slots cache.", e.getMessage());
    }
    try (JedisCluster jc3 = new JedisCluster(new HostAndPort("localhost", 8379), DefaultJedisClientConfig.builder().password("cluster").ssl(true).hostnameVerifier(localhostVerifier).hostAndPortMapper(portMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
        jc3.get("foo");
    }
}
Also used : JedisClusterOperationException(redis.clients.jedis.exceptions.JedisClusterOperationException) BasicHostnameVerifier(redis.clients.jedis.SSLJedisTest.BasicHostnameVerifier) HostnameVerifier(javax.net.ssl.HostnameVerifier) BasicHostnameVerifier(redis.clients.jedis.SSLJedisTest.BasicHostnameVerifier) Test(org.junit.Test)

Example 4 with JedisClusterOperationException

use of redis.clients.jedis.exceptions.JedisClusterOperationException in project jedis by xetorthio.

the class SSLJedisClusterTest method connectToNodesFailsWithSSLParametersAndNoHostMapping.

@Test
public void connectToNodesFailsWithSSLParametersAndNoHostMapping() {
    final SSLParameters sslParameters = new SSLParameters();
    sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
    try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), DefaultJedisClientConfig.builder().password("cluster").ssl(true).sslParameters(sslParameters).hostAndPortMapper(portMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
        jc.get("foo");
        Assert.fail("It should fail after all cluster attempts.");
    // } catch (JedisClusterMaxAttemptsException e) {
    } catch (JedisClusterOperationException e) {
        // initial connection to localhost works, but subsequent connections to nodes use 127.0.0.1
        // and fail hostname verification
        assertEquals("No more cluster attempts left.", e.getMessage());
    }
}
Also used : JedisClusterOperationException(redis.clients.jedis.exceptions.JedisClusterOperationException) SSLParameters(javax.net.ssl.SSLParameters) Test(org.junit.Test)

Example 5 with JedisClusterOperationException

use of redis.clients.jedis.exceptions.JedisClusterOperationException in project jedis by xetorthio.

the class SSLJedisClusterTest method connectByIpAddressFailsWithSSLParameters.

@Test
public void connectByIpAddressFailsWithSSLParameters() {
    final SSLParameters sslParameters = new SSLParameters();
    sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
    try (JedisCluster jc = new JedisCluster(new HostAndPort("127.0.0.1", 8379), DefaultJedisClientConfig.builder().password("cluster").ssl(true).sslParameters(sslParameters).hostAndPortMapper(hostAndPortMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
    // jc.get("key");
    // Assert.fail("There should be no reachable node in cluster.");
    // //    } catch (JedisNoReachableClusterNodeException e) {
    } catch (JedisClusterOperationException e) {
        // assertEquals("No reachable node in cluster.", e.getMessage());
        assertEquals("Could not initialize cluster slots cache.", e.getMessage());
    }
}
Also used : JedisClusterOperationException(redis.clients.jedis.exceptions.JedisClusterOperationException) SSLParameters(javax.net.ssl.SSLParameters) Test(org.junit.Test)

Aggregations

JedisClusterOperationException (redis.clients.jedis.exceptions.JedisClusterOperationException)8 Test (org.junit.Test)6 SSLParameters (javax.net.ssl.SSLParameters)4 HostnameVerifier (javax.net.ssl.HostnameVerifier)2 Connection (redis.clients.jedis.Connection)2 BasicHostnameVerifier (redis.clients.jedis.SSLJedisTest.BasicHostnameVerifier)2 ArrayList (java.util.ArrayList)1 ConnectionPool (redis.clients.jedis.ConnectionPool)1 HostAndPort (redis.clients.jedis.HostAndPort)1 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)1 JedisException (redis.clients.jedis.exceptions.JedisException)1