use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testJoinWithSameAcceptedTermButHigherVersion.
public void testJoinWithSameAcceptedTermButHigherVersion() {
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 badJoin = new Join(randomFrom(node1, node2), node1, v1.getTerm(), state2.term(), randomLongBetween(state2.version() + 1, 30));
assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handleJoin(badJoin)).getMessage(), containsString("higher than current last accepted version"));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandleClientValueWithBadTerm.
public void testHandleClientValueWithBadTerm() {
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(3, 5));
Join v1 = cs1.handleStartJoin(startJoinRequest1);
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.handleClientValue(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 testHandlePublishRequestWithSameTermButOlderOrSameVersion.
// scenario when handling a publish request from a master that we already received a newer state from
public void testHandlePublishRequestWithSameTermButOlderOrSameVersion() {
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());
}
ClusterState state2 = clusterState(startJoinRequest1.getTerm(), randomLongBetween(2, 10), node1, initialConfig, initialConfig, 42L);
cs1.handlePublishRequest(new PublishRequest(state2));
ClusterState state3 = clusterState(startJoinRequest1.getTerm(), randomLongBetween(0, state2.version()), node1, initialConfig, initialConfig, 42L);
assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handlePublishRequest(new PublishRequest(state3))).getMessage(), containsString("lower or equal to current version"));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandlePublishRequestWithTermHigherThanLastAcceptedTerm.
// scenario when handling a publish request from a fresh master
public void testHandlePublishRequestWithTermHigherThanLastAcceptedTerm() {
VotingConfiguration initialConfig = new VotingConfiguration(Collections.singleton(node1.getId()));
StartJoinRequest startJoinRequest1 = new StartJoinRequest(node1, randomLongBetween(1, 5));
ClusterState state1 = clusterState(startJoinRequest1.getTerm(), randomLongBetween(2, 10), node1, initialConfig, initialConfig, 42L);
cs2.handleStartJoin(startJoinRequest1);
cs2.handlePublishRequest(new PublishRequest(state1));
StartJoinRequest startJoinRequest2 = new StartJoinRequest(node1, randomLongBetween(startJoinRequest1.getTerm() + 1, 10));
cs2.handleStartJoin(startJoinRequest2);
ClusterState state2 = clusterState(startJoinRequest2.getTerm(), randomLongBetween(0, 20), node1, initialConfig, initialConfig, 42L);
cs2.handlePublishRequest(new PublishRequest(state2));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testJoinDoesNotWinElectionWhenOnlyCommittedConfigQuorum.
public void testJoinDoesNotWinElectionWhenOnlyCommittedConfigQuorum() {
VotingConfiguration configNode1 = new VotingConfiguration(Collections.singleton(node1.getId()));
VotingConfiguration configNode2 = new VotingConfiguration(Collections.singleton(node2.getId()));
ClusterState state1 = clusterState(0L, 0L, node1, configNode1, configNode2, 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));
}
Aggregations