@Test public void shouldNotFailOnUnreachableRedisServer() { redisServer.stop(); RedisBatchAppender redisBatchAppender = new RedisBatchAppender(); redisBatchAppender.setConnectionConfig(getRedisConnectionConfig()); redisBatchAppender.setEncoder(new PatternLayoutEncoderBase<>()); // action redisBatchAppender.start(); }
@Test public void shouldRetryConnectionAfterInterval() throws InterruptedException { RedisCluster cluster = RedisCluster.builder().ephemeral().sentinelCount(3).quorumSize(2) .replicationGroup("master1", 1) .replicationGroup("master2", 1) .replicationGroup("master3", 1) .build(); cluster.start(); Set<String> jedisSentinelHosts = JedisUtil.sentinelHosts(cluster); // simulate cluster outage cluster.stop(); try { RedisConnectionConfig connectionConfig = new RedisConnectionConfig(); connectionConfig.setSentinels(jedisSentinelHosts.stream().collect(joining(","))); connectionConfig.setScheme(RedisConnectionConfig.RedisScheme.SENTINEL); connectionConfig.setSentinelMasterName("master1"); RedisBatchAppender redisBatchAppender = spy(new RedisBatchAppender()); redisBatchAppender.setConnectionConfig(connectionConfig); redisBatchAppender.setEncoder(new PatternLayoutEncoderBase<>()); redisBatchAppender.setRetryInitializeIntervalInSeconds(1); ((Logger) LoggerFactory.getLogger(RedisBatchAppender.class)).setLevel(Level.OFF); // action, should fail redisBatchAppender.start(); // restart cluster cluster.start(); TimeUnit.SECONDS.sleep(2); assertThat("should succeed one time",redisBatchAppender.getConnectionStartupCounter() == 1); redisBatchAppender.stop(); } finally { if (cluster.isActive()) { cluster.stop(); } } }