-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option to ignore cluster init error (#3455)
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/test/java/redis/clients/jedis/misc/ClusterInitErrorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} | ||
} |