Search in sources :

Example 31 with NamedWriteableRegistry

use of org.opensearch.common.io.stream.NamedWriteableRegistry in project OpenSearch by opensearch-project.

the class SeedHostsResolverTests method testCancellationOnClose.

public void testCancellationOnClose() throws InterruptedException {
    final NetworkService networkService = new NetworkService(Collections.emptyList());
    final CountDownLatch latch = new CountDownLatch(1);
    final CountDownLatch conditionLatch = new CountDownLatch(1);
    final Transport transport = new MockNioTransport(Settings.EMPTY, Version.CURRENT, threadPool, networkService, PageCacheRecycler.NON_RECYCLING_INSTANCE, new NamedWriteableRegistry(Collections.emptyList()), new NoneCircuitBreakerService()) {

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

        @Override
        public TransportAddress[] addressesFromString(String address) throws UnknownHostException {
            if ("hostname1".equals(address)) {
                return new TransportAddress[] { new TransportAddress(TransportAddress.META_ADDRESS, 9300) };
            } else if ("hostname2".equals(address)) {
                try {
                    conditionLatch.countDown();
                    latch.await();
                    throw new AssertionError("should never be called");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            } else {
                throw new UnknownHostException(address);
            }
        }
    };
    closeables.push(transport);
    final TransportService transportService = new TransportService(Settings.EMPTY, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> null, null, Collections.emptySet());
    closeables.push(transportService);
    recreateSeedHostsResolver(transportService, Settings.builder().put(SeedHostsResolver.DISCOVERY_SEED_RESOLVER_TIMEOUT_SETTING.getKey(), "10m").build());
    final PlainActionFuture<List<TransportAddress>> fut = new PlainActionFuture<>();
    threadPool.generic().execute((() -> fut.onResponse(seedHostsResolver.resolveHosts(Arrays.asList("hostname1", "hostname2")))));
    conditionLatch.await();
    seedHostsResolver.stop();
    assertThat(FutureUtils.get(fut, 10, TimeUnit.SECONDS), hasSize(0));
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) UnknownHostException(java.net.UnknownHostException) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) TransportAddress(org.opensearch.common.transport.TransportAddress) CountDownLatch(java.util.concurrent.CountDownLatch) TransportService(org.opensearch.transport.TransportService) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) NetworkService(org.opensearch.common.network.NetworkService) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) List(java.util.List) ArrayList(java.util.ArrayList) Transport(org.opensearch.transport.Transport) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Example 32 with NamedWriteableRegistry

use of org.opensearch.common.io.stream.NamedWriteableRegistry in project OpenSearch by opensearch-project.

the class SeedHostsResolverTests method testRemovingLocalAddresses.

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

        @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, Collections.emptySet());
    closeables.push(transportService);
    final List<TransportAddress> transportAddresses = SeedHostsResolver.resolveHostsLists(new CancellableThreads(), executorService, logger, IntStream.range(9300, 9310).mapToObj(port -> NetworkAddress.format(loopbackAddress) + ":" + port).collect(Collectors.toList()), transportService, TimeValue.timeValueSeconds(30));
    assertThat(transportAddresses, hasSize(7));
    final Set<Integer> ports = new HashSet<>();
    for (final TransportAddress address : transportAddresses) {
        assertTrue(address.address().getAddress().isLoopbackAddress());
        ports.add(address.getPort());
    }
    assertThat(ports, equalTo(IntStream.range(9303, 9310).mapToObj(m -> m).collect(Collectors.toSet())));
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) Arrays(java.util.Arrays) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) FutureUtils(org.opensearch.common.util.concurrent.FutureUtils) Transport(org.opensearch.transport.Transport) InetAddress(java.net.InetAddress) IsNull.nullValue(org.hamcrest.core.IsNull.nullValue) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) After(org.junit.After) ThreadFactory(java.util.concurrent.ThreadFactory) TimeValue(org.opensearch.common.unit.TimeValue) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) TransportService(org.opensearch.transport.TransportService) Collectors(java.util.stream.Collectors) TransportAddress(org.opensearch.common.transport.TransportAddress) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) CancellableThreads(org.opensearch.common.util.CancellableThreads) IntStream(java.util.stream.IntStream) ThreadPool(org.opensearch.threadpool.ThreadPool) OpenSearchExecutors(org.opensearch.common.util.concurrent.OpenSearchExecutors) AtomicReference(java.util.concurrent.atomic.AtomicReference) Stack(java.util.Stack) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) NetworkAddress(org.opensearch.common.network.NetworkAddress) Matchers.empty(org.hamcrest.Matchers.empty) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) UnknownHostException(java.net.UnknownHostException) Mockito.verify(org.mockito.Mockito.verify) IOUtils(org.opensearch.core.internal.io.IOUtils) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) Closeable(java.io.Closeable) NetworkService(org.opensearch.common.network.NetworkService) Collections(java.util.Collections) PageCacheRecycler(org.opensearch.common.util.PageCacheRecycler) CancellableThreads(org.opensearch.common.util.CancellableThreads) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) TransportAddress(org.opensearch.common.transport.TransportAddress) TransportService(org.opensearch.transport.TransportService) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) NetworkService(org.opensearch.common.network.NetworkService) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) Transport(org.opensearch.transport.Transport) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) InetAddress(java.net.InetAddress) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) HashSet(java.util.HashSet)

Example 33 with NamedWriteableRegistry

use of org.opensearch.common.io.stream.NamedWriteableRegistry in project OpenSearch by opensearch-project.

the class ShardValidateQueryRequestTests method setUp.

