use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testStayCandidateAfterReceivingFollowerCheckFromKnownMaster.
/**
* Simulates a situation where a follower becomes disconnected from the leader, but only for such a short time where
* it becomes candidate and puts up a NO_MASTER_BLOCK, but then receives a follower check from the leader. If the leader
* does not notice the node disconnecting, it is important for the node not to be turned back into a follower but try
* and join the leader again.
*/
public void testStayCandidateAfterReceivingFollowerCheckFromKnownMaster() {
try (Cluster cluster = new Cluster(2, false, Settings.EMPTY)) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode leader = cluster.getAnyLeader();
final ClusterNode nonLeader = cluster.getAnyNodeExcept(leader);
nonLeader.onNode(() -> {
logger.debug("forcing {} to become candidate", nonLeader.getId());
synchronized (nonLeader.coordinator.mutex) {
nonLeader.coordinator.becomeCandidate("forced");
}
logger.debug("simulate follower check coming through from {} to {}", leader.getId(), nonLeader.getId());
expectThrows(CoordinationStateRejectedException.class, () -> nonLeader.coordinator.onFollowerCheckRequest(new FollowersChecker.FollowerCheckRequest(leader.coordinator.getCurrentTerm(), leader.getLocalNode())));
assertThat(nonLeader.coordinator.getMode(), equalTo(CANDIDATE));
}).run();
cluster.stabilise();
}
}
use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testExpandsConfigurationWhenGrowingFromOneNodeToThreeButDoesNotShrink.
public void testExpandsConfigurationWhenGrowingFromOneNodeToThreeButDoesNotShrink() {
try (Cluster cluster = new Cluster(1)) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode leader = cluster.getAnyLeader();
cluster.addNodesAndStabilise(2);
{
assertThat(leader.coordinator.getMode(), is(Mode.LEADER));
final VotingConfiguration lastCommittedConfiguration = leader.getLastAppliedClusterState().getLastCommittedConfiguration();
assertThat(lastCommittedConfiguration + " should be all nodes", lastCommittedConfiguration.getNodeIds(), equalTo(cluster.clusterNodes.stream().map(ClusterNode::getId).collect(Collectors.toSet())));
}
final ClusterNode disconnect1 = cluster.getAnyNode();
logger.info("--> disconnecting {}", disconnect1);
disconnect1.disconnect();
cluster.stabilise();
{
final ClusterNode newLeader = cluster.getAnyLeader();
final VotingConfiguration lastCommittedConfiguration = newLeader.getLastAppliedClusterState().getLastCommittedConfiguration();
assertThat(lastCommittedConfiguration + " should be all nodes", lastCommittedConfiguration.getNodeIds(), equalTo(cluster.clusterNodes.stream().map(ClusterNode::getId).collect(Collectors.toSet())));
}
}
}
use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testDiscoveryUsesNodesFromLastClusterState.
public void testDiscoveryUsesNodesFromLastClusterState() {
try (Cluster cluster = new Cluster(randomIntBetween(3, 5))) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode partitionedNode = cluster.getAnyNode();
if (randomBoolean()) {
logger.info("--> blackholing {}", partitionedNode);
partitionedNode.blackhole();
} else {
logger.info("--> disconnecting {}", partitionedNode);
partitionedNode.disconnect();
}
cluster.setEmptySeedHostsList();
cluster.stabilise();
partitionedNode.heal();
cluster.runRandomly(false);
cluster.stabilise();
}
}
use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testDoesNotElectNonMasterNode.
public void testDoesNotElectNonMasterNode() {
try (Cluster cluster = new Cluster(randomIntBetween(1, 5), false, Settings.EMPTY)) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode leader = cluster.getAnyLeader();
assertTrue(leader.getLocalNode().isMasterEligibleNode());
}
}
use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testAckListenerReceivesNackFromFollower.
public void testAckListenerReceivesNackFromFollower() {
try (Cluster cluster = new Cluster(3)) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode leader = cluster.getAnyLeader();
final ClusterNode follower0 = cluster.getAnyNodeExcept(leader);
final ClusterNode follower1 = cluster.getAnyNodeExcept(leader, follower0);
follower0.allowClusterStateApplicationFailure();
follower0.setClusterStateApplyResponse(ClusterStateApplyResponse.FAIL);
AckCollector ackCollector = leader.submitValue(randomLong());
cluster.stabilise(DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
assertTrue("expected ack from " + leader, ackCollector.hasAckedSuccessfully(leader));
assertTrue("expected nack from " + follower0, ackCollector.hasAckedUnsuccessfully(follower0));
assertTrue("expected ack from " + follower1, ackCollector.hasAckedSuccessfully(follower1));
assertThat("leader should be last to ack", ackCollector.getSuccessfulAckIndex(leader), equalTo(1));
}
}
Aggregations