Search in sources :

Example 6 with Transport

use of org.elasticsearch.transport.Transport in project elasticsearch by elastic.

the class UnicastZenPingTests method testUnknownHost.

public void testUnknownHost() throws InterruptedException {
    final Logger logger = mock(Logger.class);
    final NetworkService networkService = new NetworkService(Settings.EMPTY, Collections.emptyList());
    final String hostname = randomAsciiOfLength(8);
    final UnknownHostException unknownHostException = new UnknownHostException(hostname);
    final Transport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), new NamedWriteableRegistry(Collections.emptyList()), networkService, Version.CURRENT) {

        @Override
        public BoundTransportAddress boundAddress() {
            return new BoundTransportAddress(new TransportAddress[] { new TransportAddress(InetAddress.getLoopbackAddress(), 9300) }, new TransportAddress(InetAddress.getLoopbackAddress(), 9300));
        }

        @Override
        public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws UnknownHostException {
            throw unknownHostException;
        }
    };
    closeables.push(transport);
    final TransportService transportService = new TransportService(Settings.EMPTY, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> null, null);
    closeables.push(transportService);
    final List<DiscoveryNode> discoveryNodes = TestUnicastZenPing.resolveHostsLists(executorService, logger, Arrays.asList(hostname), 1, transportService, "test_", TimeValue.timeValueSeconds(1));
    assertThat(discoveryNodes, empty());
    verify(logger).warn("failed to resolve host [" + hostname + "]", unknownHostException);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) UnknownHostException(java.net.UnknownHostException) TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) Logger(org.apache.logging.log4j.Logger) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) NetworkService(org.elasticsearch.common.network.NetworkService) Transport(org.elasticsearch.transport.Transport) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 7 with Transport

use of org.elasticsearch.transport.Transport in project elasticsearch by elastic.

the class UnicastZenPingTests method testRemovingLocalAddresses.

public void testRemovingLocalAddresses() throws InterruptedException {
    final NetworkService networkService = new NetworkService(Settings.EMPTY, Collections.emptyList());
    final InetAddress loopbackAddress = InetAddress.getLoopbackAddress();
    final Transport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), new NamedWriteableRegistry(Collections.emptyList()), networkService, Version.CURRENT) {

        @Override
        public BoundTransportAddress boundAddress() {
            return new BoundTransportAddress(new TransportAddress[] { new TransportAddress(loopbackAddress, 9300), new TransportAddress(loopbackAddress, 9301) }, new TransportAddress(loopbackAddress, 9302));
        }
    };
    closeables.push(transport);
    final TransportService transportService = new TransportService(Settings.EMPTY, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> null, null);
    closeables.push(transportService);
    final List<DiscoveryNode> discoveryNodes = TestUnicastZenPing.resolveHostsLists(executorService, logger, Collections.singletonList(NetworkAddress.format(loopbackAddress)), 10, transportService, "test_", TimeValue.timeValueSeconds(1));
    assertThat(discoveryNodes, hasSize(7));
    final Set<Integer> ports = new HashSet<>();
    for (final DiscoveryNode discoveryNode : discoveryNodes) {
        assertTrue(discoveryNode.getAddress().address().getAddress().isLoopbackAddress());
        ports.add(discoveryNode.getAddress().getPort());
    }
    assertThat(ports, equalTo(IntStream.range(9303, 9310).mapToObj(m -> m).collect(Collectors.toSet())));
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Arrays(java.util.Arrays) BigArrays(org.elasticsearch.common.util.BigArrays) ConcurrentCollections(org.elasticsearch.common.util.concurrent.ConcurrentCollections) BiFunction(java.util.function.BiFunction) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) InetAddress(java.net.InetAddress) STATE_NOT_RECOVERED_BLOCK(org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK) ClusterState(org.elasticsearch.cluster.ClusterState) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) Settings(org.elasticsearch.common.settings.Settings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ClusterName(org.elasticsearch.cluster.ClusterName) Role(org.elasticsearch.cluster.node.DiscoveryNode.Role) ThreadFactory(java.util.concurrent.ThreadFactory) EnumSet(java.util.EnumSet) Transport(org.elasticsearch.transport.Transport) Collection(java.util.Collection) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractRunnable(org.elasticsearch.common.util.concurrent.AbstractRunnable) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Version(org.elasticsearch.Version) TransportAddress(org.elasticsearch.common.transport.TransportAddress) TransportConnectionListener(org.elasticsearch.transport.TransportConnectionListener) TransportSettings(org.elasticsearch.transport.TransportSettings) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) TransportException(org.elasticsearch.transport.TransportException) NetworkAddress(org.elasticsearch.common.network.NetworkAddress) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) Matchers(org.mockito.Matchers) HashMap(java.util.HashMap) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) AtomicReference(java.util.concurrent.atomic.AtomicReference) CheckedBiConsumer(org.elasticsearch.common.CheckedBiConsumer) Stack(java.util.Stack) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NetworkService(org.elasticsearch.common.network.NetworkService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) TimeValue(org.elasticsearch.common.unit.TimeValue) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ESTestCase(org.elasticsearch.test.ESTestCase) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ConnectionProfile(org.elasticsearch.transport.ConnectionProfile) Collections.emptyMap(java.util.Collections.emptyMap) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Matchers.empty(org.hamcrest.Matchers.empty) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) Collections.emptySet(java.util.Collections.emptySet) IOUtils(org.apache.lucene.util.IOUtils) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) VersionUtils(org.elasticsearch.test.VersionUtils) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Closeable(java.io.Closeable) Collections(java.util.Collections) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) NetworkService(org.elasticsearch.common.network.NetworkService) Transport(org.elasticsearch.transport.Transport) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) InetAddress(java.net.InetAddress) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) HashSet(java.util.HashSet)

