Search in sources :

Example 1 with TransportClusterHealthAction

use of org.opensearch.action.admin.cluster.health.TransportClusterHealthAction in project OpenSearch by opensearch-project.

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 cluster-manager");
    ClusterState currentState = clusterService.getClusterApplierService().state();
    clusterService.getClusterApplierService().onNewClusterState("restore cluster-manager", () -> ClusterState.builder(currentState).nodes(DiscoveryNodes.builder(currentState.nodes()).masterNodeId(currentState.nodes().getLocalNodeId())).build(), (source, e) -> {
    });
    logger.info("--> waiting for listener to be called and cluster state being blocked");
    listenerCalled.await();
    TransportClusterHealthAction action = new TransportClusterHealthAction(transportService, clusterService, threadPool, new ActionFilters(new HashSet<>()), indexNameExpressionResolver, new AllocationService(null, new TestGatewayAllocator(), null, null, null));
    PlainActionFuture<ClusterHealthResponse> listener = new PlainActionFuture<>();
    action.execute(new ClusterHealthRequest().waitForGreenStatus(), listener);
    assertFalse(listener.isDone());
    logger.info("--> realising task to restore cluster-manager");
    applyLatch.countDown();
    listener.get();
}
Also used : TestGatewayAllocator(org.opensearch.test.gateway.TestGatewayAllocator) ClusterState(org.opensearch.cluster.ClusterState) ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) ClusterHealthRequest(org.opensearch.action.admin.cluster.health.ClusterHealthRequest) TransportClusterHealthAction(org.opensearch.action.admin.cluster.health.TransportClusterHealthAction) ActionFilters(org.opensearch.action.support.ActionFilters) CountDownLatch(java.util.concurrent.CountDownLatch) AllocationService(org.opensearch.cluster.routing.allocation.AllocationService) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ClusterHealthRequest (org.opensearch.action.admin.cluster.health.ClusterHealthRequest)1 ClusterHealthResponse (org.opensearch.action.admin.cluster.health.ClusterHealthResponse)1 TransportClusterHealthAction (org.opensearch.action.admin.cluster.health.TransportClusterHealthAction)1 ActionFilters (org.opensearch.action.support.ActionFilters)1 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)1 ClusterState (org.opensearch.cluster.ClusterState)1 AllocationService (org.opensearch.cluster.routing.allocation.AllocationService)1 TestGatewayAllocator (org.opensearch.test.gateway.TestGatewayAllocator)1