Search in sources :

Example 11 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project elasticsearch by elastic.

the class Netty4SizeHeaderFrameDecoderTests method startThreadPool.

@Before
public void startThreadPool() {
    threadPool = new ThreadPool(settings);
    NetworkService networkService = new NetworkService(settings, Collections.emptyList());
    BigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
    nettyTransport = new Netty4Transport(settings, threadPool, networkService, bigArrays, new NamedWriteableRegistry(Collections.emptyList()), new NoneCircuitBreakerService());
    nettyTransport.start();
    TransportAddress[] boundAddresses = nettyTransport.boundAddress().boundAddresses();
    TransportAddress transportAddress = (TransportAddress) randomFrom(boundAddresses);
    port = transportAddress.address().getPort();
    host = transportAddress.address().getAddress();
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) BigArrays(org.elasticsearch.common.util.BigArrays) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) TransportAddress(org.elasticsearch.common.transport.TransportAddress) ThreadPool(org.elasticsearch.threadpool.ThreadPool) NetworkService(org.elasticsearch.common.network.NetworkService) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 12 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project elasticsearch by elastic.

the class Ec2DiscoveryTests method createTransportService.

@Before
public void createTransportService() {
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    final Transport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(Settings.EMPTY, Collections.emptyList()), Version.CURRENT) {

        @Override
        public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws UnknownHostException {
            // we just need to ensure we don't resolve DNS here
            return new TransportAddress[] { poorMansDNS.getOrDefault(address, buildNewFakeTransportAddress()) };
        }
    };
    transportService = new MockTransportService(Settings.EMPTY, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, null);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportAddress(org.elasticsearch.common.transport.TransportAddress) NetworkService(org.elasticsearch.common.network.NetworkService) Matchers.containsString(org.hamcrest.Matchers.containsString) Transport(org.elasticsearch.transport.Transport) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 13 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project elasticsearch by elastic.

the class FileBasedUnicastHostsProviderTests method createTransportSvc.

@Before
public void createTransportSvc() {
    MockTcpTransport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), new NamedWriteableRegistry(Collections.emptyList()), new NetworkService(Settings.EMPTY, Collections.emptyList())) {

        @Override
        public BoundTransportAddress boundAddress() {
            return new BoundTransportAddress(new TransportAddress[] { new TransportAddress(InetAddress.getLoopbackAddress(), 9300) }, new TransportAddress(InetAddress.getLoopbackAddress(), 9300));
        }
    };
    transportService = new MockTransportService(Settings.EMPTY, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, null);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) MockTransportService(org.elasticsearch.test.transport.MockTransportService) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) NetworkService(org.elasticsearch.common.network.NetworkService) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 14 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project elasticsearch by elastic.

the class ZenDiscoveryUnitTests method buildZenDiscovery.

