use of org.elasticsearch.discovery.zen.NodesFaultDetection in project elasticsearch by elastic.
the class ZenFaultDetectionTests method testNodesFaultDetectionConnectOnDisconnect.
public void testNodesFaultDetectionConnectOnDisconnect() throws InterruptedException {
boolean shouldRetry = randomBoolean();
// make sure we don't ping again after the initial ping
final Settings pingSettings = Settings.builder().put(FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING.getKey(), shouldRetry).put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "5m").build();
ClusterState clusterState = ClusterState.builder(new ClusterName("test")).nodes(buildNodesForA(true)).build();
NodesFaultDetection nodesFDA = new NodesFaultDetection(Settings.builder().put(settingsA).put(pingSettings).build(), threadPool, serviceA, clusterState.getClusterName());
nodesFDA.setLocalNode(nodeA);
NodesFaultDetection nodesFDB = new NodesFaultDetection(Settings.builder().put(settingsB).put(pingSettings).build(), threadPool, serviceB, clusterState.getClusterName());
nodesFDB.setLocalNode(nodeB);
final CountDownLatch pingSent = new CountDownLatch(1);
nodesFDB.addListener(new NodesFaultDetection.Listener() {
@Override
public void onPingReceived(NodesFaultDetection.PingRequest pingRequest) {
pingSent.countDown();
}
});
nodesFDA.updateNodesAndPing(clusterState);
// wait for the first ping to go out, so we will really respond to a disconnect event rather then
// the ping failing
pingSent.await(30, TimeUnit.SECONDS);
final String[] failureReason = new String[1];
final DiscoveryNode[] failureNode = new DiscoveryNode[1];
final CountDownLatch notified = new CountDownLatch(1);
nodesFDA.addListener(new NodesFaultDetection.Listener() {
@Override
public void onNodeFailure(DiscoveryNode node, String reason) {
failureNode[0] = node;
failureReason[0] = reason;
notified.countDown();
}
});
// will raise a disconnect on A
serviceB.stop();
notified.await(30, TimeUnit.SECONDS);
CircuitBreaker inFlightRequestsBreaker = circuitBreakerService.getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
assertThat(inFlightRequestsBreaker.getTrippedCount(), equalTo(0L));
assertEquals(nodeB, failureNode[0]);
Matcher<String> matcher = Matchers.containsString("verified");
if (!shouldRetry) {
matcher = Matchers.not(matcher);
}
assertThat(failureReason[0], matcher);
}
Aggregations