use of org.elasticsearch.common.transport.TransportAddress in project elasticsearch by elastic.
the class BootstrapChecksTests method testEnforceLimitsWhenPublishingToNonLocalAddress.
public void testEnforceLimitsWhenPublishingToNonLocalAddress() {
final List<TransportAddress> transportAddresses = new ArrayList<>();
for (int i = 0; i < randomIntBetween(1, 8); i++) {
final TransportAddress randomTransportAddress = buildNewFakeTransportAddress();
transportAddresses.add(randomTransportAddress);
}
final TransportAddress publishAddress = new TransportAddress(InetAddress.getLoopbackAddress(), 0);
final BoundTransportAddress boundTransportAddress = mock(BoundTransportAddress.class);
when(boundTransportAddress.boundAddresses()).thenReturn(transportAddresses.toArray(new TransportAddress[0]));
when(boundTransportAddress.publishAddress()).thenReturn(publishAddress);
assertTrue(BootstrapChecks.enforceLimits(boundTransportAddress));
}
use of org.elasticsearch.common.transport.TransportAddress in project elasticsearch by elastic.
the class BootstrapChecksTests method testEnforceLimitsWhenBoundToNonLocalAddress.
public void testEnforceLimitsWhenBoundToNonLocalAddress() {
final List<TransportAddress> transportAddresses = new ArrayList<>();
final TransportAddress nonLocalTransportAddress = buildNewFakeTransportAddress();
transportAddresses.add(nonLocalTransportAddress);
for (int i = 0; i < randomIntBetween(0, 7); i++) {
final TransportAddress randomTransportAddress = randomBoolean() ? buildNewFakeTransportAddress() : new TransportAddress(InetAddress.getLoopbackAddress(), i);
transportAddresses.add(randomTransportAddress);
}
final TransportAddress publishAddress = randomBoolean() ? buildNewFakeTransportAddress() : new TransportAddress(InetAddress.getLoopbackAddress(), 0);
final BoundTransportAddress boundTransportAddress = mock(BoundTransportAddress.class);
Collections.shuffle(transportAddresses, random());
when(boundTransportAddress.boundAddresses()).thenReturn(transportAddresses.toArray(new TransportAddress[0]));
when(boundTransportAddress.publishAddress()).thenReturn(publishAddress);
assertTrue(BootstrapChecks.enforceLimits(boundTransportAddress));
}
use of org.elasticsearch.common.transport.TransportAddress in project elasticsearch by elastic.
the class BootstrapChecksTests method testNonProductionMode.
public void testNonProductionMode() throws NodeValidationException {
// nothing should happen since we are in non-production mode
final List<TransportAddress> transportAddresses = new ArrayList<>();
for (int i = 0; i < randomIntBetween(1, 8); i++) {
TransportAddress localTransportAddress = new TransportAddress(InetAddress.getLoopbackAddress(), i);
transportAddresses.add(localTransportAddress);
}
TransportAddress publishAddress = new TransportAddress(InetAddress.getLoopbackAddress(), 0);
BoundTransportAddress boundTransportAddress = mock(BoundTransportAddress.class);
when(boundTransportAddress.boundAddresses()).thenReturn(transportAddresses.toArray(new TransportAddress[0]));
when(boundTransportAddress.publishAddress()).thenReturn(publishAddress);
BootstrapChecks.check(Settings.EMPTY, boundTransportAddress, Collections.emptyList());
}
use of org.elasticsearch.common.transport.TransportAddress in project elasticsearch by elastic.
the class Netty4HttpServerTransport method createBoundHttpAddress.
private BoundTransportAddress createBoundHttpAddress() {
// Bind and start to accept incoming connections.
InetAddress[] hostAddresses;
try {
hostAddresses = networkService.resolveBindHostAddresses(bindHosts);
} catch (IOException e) {
throw new BindHttpException("Failed to resolve host [" + Arrays.toString(bindHosts) + "]", e);
}
List<TransportAddress> boundAddresses = new ArrayList<>(hostAddresses.length);
for (InetAddress address : hostAddresses) {
boundAddresses.add(bindAddress(address));
}
final InetAddress publishInetAddress;
try {
publishInetAddress = networkService.resolvePublishHostAddresses(publishHosts);
} catch (Exception e) {
throw new BindTransportException("Failed to resolve publish address", e);
}
final int publishPort = resolvePublishPort(settings, boundAddresses, publishInetAddress);
final InetSocketAddress publishAddress = new InetSocketAddress(publishInetAddress, publishPort);
return new BoundTransportAddress(boundAddresses.toArray(new TransportAddress[0]), new TransportAddress(publishAddress));
}
use of org.elasticsearch.common.transport.TransportAddress in project elasticsearch by elastic.
the class Netty4HttpServerTransportTests method testBindUnavailableAddress.
public void testBindUnavailableAddress() {
try (Netty4HttpServerTransport transport = new Netty4HttpServerTransport(Settings.EMPTY, networkService, bigArrays, threadPool, xContentRegistry(), new NullDispatcher())) {
transport.start();
TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses());
Settings settings = Settings.builder().put("http.port", remoteAddress.getPort()).build();
try (Netty4HttpServerTransport otherTransport = new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry(), new NullDispatcher())) {
BindHttpException bindHttpException = expectThrows(BindHttpException.class, () -> otherTransport.start());
assertEquals("Failed to bind to [" + remoteAddress.getPort() + "]", bindHttpException.getMessage());
}
}
}
Aggregations