Search in sources :

Example 1 with TransportClusterHealthAction

use of org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction in project elasticsearch by elastic.

the class ClusterStateHealthTests method testClusterHealthWaitsForClusterStateApplication.

public void testClusterHealthWaitsForClusterStateApplication() throws InterruptedException, ExecutionException {
    final CountDownLatch applyLatch = new CountDownLatch(1);
    final CountDownLatch listenerCalled = new CountDownLatch(1);
    setState(clusterService, ClusterState.builder(clusterService.state()).nodes(DiscoveryNodes.builder(clusterService.state().nodes()).masterNodeId(null)).build());
    clusterService.addStateApplier(event -> {
        listenerCalled.countDown();
        try {
            applyLatch.await();
        } catch (InterruptedException e) {
            logger.debug("interrupted", e);
        }
    });
    logger.info("--> submit task to restore master");
    clusterService.submitStateUpdateTask("restore master", new LocalClusterUpdateTask() {

        @Override
        public ClusterTasksResult<LocalClusterUpdateTask> execute(ClusterState currentState) throws Exception {
            return newState(ClusterState.builder(currentState).nodes(DiscoveryNodes.builder(currentState.nodes()).masterNodeId(currentState.nodes().getLocalNodeId())).build());
        }

        @Override
        public void onFailure(String source, Exception e) {
            logger.warn("unexpected failure", e);
        }
    });
    logger.info("--> waiting for listener to be called and cluster state being blocked");
    listenerCalled.await();
    TransportClusterHealthAction action = new TransportClusterHealthAction(Settings.EMPTY, transportService, clusterService, threadPool, new ActionFilters(new HashSet<>()), indexNameExpressionResolver, new TestGatewayAllocator());
    PlainActionFuture<ClusterHealthResponse> listener = new PlainActionFuture<>();
    action.execute(new ClusterHealthRequest().waitForGreenStatus(), listener);
    assertFalse(listener.isDone());
    logger.info("--> realising task to restore master");
    applyLatch.countDown();
    listener.get();
}
Also used : TestGatewayAllocator(org.elasticsearch.test.gateway.TestGatewayAllocator) ClusterState(org.elasticsearch.cluster.ClusterState) LocalClusterUpdateTask(org.elasticsearch.cluster.LocalClusterUpdateTask) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) ActionFilters(org.elasticsearch.action.support.ActionFilters) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) TransportClusterHealthAction(org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 ClusterHealthRequest (org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)1 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)1 TransportClusterHealthAction (org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction)1 ActionFilters (org.elasticsearch.action.support.ActionFilters)1 PlainActionFuture (org.elasticsearch.action.support.PlainActionFuture)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 LocalClusterUpdateTask (org.elasticsearch.cluster.LocalClusterUpdateTask)1 TestGatewayAllocator (org.elasticsearch.test.gateway.TestGatewayAllocator)1