private ZenDiscovery buildZenDiscovery(Settings settings, TransportService service, ClusterService clusterService, ThreadPool threadPool) {
    ZenDiscovery zenDiscovery = new ZenDiscovery(settings, threadPool, service, new NamedWriteableRegistry(ClusterModule.getNamedWriteables()), clusterService, Collections::emptyList);
    zenDiscovery.start();
    return zenDiscovery;
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Collections(java.util.Collections)

Example 15 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project elasticsearch by elastic.

the class UnicastZenPingTests method testPingingTemporalPings.

public void testPingingTemporalPings() throws ExecutionException, InterruptedException {
    final Settings settings = Settings.builder().put("cluster.name", "test").put(TransportSettings.PORT.getKey(), 0).build();
    NetworkService networkService = new NetworkService(settings, Collections.emptyList());
    final BiFunction<Settings, Version, Transport> supplier = (s, v) -> new MockTcpTransport(s, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), new NamedWriteableRegistry(Collections.emptyList()), networkService, v);
    NetworkHandle handleA = startServices(settings, threadPool, "UZP_A", Version.CURRENT, supplier, EnumSet.allOf(Role.class));
    closeables.push(handleA.transportService);
    NetworkHandle handleB = startServices(settings, threadPool, "UZP_B", Version.CURRENT, supplier, EnumSet.allOf(Role.class));
    closeables.push(handleB.transportService);
    final Settings hostsSettings = Settings.builder().put("cluster.name", "test").put("discovery.zen.ping.unicast.hosts", // use nodes for simplicity
    (String) null).build();
    final ClusterState state = ClusterState.builder(new ClusterName("test")).version(randomNonNegativeLong()).build();
    final TestUnicastZenPing zenPingA = new TestUnicastZenPing(hostsSettings, threadPool, handleA, EMPTY_HOSTS_PROVIDER);
    zenPingA.start(new PingContextProvider() {

        @Override
        public DiscoveryNodes nodes() {
            return DiscoveryNodes.builder().add(handleA.node).add(handleB.node).localNodeId("UZP_A").build();
        }

        @Override
        public ClusterState clusterState() {
            return ClusterState.builder(state).blocks(ClusterBlocks.builder().addGlobalBlock(STATE_NOT_RECOVERED_BLOCK)).build();
        }
    });
    closeables.push(zenPingA);
    // Node B doesn't know about A!
    TestUnicastZenPing zenPingB = new TestUnicastZenPing(hostsSettings, threadPool, handleB, EMPTY_HOSTS_PROVIDER);
    zenPingB.start(new PingContextProvider() {

        @Override
        public DiscoveryNodes nodes() {
            return DiscoveryNodes.builder().add(handleB.node).localNodeId("UZP_B").build();
        }

        @Override
        public ClusterState clusterState() {
            return state;
        }
    });
    closeables.push(zenPingB);
    {
        logger.info("pinging from UZP_A so UZP_B will learn about it");
        Collection<ZenPing.PingResponse> pingResponses = zenPingA.pingAndWait().toList();
        assertThat(pingResponses.size(), equalTo(1));
        ZenPing.PingResponse ping = pingResponses.iterator().next();
        assertThat(ping.node().getId(), equalTo("UZP_B"));
        assertThat(ping.getClusterStateVersion(), equalTo(state.version()));
    }
    {
        logger.info("pinging from UZP_B");
        Collection<ZenPing.PingResponse> pingResponses = zenPingB.pingAndWait().toList();
        assertThat(pingResponses.size(), equalTo(1));
        ZenPing.PingResponse ping = pingResponses.iterator().next();
        assertThat(ping.node().getId(), equalTo("UZP_A"));
        // A has a block
        assertThat(ping.getClusterStateVersion(), equalTo(-1L));
    }
}
Also used : 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) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) ClusterState(org.elasticsearch.cluster.ClusterState) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) Role(org.elasticsearch.cluster.node.DiscoveryNode.Role) Version(org.elasticsearch.Version) NetworkService(org.elasticsearch.common.network.NetworkService) ClusterName(org.elasticsearch.cluster.ClusterName) Collection(java.util.Collection) Transport(org.elasticsearch.transport.Transport) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) Settings(org.elasticsearch.common.settings.Settings) TransportSettings(org.elasticsearch.transport.TransportSettings) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Aggregations

NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)71 NetworkService (org.elasticsearch.common.network.NetworkService)27 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)25 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)23 Settings (org.elasticsearch.common.settings.Settings)21 ThreadPool (org.elasticsearch.threadpool.ThreadPool)19 ArrayList (java.util.ArrayList)18 MockTransportService (org.elasticsearch.test.transport.MockTransportService)18 Transport (org.elasticsearch.transport.Transport)18 IOException (java.io.IOException)15 Collections (java.util.Collections)15 TransportAddress (org.elasticsearch.common.transport.TransportAddress)15 BigArrays (org.elasticsearch.common.util.BigArrays)15 SearchModule (org.elasticsearch.search.SearchModule)15 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)15 MockTcpTransport (org.elasticsearch.transport.MockTcpTransport)15 NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)14 TransportService (org.elasticsearch.transport.TransportService)14 List (java.util.List)13 ESTestCase (org.elasticsearch.test.ESTestCase)13