use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testSetInitialState.
public void testSetInitialState() {
VotingConfiguration initialConfig = new VotingConfiguration(Collections.singleton(node1.getId()));
ClusterState state1 = clusterState(0L, 0L, node1, initialConfig, initialConfig, 42L);
assertTrue(state1.getLastAcceptedConfiguration().hasQuorum(Collections.singleton(node1.getId())));
assertTrue(state1.getLastCommittedConfiguration().hasQuorum(Collections.singleton(node1.getId())));
cs1.setInitialState(state1);
assertThat(cs1.getLastAcceptedState(), equalTo(state1));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testSetInitialStateWhenAlreadySet.
public void testSetInitialStateWhenAlreadySet() {
VotingConfiguration initialConfig = new VotingConfiguration(Collections.singleton(node1.getId()));
ClusterState state1 = clusterState(0L, 0L, node1, initialConfig, initialConfig, 42L);
assertTrue(state1.getLastAcceptedConfiguration().hasQuorum(Collections.singleton(node1.getId())));
assertTrue(state1.getLastCommittedConfiguration().hasQuorum(Collections.singleton(node1.getId())));
cs1.setInitialState(state1);
assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.setInitialState(state1)).getMessage(), containsString("initial state already set"));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandleClientValueWithIllegalCommittedConfigurationChange.
public void testHandleClientValueWithIllegalCommittedConfigurationChange() {
assumeTrue("test only works with assertions enabled", Assertions.ENABLED);
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 newConfig = new VotingConfiguration(Collections.singleton(node2.getId()));
ClusterState state2 = clusterState(startJoinRequest1.getTerm(), 2L, node1, newConfig, newConfig, 42L);
assertThat(expectThrows(AssertionError.class, () -> cs1.handleClientValue(state2)).getMessage(), containsString("last committed configuration should not change"));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandlePublishResponseWhenSteppedDownAsLeader.
public void testHandlePublishResponseWhenSteppedDownAsLeader() {
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);
StartJoinRequest startJoinRequest2 = new StartJoinRequest(node1, randomLongBetween(startJoinRequest1.getTerm() + 1, 10));
cs1.handleStartJoin(startJoinRequest2);
assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handlePublishResponse(randomFrom(node1, node2, node3), publishResponse)).getMessage(), containsString("election not won"));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testJoinWithSameLastAcceptedTermButLowerOrSameVersionWinsElection.
public void testJoinWithSameLastAcceptedTermButLowerOrSameVersionWinsElection() {
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(node1, node1, v1.getTerm(), state2.term(), randomLongBetween(0, state2.version()));
assertTrue(cs1.handleJoin(join));
assertTrue(cs1.electionWon());
assertTrue(cs1.containsJoinVoteFor(node1));
assertFalse(cs1.containsJoinVoteFor(node2));
assertEquals(cs1.getLastPublishedVersion(), cs1.getLastAcceptedVersion());
assertFalse(cs1.handleJoin(join));
}
Aggregations