Skip to content

Commit aa7fee1

Browse files
authored
[automatic failover] Fix misleading timing information for AA scenario test (#4303)
1 parent 840eb9e commit aa7fee1

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/test/java/redis/clients/jedis/scenario/ActiveActiveFailoverIT.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public void accept(DatabaseSwitchEvent e) {
120120
AtomicLong retryingThreadsCounter = new AtomicLong(0);
121121
AtomicLong failedCommandsAfterFailover = new AtomicLong(0);
122122
AtomicReference<Instant> lastFailedCommandAt = new AtomicReference<>();
123+
Endpoint primaryEndpoint = client.getActiveDatabaseEndpoint();
123124

124125
// Start thread that imitates an application that uses the client
125126
MultiThreadedFakeApp fakeApp = new MultiThreadedFakeApp(client, (UnifiedJedis c) -> {
@@ -130,13 +131,15 @@ public void accept(DatabaseSwitchEvent e) {
130131
int maxTries = 500;
131132
int retryingDelay = 5;
132133
while (true) {
134+
boolean attemptToExecuteOnFailedCluster = true;
133135
try {
134136
Map<String, String> executionInfo = new HashMap<String, String>() {
135137
{
136138
put("threadId", String.valueOf(threadId));
137139
put("cluster", reporter.getCurrentClusterName());
138140
}
139141
};
142+
attemptToExecuteOnFailedCluster = client.getActiveDatabaseEndpoint() == primaryEndpoint;
140143
client.xadd("execution_log", StreamEntryID.NEW_ENTRY, executionInfo);
141144
executedCommands.incrementAndGet();
142145

@@ -148,7 +151,8 @@ public void accept(DatabaseSwitchEvent e) {
148151
break;
149152
} catch (JedisConnectionException e) {
150153

151-
if (reporter.failoverHappened) {
154+
if (reporter.failoverHappened && !reporter.failbackHappened
155+
&& attemptToExecuteOnFailedCluster) {
152156
failedCommandsAfterFailover.incrementAndGet();
153157
lastFailedCommandAt.set(Instant.now());
154158
}
@@ -219,9 +223,12 @@ public void accept(DatabaseSwitchEvent e) {
219223
log.info("Failback happened at: {}", reporter.failbackAt);
220224
log.info("Last failed command at: {}", lastFailedCommandAt.get());
221225
log.info("Failed commands after failover: {}", failedCommandsAfterFailover.get());
222-
Duration fullFailoverTime = Duration.between(reporter.failoverAt, lastFailedCommandAt.get());
223-
log.info("Full failover time: {} s", fullFailoverTime.getSeconds());
224-
226+
if (lastFailedCommandAt.get() == null) {
227+
log.info("No failed commands after failover!");
228+
} else {
229+
Duration fullFailoverTime = Duration.between(reporter.failoverAt, lastFailedCommandAt.get());
230+
log.info("Full failover time: {} s", fullFailoverTime.getSeconds());
231+
}
225232
assertEquals(0, pool1.getNumActive());
226233
assertTrue(fakeApp.capturedExceptions().isEmpty());
227234
assertTrue(reporter.failoverHappened);

0 commit comments

Comments
 (0)