@@ -546,6 +546,24 @@ public void testHandlePublishResponseWithCommit() {
546546 assertThat (applyCommit .get ().getVersion (), equalTo (state2 .version ()));
547547 }
548548
549+ public void testHandlePublishResponseWhenSteppedDownAsLeader () {
550+ VotingConfiguration initialConfig = new VotingConfiguration (Collections .singleton (node1 .getId ()));
551+ ClusterState state1 = clusterState (0L , 1L , node1 , initialConfig , initialConfig , 42L );
552+ cs1 .setInitialState (state1 );
553+ StartJoinRequest startJoinRequest1 = new StartJoinRequest (node1 , randomLongBetween (1 , 5 ));
554+ Join v1 = cs1 .handleStartJoin (startJoinRequest1 );
555+ assertTrue (cs1 .handleJoin (v1 ));
556+ assertTrue (cs1 .electionWon ());
557+ ClusterState state2 = clusterState (startJoinRequest1 .getTerm (), 2L , node1 , initialConfig , initialConfig , 42L );
558+ PublishRequest publishRequest = cs1 .handleClientValue (state2 );
559+ PublishResponse publishResponse = cs1 .handlePublishRequest (publishRequest );
560+ StartJoinRequest startJoinRequest2 = new StartJoinRequest (node1 , randomLongBetween (startJoinRequest1 .getTerm () + 1 , 10 ));
561+ cs1 .handleStartJoin (startJoinRequest2 );
562+ assertThat (expectThrows (CoordinationStateRejectedException .class ,
563+ () -> cs1 .handlePublishResponse (randomFrom (node1 , node2 , node3 ), publishResponse )).getMessage (),
564+ containsString ("election not won" ));
565+ }
566+
549567 public void testHandlePublishResponseWithoutPublishConfigQuorum () {
550568 VotingConfiguration configNode1 = new VotingConfiguration (Collections .singleton (node1 .getId ()));
551569 VotingConfiguration configNode2 = new VotingConfiguration (Collections .singleton (node2 .getId ()));
0 commit comments