use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testJoinWithBadCurrentTerm.
public void testJoinWithBadCurrentTerm() {
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);
Join badJoin = new Join(randomFrom(node1, node2), node1, randomLongBetween(0, startJoinRequest1.getTerm() - 1), randomNonNegativeLong(), randomNonNegativeLong());
assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handleJoin(badJoin)).getMessage(), containsString("does not match current term"));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandleClientValueWithDifferentReconfigurationWhileAlreadyReconfiguring.
public void testHandleClientValueWithDifferentReconfigurationWhileAlreadyReconfiguring() {
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);
VotingConfiguration newConfig2 = new VotingConfiguration(Collections.singleton(node3.getId()));
ClusterState state3 = clusterState(startJoinRequest1.getTerm(), 3L, node1, initialConfig, newConfig2, 42L);
assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handleClientValue(state3)).getMessage(), containsString("only allow reconfiguration while not already reconfiguring"));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandlePublishRequestWithBadTerm.
public void testHandlePublishRequestWithBadTerm() {
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);
if (randomBoolean()) {
assertTrue(cs1.handleJoin(v1));
assertTrue(cs1.electionWon());
}
long term = randomBoolean() ? randomLongBetween(startJoinRequest1.getTerm() + 1, 10) : randomLongBetween(0, startJoinRequest1.getTerm() - 1);
ClusterState state2 = clusterState(term, 2L, node1, initialConfig, initialConfig, 42L);
assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handlePublishRequest(new PublishRequest(state2))).getMessage(), containsString("does not match current term"));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testJoinDoesNotWinElectionWhenOnlyLastAcceptedConfigQuorum.
public void testJoinDoesNotWinElectionWhenOnlyLastAcceptedConfigQuorum() {
VotingConfiguration configNode1 = new VotingConfiguration(Collections.singleton(node1.getId()));
VotingConfiguration configNode2 = new VotingConfiguration(Collections.singleton(node2.getId()));
ClusterState state1 = clusterState(0L, 0L, node1, configNode2, configNode1, 42L);
cs1.setInitialState(state1);
StartJoinRequest startJoinRequest = new StartJoinRequest(node1, randomLongBetween(1, 5));
Join join = cs1.handleStartJoin(startJoinRequest);
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 testHandlePublishResponseWithoutCommit.
public void testHandlePublishResponseWithoutCommit() {
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(node2, publishResponse);
assertFalse(applyCommit.isPresent());
}
Aggregations