use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testFollowerDisconnectionDetectedQuickly.
public void testFollowerDisconnectionDetectedQuickly() {
try (Cluster cluster = new Cluster(randomIntBetween(3, 5))) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode leader = cluster.getAnyLeader();
final ClusterNode follower = cluster.getAnyNodeExcept(leader);
logger.info("--> disconnecting follower {}", follower);
follower.disconnect();
logger.info("--> leader {} and follower {} get disconnect event", leader, follower);
leader.onDisconnectEventFrom(follower);
// to turn follower into candidate, which stabilisation asserts at the end
follower.onDisconnectEventFrom(leader);
cluster.stabilise(// disconnect is scheduled
DEFAULT_DELAY_VARIABILITY + DEFAULT_CLUSTER_STATE_UPDATE_DELAY + // then wait for the followup reconfiguration
DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
assertThat(cluster.getAnyLeader().getId(), equalTo(leader.getId()));
}
}
use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testAckListenerReceivesNackFromLeader.
public void testAckListenerReceivesNackFromLeader() {
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);
final long startingTerm = leader.coordinator.getCurrentTerm();
leader.allowClusterStateApplicationFailure();
leader.setClusterStateApplyResponse(ClusterStateApplyResponse.FAIL);
AckCollector ackCollector = leader.submitValue(randomLong());
cluster.runFor(DEFAULT_CLUSTER_STATE_UPDATE_DELAY, "committing value");
assertTrue(leader.coordinator.getMode() != Coordinator.Mode.LEADER || leader.coordinator.getCurrentTerm() > startingTerm);
leader.setClusterStateApplyResponse(ClusterStateApplyResponse.SUCCEED);
cluster.stabilise();
assertTrue("expected nack from " + leader, ackCollector.hasAckedUnsuccessfully(leader));
assertTrue("expected ack from " + follower0, ackCollector.hasAckedSuccessfully(follower0));
assertTrue("expected ack from " + follower1, ackCollector.hasAckedSuccessfully(follower1));
assertTrue(leader.coordinator.getMode() != Coordinator.Mode.LEADER || leader.coordinator.getCurrentTerm() > startingTerm);
}
}
use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testDoesNotShrinkConfigurationBelowFiveNodesIfAutoShrinkDisabled.
public void testDoesNotShrinkConfigurationBelowFiveNodesIfAutoShrinkDisabled() {
try (Cluster cluster = new Cluster(5)) {
cluster.runRandomly();
cluster.stabilise();
cluster.getAnyLeader().submitSetAutoShrinkVotingConfiguration(false);
cluster.stabilise(DEFAULT_ELECTION_DELAY);
final ClusterNode disconnect1 = cluster.getAnyNode();
final ClusterNode disconnect2 = cluster.getAnyNodeExcept(disconnect1);
logger.info("--> disconnecting {} and {}", disconnect1, disconnect2);
disconnect1.disconnect();
disconnect2.disconnect();
cluster.stabilise();
final ClusterNode disconnect3 = cluster.getAnyNodeExcept(disconnect1, disconnect2);
logger.info("--> disconnecting {}", disconnect3);
disconnect3.disconnect();
cluster.runFor(DEFAULT_STABILISATION_TIME, "allowing time for fault detection");
for (final ClusterNode clusterNode : cluster.clusterNodes) {
assertThat(clusterNode.getId() + " should be a candidate", clusterNode.coordinator.getMode(), equalTo(Mode.CANDIDATE));
}
disconnect1.heal();
// would not work if disconnect1 were removed from the configuration
cluster.stabilise();
}
}
use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testAckListenerReceivesNacksIfLeaderStandsDown.
public void testAckListenerReceivesNacksIfLeaderStandsDown() {
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);
leader.blackhole();
follower0.onDisconnectEventFrom(leader);
follower1.onDisconnectEventFrom(leader);
// let followers elect a leader among themselves before healing the leader and running the publication
cluster.runFor(// disconnect is scheduled
DEFAULT_DELAY_VARIABILITY + DEFAULT_ELECTION_DELAY, "elect new leader");
// cluster has two nodes in mode LEADER, in different terms ofc, and the one in the lower term won’t be able to publish anything
leader.heal();
AckCollector ackCollector = leader.submitValue(randomLong());
// TODO: check if can find a better bound here
cluster.stabilise();
assertTrue("expected nack from " + leader, ackCollector.hasAckedUnsuccessfully(leader));
assertTrue("expected nack from " + follower0, ackCollector.hasAckedUnsuccessfully(follower0));
assertTrue("expected nack from " + follower1, ackCollector.hasAckedUnsuccessfully(follower1));
}
}
use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testFollowerRemovedIfUnableToSendRequestsToMaster.
public void testFollowerRemovedIfUnableToSendRequestsToMaster() {
try (Cluster cluster = new Cluster(3)) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode leader = cluster.getAnyLeader();
final ClusterNode otherNode = cluster.getAnyNodeExcept(leader);
cluster.blackholeConnectionsFrom(otherNode, leader);
cluster.runFor((defaultMillis(FOLLOWER_CHECK_INTERVAL_SETTING) + defaultMillis(FOLLOWER_CHECK_TIMEOUT_SETTING)) * defaultInt(FOLLOWER_CHECK_RETRY_COUNT_SETTING) + (defaultMillis(LEADER_CHECK_INTERVAL_SETTING) + DEFAULT_DELAY_VARIABILITY) * defaultInt(LEADER_CHECK_RETRY_COUNT_SETTING) + DEFAULT_CLUSTER_STATE_UPDATE_DELAY, "awaiting removal of asymmetrically-partitioned node");
assertThat(leader.getLastAppliedClusterState().nodes().toString(), leader.getLastAppliedClusterState().nodes().getSize(), equalTo(2));
cluster.clearBlackholedConnections();
cluster.stabilise(// time for the disconnected node to find the master again
defaultMillis(DISCOVERY_FIND_PEERS_INTERVAL_SETTING) * 2 + // time for joining
4 * DEFAULT_DELAY_VARIABILITY + // Then a commit of the updated cluster state
DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
}
}
Aggregations