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 <elasticmachine@users.noreply.github.com>

Co-authored-by: weizijun <weizijun1989@gmail.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
James Baiera 2020-07-14 13:35:24 -04:00 committed by GitHub
parent 55c4dec360
commit c30d382937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -208,6 +208,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

View File

@ -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();
/*