Skip to content

Commit

Permalink
Merge dc1cc67 into 70f7ea8
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 authored Jun 3, 2023
2 parents 70f7ea8 + dc1cc67 commit fd54290
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

public class ClusterConnectionProvider implements ConnectionProvider {

private static final String INIT_NO_ERROR_PROPERTY = "jedis.cluster.initNoError";

protected final JedisClusterInfoCache cache;

public ClusterConnectionProvider(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig) {
Expand Down Expand Up @@ -53,6 +55,9 @@ private void initializeSlotsCache(Set<HostAndPort> startNodes, JedisClientConfig
}
}

if (System.getProperty(INIT_NO_ERROR_PROPERTY) != null) {
return;
}
JedisClusterOperationException uninitializedException
= new JedisClusterOperationException("Could not initialize cluster slots cache.");
uninitializedException.addSuppressed(firstException);
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/redis/clients/jedis/misc/ClusterInitErrorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package redis.clients.jedis.misc;

import java.util.Collections;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import redis.clients.jedis.DefaultJedisClientConfig;
import redis.clients.jedis.HostAndPorts;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.exceptions.JedisClusterOperationException;

public class ClusterInitErrorTest {

private static final String INIT_NO_ERROR_PROPERTY = "jedis.cluster.initNoError";

@After
public void cleanUp() {
System.getProperties().remove(INIT_NO_ERROR_PROPERTY);
}

@Test(expected = JedisClusterOperationException.class)
public void initError() {
Assert.assertNull(System.getProperty(INIT_NO_ERROR_PROPERTY));
try (JedisCluster cluster = new JedisCluster(
Collections.singleton(HostAndPorts.getRedisServers().get(0)),
DefaultJedisClientConfig.builder().password("foobared").build())) {
throw new IllegalStateException("should not reach here");
}
}

@Test
public void initNoError() {
System.setProperty(INIT_NO_ERROR_PROPERTY, "");
try (JedisCluster cluster = new JedisCluster(
Collections.singleton(HostAndPorts.getRedisServers().get(0)),
DefaultJedisClientConfig.builder().password("foobared").build())) {
Assert.assertThrows(JedisClusterOperationException.class, () -> cluster.get("foo"));
}
}
}

0 comments on commit fd54290

Please sign in to comment.