public void setUp() throws Exception {
    super.setUp();
    IndicesModule indicesModule = new IndicesModule(Collections.emptyList());
    SearchModule searchModule = new SearchModule(Settings.EMPTY, Collections.emptyList());
    List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
    entries.addAll(indicesModule.getNamedWriteables());
    entries.addAll(searchModule.getNamedWriteables());
    namedWriteableRegistry = new NamedWriteableRegistry(entries);
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) IndicesModule(org.opensearch.indices.IndicesModule) ArrayList(java.util.ArrayList) SearchModule(org.opensearch.search.SearchModule)

Example 34 with NamedWriteableRegistry

use of org.opensearch.common.io.stream.NamedWriteableRegistry in project OpenSearch by opensearch-project.

the class BroadcastReplicationTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    MockNioTransport transport = new MockNioTransport(Settings.EMPTY, Version.CURRENT, threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, new NamedWriteableRegistry(Collections.emptyList()), circuitBreakerService);
    clusterService = createClusterService(threadPool);
    transportService = new TransportService(clusterService.getSettings(), transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null, Collections.emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    broadcastReplicationAction = new TestBroadcastReplicationAction(clusterService, transportService, new ActionFilters(new HashSet<>()), new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), null);
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) Date(java.util.Date) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ConcurrentCollections(org.opensearch.common.util.concurrent.ConcurrentCollections) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) After(org.junit.After) ActionListener(org.opensearch.action.ActionListener) UnavailableShardsException(org.opensearch.action.UnavailableShardsException) AfterClass(org.junit.AfterClass) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) Task(org.opensearch.tasks.Task) RestStatus(org.opensearch.rest.RestStatus) ClusterStateCreationUtils.state(org.opensearch.action.support.replication.ClusterStateCreationUtils.state) TransportService(org.opensearch.transport.TransportService) Tuple(org.opensearch.common.collect.Tuple) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ActionFilters(org.opensearch.action.support.ActionFilters) List(java.util.List) ActionTestUtils(org.opensearch.action.support.ActionTestUtils) Matchers.equalTo(org.hamcrest.Matchers.equalTo) BroadcastResponse(org.opensearch.action.support.broadcast.BroadcastResponse) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) FlushResponse(org.opensearch.action.admin.indices.flush.FlushResponse) BroadcastRequest(org.opensearch.action.support.broadcast.BroadcastRequest) BeforeClass(org.junit.BeforeClass) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) ThreadPool(org.opensearch.threadpool.ThreadPool) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) ClusterStateCreationUtils.stateWithAssignedPrimariesAndOneReplica(org.opensearch.action.support.replication.ClusterStateCreationUtils.stateWithAssignedPrimariesAndOneReplica) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) TransportFlushAction(org.opensearch.action.admin.indices.flush.TransportFlushAction) IOException(java.io.IOException) IOUtils(org.opensearch.core.internal.io.IOUtils) ShardId(org.opensearch.index.shard.ShardId) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ClusterStateCreationUtils.stateWithNoShard(org.opensearch.action.support.replication.ClusterStateCreationUtils.stateWithNoShard) CircuitBreakerService(org.opensearch.indices.breaker.CircuitBreakerService) ClusterService(org.opensearch.cluster.service.ClusterService) NetworkService(org.opensearch.common.network.NetworkService) NoShardAvailableActionException(org.opensearch.action.NoShardAvailableActionException) Collections(java.util.Collections) PageCacheRecycler(org.opensearch.common.util.PageCacheRecycler) TransportService(org.opensearch.transport.TransportService) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) NetworkService(org.opensearch.common.network.NetworkService) ActionFilters(org.opensearch.action.support.ActionFilters) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Before(org.junit.Before)

Example 35 with NamedWriteableRegistry

use of org.opensearch.common.io.stream.NamedWriteableRegistry in project OpenSearch by opensearch-project.

the class MetadataTests method testSerializationWithIndexGraveyard.

public void testSerializationWithIndexGraveyard() throws IOException {
    final IndexGraveyard graveyard = IndexGraveyardTests.createRandom();
    final Metadata originalMeta = Metadata.builder().indexGraveyard(graveyard).build();
    final BytesStreamOutput out = new BytesStreamOutput();
    originalMeta.writeTo(out);
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(ClusterModule.getNamedWriteables());
    final Metadata fromStreamMeta = Metadata.readFrom(new NamedWriteableAwareStreamInput(out.bytes().streamInput(), namedWriteableRegistry));
    assertThat(fromStreamMeta.indexGraveyard(), equalTo(fromStreamMeta.indexGraveyard()));
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Aggregations

NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)117 ThreadPool (org.opensearch.threadpool.ThreadPool)41 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)37 ClusterService (org.opensearch.cluster.service.ClusterService)37 TestThreadPool (org.opensearch.threadpool.TestThreadPool)37 AsynchronousSearchActiveStore (org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveStore)33 InternalAsynchronousSearchStats (org.opensearch.search.asynchronous.stats.InternalAsynchronousSearchStats)32 SubmitAsynchronousSearchRequest (org.opensearch.search.asynchronous.request.SubmitAsynchronousSearchRequest)30 TimeValue (org.opensearch.common.unit.TimeValue)29 SearchRequest (org.opensearch.action.search.SearchRequest)28 CountDownLatch (java.util.concurrent.CountDownLatch)26 User (org.opensearch.commons.authuser.User)24 AsynchronousSearchActiveContext (org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveContext)23 AsynchronousSearchTask (org.opensearch.search.asynchronous.task.AsynchronousSearchTask)22 NamedWriteableAwareStreamInput (org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)21 SearchModule (org.opensearch.search.SearchModule)20 StreamInput (org.opensearch.common.io.stream.StreamInput)19 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)18 ArrayList (java.util.ArrayList)16 Version (org.opensearch.Version)16