@@ -83,18 +83,18 @@ void testCoordinatorServerElection() throws Exception {
8383 CoordinatorAddress firstLeaderAddress = zookeeperClient .getCoordinatorLeaderAddress ().get ();
8484
8585 // Find the leader and try to restart it.
86- CoordinatorServer elected = null ;
86+ CoordinatorServer firstLeader = null ;
8787 for (CoordinatorServer coordinatorServer : coordinatorServerList ) {
8888 if (coordinatorServer .getServerId () == firstLeaderAddress .getId ()) {
89- elected = coordinatorServer ;
89+ firstLeader = coordinatorServer ;
9090 break ;
9191 }
9292 }
93- assertThat (elected ).isNotNull ();
93+ assertThat (firstLeader ).isNotNull ();
9494 assertThat (zookeeperClient .getCurrentEpoch ().getCoordinatorEpoch ())
9595 .isEqualTo (CoordinatorContext .INITIAL_COORDINATOR_EPOCH );
96- elected .close ();
97- elected .start ();
96+ firstLeader .close ();
97+ firstLeader .start ();
9898
9999 // Then we should get another Coordinator server leader elected
100100 waitUntilCoordinatorServerReelected (firstLeaderAddress );
@@ -104,12 +104,25 @@ void testCoordinatorServerElection() throws Exception {
104104 assertThat (zookeeperClient .getCurrentEpoch ().getCoordinatorEpoch ())
105105 .isEqualTo (CoordinatorContext .INITIAL_COORDINATOR_EPOCH + 1 );
106106
107- // kill other 2 coordinator servers except the first one
107+ CoordinatorServer secondLeader = null ;
108+ for (CoordinatorServer coordinatorServer : coordinatorServerList ) {
109+ if (coordinatorServer .getServerId () == secondLeaderAddress .getId ()) {
110+ secondLeader = coordinatorServer ;
111+ break ;
112+ }
113+ }
114+ CoordinatorServer nonLeader = null ;
108115 for (CoordinatorServer coordinatorServer : coordinatorServerList ) {
109- if (coordinatorServer .getServerId () != firstLeaderAddress .getId ()) {
110- coordinatorServer .close ();
116+ if (coordinatorServer .getServerId () != firstLeaderAddress .getId ()
117+ && coordinatorServer .getServerId () != secondLeaderAddress .getId ()) {
118+ nonLeader = coordinatorServer ;
119+ break ;
111120 }
112121 }
122+ // kill other 2 coordinator servers except the first one
123+ nonLeader .close ();
124+ secondLeader .close ();
125+
113126 // the origin coordinator server should become leader again
114127 waitUntilCoordinatorServerReelected (secondLeaderAddress );
115128 CoordinatorAddress thirdLeaderAddress = zookeeperClient .getCoordinatorLeaderAddress ().get ();
0 commit comments