add more tests to network service

Follow up for #15340

We test that bind with wilcard IP + fixed IP it raises an exception
We test binding multiple IPs

(cherry picked from commit 2cc5bb7)
This commit is contained in:
David Pilato 2015-12-09 18:29:31 +01:00
parent b6fbd18e09
commit f675801b26
1 changed files with 43 additions and 20 deletions

View File

@ -24,6 +24,8 @@ import org.elasticsearch.test.ESTestCase;
import java.net.InetAddress;
import static org.hamcrest.Matchers.is;
/**
* Tests for network service... try to keep them safe depending upon configuration
* please don't actually bind to anything, just test the addresses.
@ -42,7 +44,6 @@ public class NetworkServiceTests extends ESTestCase {
assertTrue(e.getMessage().contains("invalid: multicast"));
}
}
/**
* ensure exception if we bind to multicast ipv6 address
*/
@ -115,4 +116,26 @@ public class NetworkServiceTests extends ESTestCase {
InetAddress address = service.resolvePublishHostAddresses(new String[] { "::" });
assertFalse(address.isAnyLocalAddress());
}
/**
* ensure we can bind to multiple addresses
*/
public void testBindMultipleAddresses() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY);
InetAddress[] addresses = service.resolveBindHostAddresses(new String[]{"127.0.0.1", "127.0.0.2"});
assertThat(addresses.length, is(2));
}
/**
* ensure we can't bind to multiple addresses when using wildcard
*/
public void testBindMultipleAddressesWithWildcard() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY);
try {
service.resolveBindHostAddresses(new String[]{"0.0.0.0", "127.0.0.1"});
fail("should have hit exception");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("is wildcard, but multiple addresses specified"));
}
}
}