@@ -431,12 +431,15 @@ public void testHandlePublishRequest() {
431
431
assertTrue (cs1 .handleJoin (v1 ));
432
432
assertTrue (cs1 .electionWon ());
433
433
}
434
- ClusterState state2 = clusterState (startJoinRequest1 .getTerm (), 2L , node1 , initialConfig , initialConfig , 13L );
434
+ ClusterState state2 = clusterState (startJoinRequest1 .getTerm (), randomLongBetween ( 1 , 10 ) , node1 , initialConfig , initialConfig , 13L );
435
435
PublishResponse publishResponse = cs1 .handlePublishRequest (new PublishRequest (state2 ));
436
436
assertThat (publishResponse .getTerm (), equalTo (state2 .term ()));
437
437
assertThat (publishResponse .getVersion (), equalTo (state2 .version ()));
438
438
assertThat (cs1 .getLastAcceptedState (), equalTo (state2 ));
439
439
assertThat (value (cs1 .getLastAcceptedState ()), equalTo (13L ));
440
+ ClusterState state3 = clusterState (startJoinRequest1 .getTerm (), randomLongBetween (state2 .getVersion () + 1 , 20 ), node1 ,
441
+ initialConfig , initialConfig , 13L );
442
+ cs1 .handlePublishRequest (new PublishRequest (state3 ));
440
443
}
441
444
442
445
public void testHandlePublishRequestWithBadTerm () {
@@ -458,7 +461,8 @@ public void testHandlePublishRequestWithBadTerm() {
458
461
containsString ("does not match current term" ));
459
462
}
460
463
461
- public void testHandlePublishRequestWithOlderVersion () {
464
+ // scenario when handling a publish request from a master that we already received a newer state from
465
+ public void testHandlePublishRequestWithSameTermButOlderOrSameVersion () {
462
466
VotingConfiguration initialConfig = new VotingConfiguration (Collections .singleton (node1 .getId ()));
463
467
ClusterState state1 = clusterState (0L , 1L , node1 , initialConfig , initialConfig , 42L );
464
468
cs1 .setInitialState (state1 );
@@ -477,6 +481,20 @@ public void testHandlePublishRequestWithOlderVersion() {
477
481
containsString ("lower or equal to current version" ));
478
482
}
479
483
484
+ // scenario when handling a publish request from a fresh master
485
+ public void testHandlePublishRequestWithTermHigherThanLastAcceptedTerm () {
486
+ VotingConfiguration initialConfig = new VotingConfiguration (Collections .singleton (node1 .getId ()));
487
+ StartJoinRequest startJoinRequest1 = new StartJoinRequest (node1 , randomLongBetween (1 , 5 ));
488
+ ClusterState state1 = clusterState (startJoinRequest1 .getTerm (), randomLongBetween (2 , 10 ), node1 , initialConfig , initialConfig , 42L );
489
+ cs2 .handleStartJoin (startJoinRequest1 );
490
+ cs2 .handlePublishRequest (new PublishRequest (state1 ));
491
+ StartJoinRequest startJoinRequest2 = new StartJoinRequest (node1 , randomLongBetween (startJoinRequest1 .getTerm () + 1 , 10 ));
492
+ cs2 .handleStartJoin (startJoinRequest2 );
493
+ ClusterState state2 = clusterState (startJoinRequest2 .getTerm (), randomLongBetween (0 , 20 ), node1 , initialConfig ,
494
+ initialConfig , 42L );
495
+ cs2 .handlePublishRequest (new PublishRequest (state2 ));
496
+ }
497
+
480
498
public void testHandlePublishResponseWithCommit () {
481
499
VotingConfiguration initialConfig = new VotingConfiguration (Collections .singleton (node1 .getId ()));
482
500
ClusterState state1 = clusterState (0L , 1L , node1 , initialConfig , initialConfig , 42L );
0 commit comments