Example 8 with Transport

use of org.elasticsearch.transport.Transport in project elasticsearch by elastic.

the class UnicastZenPingTests method testPortLimit.

public void testPortLimit() throws InterruptedException {
    final NetworkService networkService = new NetworkService(Settings.EMPTY, Collections.emptyList());
    final Transport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), new NamedWriteableRegistry(Collections.emptyList()), networkService, Version.CURRENT) {

        @Override
        public BoundTransportAddress boundAddress() {
            return new BoundTransportAddress(new TransportAddress[] { new TransportAddress(InetAddress.getLoopbackAddress(), 9500) }, new TransportAddress(InetAddress.getLoopbackAddress(), 9500));
        }
    };
    closeables.push(transport);
    final TransportService transportService = new TransportService(Settings.EMPTY, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> null, null);
    closeables.push(transportService);
    final int limitPortCounts = randomIntBetween(1, 10);
    final List<DiscoveryNode> discoveryNodes = TestUnicastZenPing.resolveHostsLists(executorService, logger, Collections.singletonList("127.0.0.1"), limitPortCounts, transportService, "test_", TimeValue.timeValueSeconds(1));
    assertThat(discoveryNodes, hasSize(limitPortCounts));
    final Set<Integer> ports = new HashSet<>();
    for (final DiscoveryNode discoveryNode : discoveryNodes) {
        assertTrue(discoveryNode.getAddress().address().getAddress().isLoopbackAddress());
        ports.add(discoveryNode.getAddress().getPort());
    }
    assertThat(ports, equalTo(IntStream.range(9300, 9300 + limitPortCounts).mapToObj(m -> m).collect(Collectors.toSet())));
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Arrays(java.util.Arrays) BigArrays(org.elasticsearch.common.util.BigArrays) ConcurrentCollections(org.elasticsearch.common.util.concurrent.ConcurrentCollections) BiFunction(java.util.function.BiFunction) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) InetAddress(java.net.InetAddress) STATE_NOT_RECOVERED_BLOCK(org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK) ClusterState(org.elasticsearch.cluster.ClusterState) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) Settings(org.elasticsearch.common.settings.Settings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ClusterName(org.elasticsearch.cluster.ClusterName) Role(org.elasticsearch.cluster.node.DiscoveryNode.Role) ThreadFactory(java.util.concurrent.ThreadFactory) EnumSet(java.util.EnumSet) Transport(org.elasticsearch.transport.Transport) Collection(java.util.Collection) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractRunnable(org.elasticsearch.common.util.concurrent.AbstractRunnable) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Version(org.elasticsearch.Version) TransportAddress(org.elasticsearch.common.transport.TransportAddress) TransportConnectionListener(org.elasticsearch.transport.TransportConnectionListener) TransportSettings(org.elasticsearch.transport.TransportSettings) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) TransportException(org.elasticsearch.transport.TransportException) NetworkAddress(org.elasticsearch.common.network.NetworkAddress) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) Matchers(org.mockito.Matchers) HashMap(java.util.HashMap) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) AtomicReference(java.util.concurrent.atomic.AtomicReference) CheckedBiConsumer(org.elasticsearch.common.CheckedBiConsumer) Stack(java.util.Stack) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NetworkService(org.elasticsearch.common.network.NetworkService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) TimeValue(org.elasticsearch.common.unit.TimeValue) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ESTestCase(org.elasticsearch.test.ESTestCase) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ConnectionProfile(org.elasticsearch.transport.ConnectionProfile) Collections.emptyMap(java.util.Collections.emptyMap) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Matchers.empty(org.hamcrest.Matchers.empty) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) Collections.emptySet(java.util.Collections.emptySet) IOUtils(org.apache.lucene.util.IOUtils) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) VersionUtils(org.elasticsearch.test.VersionUtils) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Closeable(java.io.Closeable) Collections(java.util.Collections) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) NetworkService(org.elasticsearch.common.network.NetworkService) Transport(org.elasticsearch.transport.Transport) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) HashSet(java.util.HashSet)

