@@ -279,6 +279,25 @@ public void testJoinAccumulation() {
279279 FutureUtils .get (fut );
280280 }
281281
282+ public void testJoinFollowerWithHigherTerm () {
283+ DiscoveryNode node0 = newNode (0 , true );
284+ DiscoveryNode node1 = newNode (1 , true );
285+ long initialTerm = randomLongBetween (1 , 10 );
286+ long initialVersion = randomLongBetween (1 , 10 );
287+ setupFakeMasterServiceAndCoordinator (initialTerm , initialState (false , node0 , initialTerm , initialVersion ,
288+ new VotingConfiguration (Collections .singleton (node0 .getId ()))));
289+ long newTerm = initialTerm + randomLongBetween (1 , 10 );
290+ coordinator .coordinationState .get ().handleStartJoin (new StartJoinRequest (node1 , newTerm ));
291+ synchronized (coordinator .mutex ) {
292+ coordinator .becomeFollower ("test" , node1 );
293+ }
294+ assertFalse (isLocalNodeElectedMaster ());
295+ long newerTerm = newTerm + randomLongBetween (1 , 10 );
296+ joinNodeAndRun (new JoinRequest (node1 ,
297+ Optional .of (new Join (node1 , node0 , newerTerm , initialTerm , initialVersion ))));
298+ assertTrue (isLocalNodeElectedMaster ());
299+ }
300+
282301 public void testJoinFollowerFails () {
283302 DiscoveryNode node0 = newNode (0 , true );
284303 DiscoveryNode node1 = newNode (1 , true );
@@ -293,8 +312,7 @@ public void testJoinFollowerFails() {
293312 }
294313 assertFalse (isLocalNodeElectedMaster ());
295314 assertThat (expectThrows (CoordinationStateRejectedException .class ,
296- () -> joinNodeAndRun (new JoinRequest (node1 ,
297- Optional .of (new Join (node1 , node0 , newTerm , initialTerm , initialVersion ))))).getMessage (),
315+ () -> joinNodeAndRun (new JoinRequest (node1 , Optional .empty ()))).getMessage (),
298316 containsString ("join target is a follower" ));
299317 assertFalse (isLocalNodeElectedMaster ());
300318 }
0 commit comments