use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testAckListenerReceivesAcksFromAllNodes.
public void testAckListenerReceivesAcksFromAllNodes() {
try (Cluster cluster = new Cluster(randomIntBetween(3, 5))) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode leader = cluster.getAnyLeader();
AckCollector ackCollector = leader.submitValue(randomLong());
cluster.stabilise(DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
for (final ClusterNode clusterNode : cluster.clusterNodes) {
assertTrue("expected ack from " + clusterNode, ackCollector.hasAckedSuccessfully(clusterNode));
}
assertThat("leader should be last to ack", ackCollector.getSuccessfulAckIndex(leader), equalTo(cluster.clusterNodes.size() - 1));
}
}
use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testLeaderDisconnectionWithoutDisconnectEventDetectedQuickly.
public void testLeaderDisconnectionWithoutDisconnectEventDetectedQuickly() {
try (Cluster cluster = new Cluster(randomIntBetween(3, 5))) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode originalLeader = cluster.getAnyLeader();
logger.info("--> disconnecting leader {}", originalLeader);
originalLeader.disconnect();
cluster.stabilise(Math.max(// Each follower may have just sent a leader check, which receives no response
defaultMillis(LEADER_CHECK_TIMEOUT_SETTING) + // then wait for the follower to check the leader
defaultMillis(LEADER_CHECK_INTERVAL_SETTING) + // then wait for the exception response
DEFAULT_DELAY_VARIABILITY + // then wait for a new election
DEFAULT_ELECTION_DELAY, // ALSO the leader may have just sent a follower check, which receives no response
defaultMillis(FOLLOWER_CHECK_TIMEOUT_SETTING) + // wait for the leader to check its followers
defaultMillis(FOLLOWER_CHECK_INTERVAL_SETTING) + // then wait for the exception response
DEFAULT_DELAY_VARIABILITY) + // wait for the removal to be committed
DEFAULT_CLUSTER_STATE_UPDATE_DELAY + // then wait for the followup reconfiguration
DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
assertThat(cluster.getAnyLeader().getId(), not(equalTo(originalLeader.getId())));
}
}
use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testClusterRecoversAfterExceptionDuringSerialization.
public void testClusterRecoversAfterExceptionDuringSerialization() {
try (Cluster cluster = new Cluster(randomIntBetween(1, 5))) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode leader1 = cluster.getAnyLeader();
logger.info("--> submitting broken task to [{}]", leader1);
final AtomicBoolean failed = new AtomicBoolean();
leader1.submitUpdateTask("broken-task", cs -> ClusterState.builder(cs).putCustom("broken", new BrokenCustom()).build(), (source, e) -> {
assertThat(e.getCause(), instanceOf(ElasticsearchException.class));
assertThat(e.getCause().getMessage(), equalTo(BrokenCustom.EXCEPTION_MESSAGE));
failed.set(true);
});
cluster.runFor(DEFAULT_DELAY_VARIABILITY + 1, "processing broken task");
assertTrue(failed.get());
cluster.stabilise();
final ClusterNode leader2 = cluster.getAnyLeader();
long finalValue = randomLong();
logger.info("--> submitting value [{}] to [{}]", finalValue, leader2);
leader2.submitValue(finalValue);
cluster.stabilise(DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
for (final ClusterNode clusterNode : cluster.clusterNodes) {
final String nodeId = clusterNode.getId();
final ClusterState appliedState = clusterNode.getLastAppliedClusterState();
assertThat(nodeId + " has the applied value", value(appliedState), is(finalValue));
}
}
}
use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testSingleNodeDiscoveryWithoutQuorum.
public void testSingleNodeDiscoveryWithoutQuorum() {
try (Cluster cluster = new Cluster(3)) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode clusterNode = cluster.getAnyNode();
logger.debug("rebooting [{}]", clusterNode.getId());
clusterNode.close();
cluster.clusterNodes.forEach(cn -> cluster.deterministicTaskQueue.scheduleNow(cn.onNode(new Runnable() {
@Override
public void run() {
cn.transportService.disconnectFromNode(clusterNode.getLocalNode());
}
@Override
public String toString() {
return "disconnect from " + clusterNode.getLocalNode() + " after shutdown";
}
})));
IllegalStateException ise = expectThrows(IllegalStateException.class, () -> cluster.clusterNodes.replaceAll(cn -> cn == clusterNode ? cn.restartedNode(Function.identity(), Function.identity(), Settings.builder().put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE).build()) : cn));
assertThat(ise.getMessage(), allOf(containsString("cannot start with [discovery.type] set to [single-node] when local node"), containsString("does not have quorum in voting configuration")));
// to avoid closing it twice
cluster.clusterNodes.remove(clusterNode);
}
}
use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.
the class CoordinatorTests method testDiffBasedPublishing.
public void testDiffBasedPublishing() {
try (Cluster cluster = new Cluster(randomIntBetween(1, 5))) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode leader = cluster.getAnyLeader();
final long finalValue = randomLong();
final Map<ClusterNode, PublishClusterStateStats> prePublishStats = cluster.clusterNodes.stream().collect(Collectors.toMap(Function.identity(), cn -> cn.coordinator.stats().getPublishStats()));
logger.info("--> submitting value [{}] to [{}]", finalValue, leader);
leader.submitValue(finalValue);
cluster.stabilise(DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
final Map<ClusterNode, PublishClusterStateStats> postPublishStats = cluster.clusterNodes.stream().collect(Collectors.toMap(Function.identity(), cn -> cn.coordinator.stats().getPublishStats()));
for (ClusterNode cn : cluster.clusterNodes) {
assertThat(value(cn.getLastAppliedClusterState()), is(finalValue));
assertEquals(cn.toString(), prePublishStats.get(cn).getFullClusterStateReceivedCount(), postPublishStats.get(cn).getFullClusterStateReceivedCount());
assertEquals(cn.toString(), prePublishStats.get(cn).getCompatibleClusterStateDiffReceivedCount() + 1, postPublishStats.get(cn).getCompatibleClusterStateDiffReceivedCount());
assertEquals(cn.toString(), prePublishStats.get(cn).getIncompatibleClusterStateDiffReceivedCount(), postPublishStats.get(cn).getIncompatibleClusterStateDiffReceivedCount());
}
}
}
Aggregations