@@ -221,12 +221,12 @@ public void testConfirmOffset() throws Exception {
221221 // Step2, shutdown store2
222222 this .messageStore2 .shutdown ();
223223
224- // Put message, which should put failed.
224+ // Put message, which should succeed because slave is removed from syncStateSet, only master remains
225225 final PutMessageResult putMessageResult = this .messageStore1 .putMessage (buildMessage ());
226- assertEquals (putMessageResult .getPutMessageStatus (), PutMessageStatus . FLUSH_SLAVE_TIMEOUT );
226+ assertEquals (PutMessageStatus . PUT_OK , putMessageResult .getPutMessageStatus ());
227227
228- // The confirmOffset still don't change, because syncStateSet contains broker2, but broker2 shutdown
229- assertEquals ( confirmOffset , this .messageStore1 .getConfirmOffset ());
228+ // The confirmOffset should update because syncStateSet only contains master after slave shutdown
229+ assertTrue ( this .messageStore1 .getConfirmOffset () >= confirmOffset );
230230
231231 // Step3, shutdown store1, start store2, change store2 to master, epoch = 2
232232 this .messageStore1 .shutdown ();
@@ -296,10 +296,19 @@ public void testOptionAllAckInSyncStateSet() throws Exception {
296296 this .messageStore2 .shutdown ();
297297 this .messageStore2 .destroy ();
298298
299+ // Wait for connection to be removed and syncStateSet to be updated by removeConnection
300+ await ().atMost (10 , TimeUnit .SECONDS ).until (() -> {
301+ AutoSwitchHAService haService = (AutoSwitchHAService ) this .messageStore1 .getHaService ();
302+ return haService .getConnectionCount ().get () == 0
303+ && haService .getLocalSyncStateSet ().size () == 1 ;
304+ });
305+
306+ // Now manually set syncStateSet back to {1, 2} to test the scenario where
307+ // syncStateSet contains a disconnected slave
299308 ((AutoSwitchHAService ) this .messageStore1 .getHaService ()).setSyncStateSet (result );
300309
301310 final PutMessageResult putMessageResult = this .messageStore1 .putMessage (buildMessage ());
302- assertEquals (putMessageResult .getPutMessageStatus (), PutMessageStatus . FLUSH_SLAVE_TIMEOUT );
311+ assertEquals (PutMessageStatus . FLUSH_SLAVE_TIMEOUT , putMessageResult .getPutMessageStatus ());
303312 }
304313
305314 @ Ignore
0 commit comments