Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw exception if JedisCluster cannot connect to any host-port #2721

Merged
merged 6 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ private void initializeSlotsCache(Set<HostAndPort> startNodes, JedisClientConfig
// try next nodes
}
}

throw new JedisClusterOperationException("Could not initialize cluster slots cache.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package redis.clients.jedis;

import org.junit.Test;

import redis.clients.jedis.exceptions.JedisClusterOperationException;

public class JedisClusterWithoutSetupTest {

@Test(expected = JedisClusterOperationException.class)
public void uselessStartNodes() {
new JedisCluster(new HostAndPort("localhost", 7378));
}
}
27 changes: 15 additions & 12 deletions src/test/java/redis/clients/jedis/SSLACLJedisClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,12 @@ public void connectByIpAddressFailsWithSSLParameters() {
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) {
// 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("No reachable node in cluster.", e.getMessage());
assertEquals("Could not initialize cluster slots cache.", e.getMessage());
}
}

Expand All @@ -169,13 +170,14 @@ public void connectWithCustomHostNameVerifier() {
DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true)
.hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build(),
DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
jc2.get("key");
Assert.fail("There should be no reachable node in cluster.");
// } catch (JedisNoReachableClusterNodeException e) {
// jc2.get("key");
// 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("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),
Expand Down Expand Up @@ -205,11 +207,12 @@ public void connectWithEmptyTrustStore() throws Exception {
try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379),
DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true)
.sslSocketFactory(sslSocketFactory).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
jc.get("key");
Assert.fail("There should be no reachable node in cluster.");
// } catch (JedisNoReachableClusterNodeException e) {
// 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("No reachable node in cluster.", e.getMessage());
assertEquals("Could not initialize cluster slots cache.", e.getMessage());
}
}

Expand Down
27 changes: 15 additions & 12 deletions src/test/java/redis/clients/jedis/SSLJedisClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ public void connectByIpAddressFailsWithSSLParameters() {
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) {
// 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("No reachable node in cluster.", e.getMessage());
assertEquals("Could not initialize cluster slots cache.", e.getMessage());
}
}

Expand All @@ -168,13 +169,14 @@ public void connectWithCustomHostNameVerifier() {
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) {
// 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("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),
Expand Down Expand Up @@ -204,11 +206,12 @@ public void connectWithEmptyTrustStore() throws Exception {
try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379),
DefaultJedisClientConfig.builder().password("cluster").ssl(true)
.sslSocketFactory(sslSocketFactory).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
jc.get("key");
Assert.fail("There should be no reachable node in cluster.");
// } catch (JedisNoReachableClusterNodeException e) {
// 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("No reachable node in cluster.", e.getMessage());
assertEquals("Could not initialize cluster slots cache.", e.getMessage());
}
}

Expand Down