diff --git a/src/test/java/org/opensearch/security/test/helper/cluster/ClusterHelper.java b/src/test/java/org/opensearch/security/test/helper/cluster/ClusterHelper.java index 1ebd46cec6..75ad6e103b 100644 --- a/src/test/java/org/opensearch/security/test/helper/cluster/ClusterHelper.java +++ b/src/test/java/org/opensearch/security/test/helper/cluster/ClusterHelper.java @@ -39,6 +39,7 @@ import java.util.SortedSet; import java.util.TreeSet; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -247,10 +248,10 @@ public final void stopCluster() throws Exception { private void closeAllNodes() throws Exception { //close non master nodes - opensearchNodes.stream().filter(n->!n.isMasterEligible()).forEach(node->closeNode(node)); + opensearchNodes.stream().filter(n->!n.isMasterEligible()).forEach(ClusterHelper::closeNode); //close master nodes - opensearchNodes.stream().filter(n->n.isMasterEligible()).forEach(node->closeNode(node)); + opensearchNodes.stream().filter(n->n.isMasterEligible()).forEach(ClusterHelper::closeNode); opensearchNodes.clear(); clusterState = ClusterState.STOPPED; } @@ -258,7 +259,7 @@ private void closeAllNodes() throws Exception { private static void closeNode(Node node) { try { node.close(); - Thread.sleep(250); + node.awaitClose(250, TimeUnit.MILLISECONDS); } catch (Throwable e) { //ignore }