Skip to content

Commit c30d382

Browse files
jbaieraweizijunelasticmachine
authored
LLRC RestClient add isRunning method (#57973) (#59345)
* 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 <[email protected]> Co-authored-by: weizijun <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 55c4dec commit c30d382

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

client/rest/src/main/java/org/elasticsearch/client/RestClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ public List<Node> getNodes() {
208208
return nodeTuple.nodes;
209209
}
210210

211+
/**
212+
* check client running status
213+
* @return client running status
214+
*/
215+
public boolean isRunning() {
216+
return client.isRunning();
217+
}
218+
211219
/**
212220
* Sends a request to the Elasticsearch cluster that the client points to.
213221
* Blocks until the request is completed and returns its response or fails

client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@
4545
import static java.util.Collections.singletonList;
4646
import static org.hamcrest.Matchers.instanceOf;
4747
import static org.junit.Assert.assertEquals;
48+
import static org.junit.Assert.assertFalse;
4849
import static org.junit.Assert.assertSame;
4950
import static org.junit.Assert.assertThat;
5051
import static org.junit.Assert.assertTrue;
5152
import static org.junit.Assert.fail;
5253
import static org.mockito.Mockito.mock;
5354
import static org.mockito.Mockito.times;
5455
import static org.mockito.Mockito.verify;
56+
import static org.mockito.Mockito.when;
5557

5658
public class RestClientTests extends RestClientTestCase {
5759

@@ -387,6 +389,18 @@ public void testRoundRobin() throws IOException {
387389
assertEquals(Integer.MIN_VALUE + 50, lastNodeIndex.get());
388390
}
389391

392+
public void testIsRunning(){
393+
List<Node> nodes = Collections.singletonList(new Node(new HttpHost("localhost", 9200)));
394+
CloseableHttpAsyncClient client = mock(CloseableHttpAsyncClient.class);
395+
RestClient restClient = new RestClient(client, new Header[] {}, nodes, null, null, null, false);
396+
397+
when(client.isRunning()).thenReturn(true);
398+
assertTrue(restClient.isRunning());
399+
400+
when(client.isRunning()).thenReturn(false);
401+
assertFalse(restClient.isRunning());
402+
}
403+
390404
private static void assertNodes(NodeTuple<List<Node>> nodeTuple, AtomicInteger lastNodeIndex, int runs) throws IOException {
391405
int distance = lastNodeIndex.get() % nodeTuple.nodes.size();
392406
/*

0 commit comments

Comments
 (0)