use of org.elasticsearch.transport.MockTransportClient in project elasticsearch by elastic.
the class SearchRequestBuilderTests method initClient.
@BeforeClass
public static void initClient() {
//this client will not be hit by any request, but it needs to be a non null proper client
//that is why we create it but we don't add any transport address to it
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
client = new MockTransportClient(settings);
}
use of org.elasticsearch.transport.MockTransportClient in project elasticsearch by elastic.
the class TransportClientTests method testThatUsingAClosedClientThrowsAnException.
public void testThatUsingAClosedClientThrowsAnException() throws ExecutionException, InterruptedException {
final TransportClient client = new MockTransportClient(Settings.EMPTY);
client.close();
final IllegalStateException e = expectThrows(IllegalStateException.class, () -> client.admin().cluster().health(new ClusterHealthRequest()).get());
assertThat(e, hasToString(containsString("transport client is closed")));
}
use of org.elasticsearch.transport.MockTransportClient in project elasticsearch by elastic.
the class NodeDisconnectIT method testNotifyOnDisconnectInSniffer.
public void testNotifyOnDisconnectInSniffer() throws IOException {
internalCluster().ensureAtLeastNumDataNodes(2);
final Set<DiscoveryNode> disconnectedNodes = Collections.synchronizedSet(new HashSet<>());
try (TransportClient client = new MockTransportClient(Settings.builder().put("cluster.name", internalCluster().getClusterName()).build(), Collections.emptySet(), (n, e) -> disconnectedNodes.add(n))) {
int numNodes = 0;
for (TransportService service : internalCluster().getInstances(TransportService.class)) {
numNodes++;
client.addTransportAddress(service.boundAddress().publishAddress());
}
Set<TransportAddress> discoveryNodes = client.connectedNodes().stream().map(n -> n.getAddress()).collect(Collectors.toSet());
assertEquals(numNodes, discoveryNodes.size());
assertEquals(0, disconnectedNodes.size());
internalCluster().stopRandomDataNode();
client.getNodesService().doSample();
assertEquals(1, disconnectedNodes.size());
assertTrue(discoveryNodes.contains(disconnectedNodes.stream().findAny().get().getAddress()));
}
assertEquals(1, disconnectedNodes.size());
}
use of org.elasticsearch.transport.MockTransportClient in project elasticsearch by elastic.
the class NodeDisconnectIT method testNotifyOnDisconnect.
public void testNotifyOnDisconnect() throws IOException {
internalCluster().ensureAtLeastNumDataNodes(2);
final Set<DiscoveryNode> disconnectedNodes = Collections.synchronizedSet(new HashSet<>());
try (TransportClient client = new MockTransportClient(Settings.builder().put("cluster.name", internalCluster().getClusterName()).put(CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL.getKey(), // disable sniffing for better control
"1h").build(), Collections.emptySet(), (n, e) -> disconnectedNodes.add(n))) {
for (TransportService service : internalCluster().getInstances(TransportService.class)) {
client.addTransportAddress(service.boundAddress().publishAddress());
}
internalCluster().stopRandomDataNode();
for (int i = 0; i < 20; i++) {
// fire up requests such that we hit the node and pass it to the listener
client.admin().cluster().prepareState().get();
}
assertEquals(1, disconnectedNodes.size());
}
assertEquals(1, disconnectedNodes.size());
}
use of org.elasticsearch.transport.MockTransportClient in project elasticsearch by elastic.
the class TransportClientHeadersTests method buildClient.
@Override
protected Client buildClient(Settings headersSettings, GenericAction[] testedActions) {
transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null);
transportService.start();
transportService.acceptIncomingRequests();
TransportClient client = new MockTransportClient(Settings.builder().put("client.transport.sniff", false).put("cluster.name", "cluster1").put("node.name", "transport_client_" + this.getTestName()).put(headersSettings).build(), InternalTransportServiceInterceptor.TestPlugin.class);
InternalTransportServiceInterceptor.TestPlugin plugin = client.injector.getInstance(PluginsService.class).filterPlugins(InternalTransportServiceInterceptor.TestPlugin.class).stream().findFirst().get();
plugin.instance.threadPool = client.threadPool();
plugin.instance.address = transportService.boundAddress().publishAddress();
client.addTransportAddress(transportService.boundAddress().publishAddress());
return client;
}
Aggregations