use of java.net.InetAddress in project elasticsearch by elastic.
the class NetworkUtilsTests method testSortKeyLinkLocal.
/**
* test private addresses sort before link local addresses
*/
public void testSortKeyLinkLocal() throws Exception {
InetAddress linkLocal = InetAddress.getByName("fe80::1");
assert linkLocal.isLinkLocalAddress();
InetAddress ordinary = InetAddress.getByName("fddd::1");
assertTrue(NetworkUtils.sortKey(ordinary, true) < NetworkUtils.sortKey(linkLocal, true));
assertTrue(NetworkUtils.sortKey(ordinary, false) < NetworkUtils.sortKey(linkLocal, false));
}
use of java.net.InetAddress in project elasticsearch by elastic.
the class InetAddressesTests method testForStringIPv4Input.
public void testForStringIPv4Input() throws UnknownHostException {
String ipStr = "192.168.0.1";
InetAddress ipv4Addr = null;
// Shouldn't hit DNS, because it's an IP string literal.
ipv4Addr = InetAddress.getByName(ipStr);
assertEquals(ipv4Addr, InetAddresses.forString(ipStr));
assertTrue(InetAddresses.isInetAddress(ipStr));
}
use of java.net.InetAddress in project elasticsearch by elastic.
the class InetAddressesTests method testForStringIPv6EightColons.
public void testForStringIPv6EightColons() throws UnknownHostException {
String[] eightColons = { "::7:6:5:4:3:2:1", "::7:6:5:4:3:2:0", "7:6:5:4:3:2:1::", "0:6:5:4:3:2:1::" };
for (int i = 0; i < eightColons.length; i++) {
InetAddress ipv6Addr = null;
// Shouldn't hit DNS, because it's an IP string literal.
ipv6Addr = InetAddress.getByName(eightColons[i]);
assertEquals(ipv6Addr, InetAddresses.forString(eightColons[i]));
assertTrue(InetAddresses.isInetAddress(eightColons[i]));
}
}
use of java.net.InetAddress in project elasticsearch by elastic.
the class NetworkServiceTests method testPublishAnyLocalV4.
/**
* ensure specifying wildcard ipv4 address selects reasonable publish address
*/
public void testPublishAnyLocalV4() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList());
InetAddress address = service.resolvePublishHostAddresses(new String[] { "0.0.0.0" });
assertFalse(address.isAnyLocalAddress());
}
use of java.net.InetAddress in project elasticsearch by elastic.
the class BoundTransportAddressTests method testSerialization.
public void testSerialization() throws Exception {
InetAddress[] inetAddresses = InetAddress.getAllByName("0.0.0.0");
List<TransportAddress> transportAddressList = new ArrayList<>();
for (InetAddress address : inetAddresses) {
transportAddressList.add(new TransportAddress(address, randomIntBetween(9200, 9299)));
}
final BoundTransportAddress transportAddress = new BoundTransportAddress(transportAddressList.toArray(new TransportAddress[0]), transportAddressList.get(0));
assertThat(transportAddress.boundAddresses().length, equalTo(transportAddressList.size()));
// serialize
BytesStreamOutput streamOutput = new BytesStreamOutput();
transportAddress.writeTo(streamOutput);
StreamInput in = streamOutput.bytes().streamInput();
BoundTransportAddress serializedAddress;
if (randomBoolean()) {
serializedAddress = BoundTransportAddress.readBoundTransportAddress(in);
} else {
serializedAddress = new BoundTransportAddress();
serializedAddress.readFrom(in);
}
assertThat(serializedAddress, not(sameInstance(transportAddress)));
assertThat(serializedAddress.boundAddresses().length, equalTo(transportAddress.boundAddresses().length));
assertThat(serializedAddress.publishAddress(), equalTo(transportAddress.publishAddress()));
TransportAddress[] serializedBoundAddresses = serializedAddress.boundAddresses();
TransportAddress[] boundAddresses = transportAddress.boundAddresses();
for (int i = 0; i < serializedBoundAddresses.length; i++) {
assertThat(serializedBoundAddresses[i], equalTo(boundAddresses[i]));
}
}
Aggregations