Search in sources :

Example 1 with GceNameResolver

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"));
    }
}
Also used : NetworkService(org.elasticsearch.common.network.NetworkService) GceNameResolver(org.elasticsearch.cloud.gce.network.GceNameResolver) InetAddress(java.net.InetAddress) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

InetAddress (java.net.InetAddress)1 GceNameResolver (org.elasticsearch.cloud.gce.network.GceNameResolver)1 NetworkService (org.elasticsearch.common.network.NetworkService)1 Settings (org.elasticsearch.common.settings.Settings)1