mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-25 09:28:27 +00:00
* 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:
parent
55c4dec360
commit
c30d382937
@ -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
|
||||
|
@ -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();
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user