diff --git a/src/test/java/redis/clients/jedis/scenario/ActiveActiveFailoverIT.java b/src/test/java/redis/clients/jedis/scenario/ActiveActiveFailoverIT.java index 798728bfbc..5025627d7b 100644 --- a/src/test/java/redis/clients/jedis/scenario/ActiveActiveFailoverIT.java +++ b/src/test/java/redis/clients/jedis/scenario/ActiveActiveFailoverIT.java @@ -120,6 +120,7 @@ public void accept(DatabaseSwitchEvent e) { AtomicLong retryingThreadsCounter = new AtomicLong(0); AtomicLong failedCommandsAfterFailover = new AtomicLong(0); AtomicReference lastFailedCommandAt = new AtomicReference<>(); + Endpoint primaryEndpoint = client.getActiveDatabaseEndpoint(); // Start thread that imitates an application that uses the client MultiThreadedFakeApp fakeApp = new MultiThreadedFakeApp(client, (UnifiedJedis c) -> { @@ -130,6 +131,7 @@ public void accept(DatabaseSwitchEvent e) { int maxTries = 500; int retryingDelay = 5; while (true) { + boolean attemptToExecuteOnFailedCluster = true; try { Map executionInfo = new HashMap() { { @@ -137,6 +139,7 @@ public void accept(DatabaseSwitchEvent e) { put("cluster", reporter.getCurrentClusterName()); } }; + attemptToExecuteOnFailedCluster = client.getActiveDatabaseEndpoint() == primaryEndpoint; client.xadd("execution_log", StreamEntryID.NEW_ENTRY, executionInfo); executedCommands.incrementAndGet(); @@ -148,7 +151,8 @@ public void accept(DatabaseSwitchEvent e) { break; } catch (JedisConnectionException e) { - if (reporter.failoverHappened) { + if (reporter.failoverHappened && !reporter.failbackHappened + && attemptToExecuteOnFailedCluster) { failedCommandsAfterFailover.incrementAndGet(); lastFailedCommandAt.set(Instant.now()); } @@ -219,9 +223,12 @@ public void accept(DatabaseSwitchEvent e) { log.info("Failback happened at: {}", reporter.failbackAt); log.info("Last failed command at: {}", lastFailedCommandAt.get()); log.info("Failed commands after failover: {}", failedCommandsAfterFailover.get()); - Duration fullFailoverTime = Duration.between(reporter.failoverAt, lastFailedCommandAt.get()); - log.info("Full failover time: {} s", fullFailoverTime.getSeconds()); - + if (lastFailedCommandAt.get() == null) { + log.info("No failed commands after failover!"); + } else { + Duration fullFailoverTime = Duration.between(reporter.failoverAt, lastFailedCommandAt.get()); + log.info("Full failover time: {} s", fullFailoverTime.getSeconds()); + } assertEquals(0, pool1.getNumActive()); assertTrue(fakeApp.capturedExceptions().isEmpty()); assertTrue(reporter.failoverHappened);