use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandleCommitWithBadVersion.
public void testHandleCommitWithBadVersion() {
VotingConfiguration initialConfig = new VotingConfiguration(Collections.singleton(node1.getId()));
ClusterState state1 = clusterState(0L, 0L, node1, initialConfig, initialConfig, 42L);
cs1.setInitialState(state1);
StartJoinRequest startJoinRequest1 = new StartJoinRequest(node1, randomLongBetween(1, 5));
Join v1 = cs1.handleStartJoin(startJoinRequest1);
assertTrue(cs1.handleJoin(v1));
assertTrue(cs1.electionWon());
ClusterState state2 = clusterState(startJoinRequest1.getTerm(), 2L, node1, initialConfig, initialConfig, 7L);
PublishRequest publishRequest = cs1.handleClientValue(state2);
cs1.handlePublishRequest(publishRequest);
assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handleCommit(new ApplyCommitRequest(node1, startJoinRequest1.getTerm(), randomLongBetween(3, 10)))).getMessage(), containsString("does not match current version"));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testJoinDoesNotWinElection.
public void testJoinDoesNotWinElection() {
VotingConfiguration initialConfig = new VotingConfiguration(Collections.singleton(node1.getId()));
ClusterState state1 = clusterState(0L, 0L, node1, initialConfig, initialConfig, 42L);
cs1.setInitialState(state1);
StartJoinRequest startJoinRequest1 = new StartJoinRequest(node2, randomLongBetween(1, 5));
cs1.handleStartJoin(startJoinRequest1);
ClusterState state2 = clusterState(startJoinRequest1.getTerm(), randomLongBetween(2, 20), node1, initialConfig, initialConfig, 42L);
cs1.handlePublishRequest(new PublishRequest(state2));
StartJoinRequest startJoinRequest2 = new StartJoinRequest(node2, randomLongBetween(startJoinRequest1.getTerm() + 1, 10));
Join v1 = cs1.handleStartJoin(startJoinRequest2);
Join join = new Join(node2, node1, v1.getTerm(), randomLongBetween(0, state2.term()), randomLongBetween(0, state2.version()));
assertTrue(cs1.handleJoin(join));
assertFalse(cs1.electionWon());
assertEquals(cs1.getLastPublishedVersion(), 0L);
assertFalse(cs1.handleJoin(join));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandleClientValueWithConfigurationChangeButNoJoinQuorum.
public void testHandleClientValueWithConfigurationChangeButNoJoinQuorum() {
VotingConfiguration initialConfig = new VotingConfiguration(Collections.singleton(node1.getId()));
ClusterState state1 = clusterState(0L, 0L, node1, initialConfig, initialConfig, 42L);
cs1.setInitialState(state1);
StartJoinRequest startJoinRequest1 = new StartJoinRequest(node1, randomLongBetween(1, 5));
Join v1 = cs1.handleStartJoin(startJoinRequest1);
assertTrue(cs1.handleJoin(v1));
assertTrue(cs1.electionWon());
VotingConfiguration newConfig = new VotingConfiguration(Collections.singleton(node2.getId()));
ClusterState state2 = clusterState(startJoinRequest1.getTerm(), 2L, node1, initialConfig, newConfig, 42L);
assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handleClientValue(state2)).getMessage(), containsString("only allow reconfiguration if joinVotes have quorum for new config"));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandleClientValueWithSameReconfigurationWhileAlreadyReconfiguring.
public void testHandleClientValueWithSameReconfigurationWhileAlreadyReconfiguring() {
VotingConfiguration initialConfig = new VotingConfiguration(Collections.singleton(node1.getId()));
ClusterState state1 = clusterState(0L, 0L, node1, initialConfig, initialConfig, 42L);
cs1.setInitialState(state1);
StartJoinRequest startJoinRequest1 = new StartJoinRequest(node1, randomLongBetween(1, 5));
Join v1 = cs1.handleStartJoin(startJoinRequest1);
Join v2 = cs2.handleStartJoin(startJoinRequest1);
assertTrue(cs1.handleJoin(v1));
assertTrue(cs1.electionWon());
assertTrue(cs1.handleJoin(v2));
VotingConfiguration newConfig1 = new VotingConfiguration(Collections.singleton(node2.getId()));
ClusterState state2 = clusterState(startJoinRequest1.getTerm(), 2L, node1, initialConfig, newConfig1, 42L);
PublishRequest publishRequest = cs1.handleClientValue(state2);
cs1.handlePublishRequest(publishRequest);
ClusterState state3 = clusterState(startJoinRequest1.getTerm(), 3L, node1, initialConfig, newConfig1, 42L);
cs1.handleClientValue(state3);
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandlePublishResponseWithCommit.
public void testHandlePublishResponseWithCommit() {
VotingConfiguration initialConfig = new VotingConfiguration(Collections.singleton(node1.getId()));
ClusterState state1 = clusterState(0L, 0L, node1, initialConfig, initialConfig, 42L);
cs1.setInitialState(state1);
StartJoinRequest startJoinRequest1 = new StartJoinRequest(node1, randomLongBetween(1, 5));
Join v1 = cs1.handleStartJoin(startJoinRequest1);
assertTrue(cs1.handleJoin(v1));
assertTrue(cs1.electionWon());
ClusterState state2 = clusterState(startJoinRequest1.getTerm(), 2L, node1, initialConfig, initialConfig, 42L);
PublishRequest publishRequest = cs1.handleClientValue(state2);
PublishResponse publishResponse = cs1.handlePublishRequest(publishRequest);
Optional<ApplyCommitRequest> applyCommit = cs1.handlePublishResponse(node1, publishResponse);
assertTrue(applyCommit.isPresent());
assertThat(applyCommit.get().getSourceNode(), equalTo(node1));
assertThat(applyCommit.get().getTerm(), equalTo(state2.term()));
assertThat(applyCommit.get().getVersion(), equalTo(state2.version()));
}
Aggregations