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();
}
Aggregations