Search in sources :

Example 1 with NodesFaultDetection

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);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) CountDownLatch(java.util.concurrent.CountDownLatch) NodesFaultDetection(org.elasticsearch.discovery.zen.NodesFaultDetection) ClusterName(org.elasticsearch.cluster.ClusterName) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 ClusterName (org.elasticsearch.cluster.ClusterName)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 CircuitBreaker (org.elasticsearch.common.breaker.CircuitBreaker)1 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)1 Settings (org.elasticsearch.common.settings.Settings)1 NodesFaultDetection (org.elasticsearch.discovery.zen.NodesFaultDetection)1