Example 9 with Transport

use of org.elasticsearch.transport.Transport in project elasticsearch by elastic.

the class NetworkModuleTests method testOverrideDefault.

public void testOverrideDefault() {
    Settings settings = Settings.builder().put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom").put(NetworkModule.HTTP_DEFAULT_TYPE_SETTING.getKey(), "default_custom").put(NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.getKey(), "local").put(NetworkModule.TRANSPORT_TYPE_KEY, "default_custom").build();
    // content doesn't matter we check reference equality
    Supplier<Transport> customTransport = () -> null;
    Supplier<HttpServerTransport> custom = FakeHttpTransport::new;
    Supplier<HttpServerTransport> def = FakeHttpTransport::new;
    NetworkModule module = newNetworkModule(settings, false, new NetworkPlugin() {

        @Override
        public Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NetworkService networkService) {
            return Collections.singletonMap("default_custom", customTransport);
        }

        @Override
        public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher) {
            Map<String, Supplier<HttpServerTransport>> supplierMap = new HashMap<>();
            supplierMap.put("custom", custom);
            supplierMap.put("default_custom", def);
            return supplierMap;
        }
    });
    assertSame(custom, module.getHttpServerTransportSupplier());
    assertSame(customTransport, module.getTransportSupplier());
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) NetworkPlugin(org.elasticsearch.plugins.NetworkPlugin) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) BigArrays(org.elasticsearch.common.util.BigArrays) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) Transport(org.elasticsearch.transport.Transport) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HashMap(java.util.HashMap) Map(java.util.Map) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Settings(org.elasticsearch.common.settings.Settings)

Example 10 with Transport

use of org.elasticsearch.transport.Transport in project elasticsearch by elastic.

the class NetworkModuleTests method testRegisterTransport.

public void testRegisterTransport() {
    Settings settings = Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "custom").put(NetworkModule.HTTP_ENABLED.getKey(), false).build();
    // content doesn't matter we check reference equality
    Supplier<Transport> custom = () -> null;
    NetworkPlugin plugin = new NetworkPlugin() {

        @Override
        public Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NetworkService networkService) {
            return Collections.singletonMap("custom", custom);
        }
    };
    NetworkModule module = newNetworkModule(settings, false, plugin);
    assertFalse(module.isTransportClient());
    assertFalse(module.isHttpEnabled());
    assertSame(custom, module.getTransportSupplier());
    // check it works with transport only as well
    module = newNetworkModule(settings, true, plugin);
    assertSame(custom, module.getTransportSupplier());
    assertTrue(module.isTransportClient());
    assertFalse(module.isHttpEnabled());
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) NetworkPlugin(org.elasticsearch.plugins.NetworkPlugin) BigArrays(org.elasticsearch.common.util.BigArrays) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Supplier(java.util.function.Supplier) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) Transport(org.elasticsearch.transport.Transport) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

Transport (org.elasticsearch.transport.Transport)22 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)18 NetworkService (org.elasticsearch.common.network.NetworkService)15 Settings (org.elasticsearch.common.settings.Settings)14 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)14 ThreadPool (org.elasticsearch.threadpool.ThreadPool)14 TransportService (org.elasticsearch.transport.TransportService)14 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)13 TransportAddress (org.elasticsearch.common.transport.TransportAddress)13 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)13 MockTcpTransport (org.elasticsearch.transport.MockTcpTransport)13 BigArrays (org.elasticsearch.common.util.BigArrays)12 MockTransportService (org.elasticsearch.test.transport.MockTransportService)12 Collections (java.util.Collections)11 Logger (org.apache.logging.log4j.Logger)11 BoundTransportAddress (org.elasticsearch.common.transport.BoundTransportAddress)11 UnknownHostException (java.net.UnknownHostException)10 List (java.util.List)10 Map (java.util.Map)10 TimeUnit (java.util.concurrent.TimeUnit)10