use of org.elasticsearch.cloud.gce.network.GceNameResolver in project elasticsearch by elastic.
the class GceNetworkTests method resolveGce.
/**
* Utility test method to test different settings
* @param gceNetworkSetting tested network.host property
* @param expected expected InetAddress, null if we expect an exception
* @throws IOException Well... If something goes wrong :)
*/
private void resolveGce(String gceNetworkSetting, InetAddress[] expected) throws IOException {
Settings nodeSettings = Settings.builder().put("network.host", gceNetworkSetting).build();
GceMetadataServiceMock mock = new GceMetadataServiceMock(nodeSettings);
NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new GceNameResolver(nodeSettings, mock)));
try {
InetAddress[] addresses = networkService.resolveBindHostAddresses(null);
if (expected == null) {
fail("We should get a IllegalArgumentException when setting network.host: _gce:doesnotexist_");
}
assertThat(addresses, arrayContaining(expected));
} catch (IllegalArgumentException e) {
if (expected != null) {
// We were expecting something and not an exception
throw e;
}
// We check that we get the expected exception
assertThat(e.getMessage(), containsString("is not one of the supported GCE network.host setting"));
}
}
Aggregations