@@ -120,6 +120,7 @@ public void accept(DatabaseSwitchEvent e) {
120120AtomicLong retryingThreadsCounter =new AtomicLong (0 );
121121AtomicLong failedCommandsAfterFailover =new AtomicLong (0 );
122122AtomicReference <Instant >lastFailedCommandAt =new AtomicReference <>();
123+ Endpoint primaryEndpoint =client .getActiveDatabaseEndpoint ();
123124
124125// Start thread that imitates an application that uses the client
125126MultiThreadedFakeApp fakeApp =new MultiThreadedFakeApp (client , (UnifiedJedis c ) -> {
@@ -130,13 +131,15 @@ public void accept(DatabaseSwitchEvent e) {
130131int maxTries =500 ;
131132int retryingDelay =5 ;
132133while (true ) {
134+ boolean attemptToExecuteOnFailedCluster =true ;
133135try {
134136Map <String ,String >executionInfo =new HashMap <String ,String >() {
135137 {
136138put ("threadId" ,String .valueOf (threadId ));
137139put ("cluster" ,reporter .getCurrentClusterName ());
138140 }
139141 };
142+ attemptToExecuteOnFailedCluster =client .getActiveDatabaseEndpoint () ==primaryEndpoint ;
140143client .xadd ("execution_log" ,StreamEntryID .NEW_ENTRY ,executionInfo );
141144executedCommands .incrementAndGet ();
142145
@@ -148,7 +151,8 @@ public void accept(DatabaseSwitchEvent e) {
148151break ;
149152 }catch (JedisConnectionException e ) {
150153
151- if (reporter .failoverHappened ) {
154+ if (reporter .failoverHappened && !reporter .failbackHappened
155+ &&attemptToExecuteOnFailedCluster ) {
152156failedCommandsAfterFailover .incrementAndGet ();
153157lastFailedCommandAt .set (Instant .now ());
154158 }
@@ -219,9 +223,12 @@ public void accept(DatabaseSwitchEvent e) {
219223log .info ("Failback happened at: {}" ,reporter .failbackAt );
220224log .info ("Last failed command at: {}" ,lastFailedCommandAt .get ());
221225log .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+ }
225232assertEquals (0 ,pool1 .getNumActive ());
226233assertTrue (fakeApp .capturedExceptions ().isEmpty ());
227234assertTrue (reporter .failoverHappened );