|
| 1 | +package redis.clients.jedis.misc; |
| 2 | + |
| 3 | +import java.util.Collections; |
| 4 | +import org.junit.After; |
| 5 | +import org.junit.Assert; |
| 6 | +import org.junit.Test; |
| 7 | +import redis.clients.jedis.DefaultJedisClientConfig; |
| 8 | +import redis.clients.jedis.HostAndPorts; |
| 9 | +import redis.clients.jedis.JedisCluster; |
| 10 | +import redis.clients.jedis.exceptions.JedisClusterOperationException; |
| 11 | + |
| 12 | +public class ClusterInitErrorTest { |
| 13 | + |
| 14 | + private static final String INIT_NO_ERROR_PROPERTY = "jedis.cluster.initNoError"; |
| 15 | + |
| 16 | + @After |
| 17 | + public void cleanUp() { |
| 18 | + System.getProperties().remove(INIT_NO_ERROR_PROPERTY); |
| 19 | + } |
| 20 | + |
| 21 | + @Test(expected = JedisClusterOperationException.class) |
| 22 | + public void initError() { |
| 23 | + Assert.assertNull(System.getProperty(INIT_NO_ERROR_PROPERTY)); |
| 24 | + try (JedisCluster cluster = new JedisCluster( |
| 25 | + Collections.singleton(HostAndPorts.getRedisServers().get(0)), |
| 26 | + DefaultJedisClientConfig.builder().password("foobared").build())) { |
| 27 | + throw new IllegalStateException("should not reach here"); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void initNoError() { |
| 33 | + System.setProperty(INIT_NO_ERROR_PROPERTY, ""); |
| 34 | + try (JedisCluster cluster = new JedisCluster( |
| 35 | + Collections.singleton(HostAndPorts.getRedisServers().get(0)), |
| 36 | + DefaultJedisClientConfig.builder().password("foobared").build())) { |
| 37 | + Assert.assertThrows(JedisClusterOperationException.class, () -> cluster.get("foo")); |
| 38 | + } |
| 39 | + } |
| 40 | +} |
0 commit comments