Search in sources :

Example 96 with NamedWriteableRegistry

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

the class AnomalyLocalizationInputTests method testWriteable.

@Test
public void testWriteable() throws Exception {
    AnomalyLocalizationInput input = new AnomalyLocalizationInput("indexName", Arrays.asList("attribute"), Arrays.asList(AggregationBuilders.max("max").field("field"), AggregationBuilders.min("min").field("field")), "@timestamp", 0L, 10L, 1L, 2, Optional.of(3L), Optional.of(QueryBuilders.matchAllQuery()));
    BytesStreamOutput out = new BytesStreamOutput();
    input.writeTo(out);
    StreamInput in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), new NamedWriteableRegistry(new SearchModule(Settings.EMPTY, false, Collections.emptyList()).getNamedWriteables()));
    AnomalyLocalizationInput newInput = new AnomalyLocalizationInput(in);
    assertEquals(input, newInput);
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) StreamInput(org.opensearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) SearchModule(org.opensearch.search.SearchModule) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 97 with NamedWriteableRegistry

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

the class FileBasedSeedHostsProviderTests method createTransportSvc.

private void createTransportSvc() {
    final MockNioTransport transport = new MockNioTransport(Settings.EMPTY, Version.CURRENT, threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, new NamedWriteableRegistry(Collections.emptyList()), new NoneCircuitBreakerService()) {

        @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.opensearch.common.io.stream.NamedWriteableRegistry) MockTransportService(org.opensearch.test.transport.MockTransportService) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) TransportAddress(org.opensearch.common.transport.TransportAddress) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) NetworkService(org.opensearch.common.network.NetworkService) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Example 98 with NamedWriteableRegistry

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

the class SeedHostsResolverTests method testResolveTimeout.

public void testResolveTimeout() {
    final Logger logger = mock(Logger.class);
    final NetworkService networkService = new NetworkService(Collections.emptyList());
    final CountDownLatch latch = 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 {
                    latch.await();
                    return new TransportAddress[] { new TransportAddress(TransportAddress.META_ADDRESS, 9300) };
                } 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);
    final TimeValue resolveTimeout = TimeValue.timeValueSeconds(randomIntBetween(3, 5));
    try {
        final List<TransportAddress> transportAddresses = SeedHostsResolver.resolveHostsLists(new CancellableThreads(), executorService, logger, Arrays.asList("hostname1", "hostname2"), transportService, resolveTimeout);
        assertThat(transportAddresses, hasSize(1));
        verify(logger).trace("resolved host [{}] to {}", "hostname1", new TransportAddress[] { new TransportAddress(TransportAddress.META_ADDRESS, 9300) });
        verify(logger).warn("timed out after [{}] resolving host [{}]", resolveTimeout, "hostname2");
        verifyNoMoreInteractions(logger);
    } finally {
        latch.countDown();
    }
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) CancellableThreads(org.opensearch.common.util.CancellableThreads) UnknownHostException(java.net.UnknownHostException) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) TransportAddress(org.opensearch.common.transport.TransportAddress) Logger(org.apache.logging.log4j.Logger) CountDownLatch(java.util.concurrent.CountDownLatch) 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) TimeValue(org.opensearch.common.unit.TimeValue) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Example 99 with NamedWriteableRegistry

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

the class DiscoveryModuleTests method setupDummyServices.

@Before
public void setupDummyServices() {
    threadPool = mock(ThreadPool.class);
    when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
    transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null);
    masterService = mock(MasterService.class);
    namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    clusterApplier = mock(ClusterApplier.class);
    clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    gatewayMetaState = mock(GatewayMetaState.class);
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ThreadPool(org.opensearch.threadpool.ThreadPool) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClusterApplier(org.opensearch.cluster.service.ClusterApplier) MasterService(org.opensearch.cluster.service.MasterService) GatewayMetaState(org.opensearch.gateway.GatewayMetaState) Before(org.junit.Before)

Example 100 with NamedWriteableRegistry

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

the class GeoHashGridTests method testSerializationPreBounds.

public void testSerializationPreBounds() throws Exception {
    Version noBoundsSupportVersion = VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, LegacyESVersion.V_7_5_0);
    GeoHashGridAggregationBuilder builder = createTestAggregatorBuilder();
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        output.setVersion(LegacyESVersion.V_7_6_0);
        builder.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), new NamedWriteableRegistry(Collections.emptyList()))) {
            in.setVersion(noBoundsSupportVersion);
            GeoHashGridAggregationBuilder readBuilder = new GeoHashGridAggregationBuilder(in);
            assertThat(readBuilder.geoBoundingBox(), equalTo(new GeoBoundingBox(new GeoPoint(Double.NaN, Double.NaN), new GeoPoint(Double.NaN, Double.NaN))));
        }
    }
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) GeoPoint(org.opensearch.common.geo.GeoPoint) GeoHashGridAggregationBuilder(org.opensearch.search.aggregations.bucket.geogrid.GeoHashGridAggregationBuilder) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) StreamInput(org.opensearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) GeoBoundingBox(org.opensearch.common.geo.GeoBoundingBox) 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