1
0
Эх сурвалжийг харах

LLRC RestClient add isRunning method (#57973)

* RestClient add isRunning method to check the inner client's status

* RestClient add isRunning method to check the inner client's status

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
weizijun 5 жил өмнө
parent
commit
4542dfc107

+ 8 - 0
client/rest/src/main/java/org/elasticsearch/client/RestClient.java

@@ -207,6 +207,14 @@ public class RestClient implements Closeable {
         return nodeTuple.nodes;
     }
 
+    /**
+     * check client running status
+     * @return client running status
+     */
+    public boolean isRunning() {
+        return client.isRunning();
+    }
+
     /**
      * Sends a request to the Elasticsearch cluster that the client points to.
      * Blocks until the request is completed and returns its response or fails

+ 14 - 0
client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java

@@ -45,6 +45,7 @@ import java.util.function.Supplier;
 import static java.util.Collections.singletonList;
 import static org.hamcrest.Matchers.instanceOf;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
@@ -52,6 +53,7 @@ import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 public class RestClientTests extends RestClientTestCase {
 
@@ -387,6 +389,18 @@ public class RestClientTests extends RestClientTestCase {
         assertEquals(Integer.MIN_VALUE + 50, lastNodeIndex.get());
     }
 
+    public void testIsRunning(){
+        List<Node> nodes = Collections.singletonList(new Node(new HttpHost("localhost", 9200)));
+        CloseableHttpAsyncClient client = mock(CloseableHttpAsyncClient.class);
+        RestClient restClient = new RestClient(client, new Header[] {}, nodes, null, null, null, false);
+
+        when(client.isRunning()).thenReturn(true);
+        assertTrue(restClient.isRunning());
+
+        when(client.isRunning()).thenReturn(false);
+        assertFalse(restClient.isRunning());
+    }
+
     private static void assertNodes(NodeTuple<List<Node>> nodeTuple, AtomicInteger lastNodeIndex, int runs) throws IOException {
         int distance = lastNodeIndex.get() % nodeTuple.nodes.size();
         /*