Search in sources :

Example 11 with NamedWriteableRegistry

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

the class SearchSortValuesAndFormatsTests method initRegistry.

@Before
public void initRegistry() {
    SearchModule searchModule = new SearchModule(Settings.EMPTY, Collections.emptyList());
    List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
    entries.addAll(searchModule.getNamedWriteables());
    namedWriteableRegistry = new NamedWriteableRegistry(entries);
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 12 with NamedWriteableRegistry

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

the class DocValueFormatTests method testSerialization.

public void testSerialization() throws Exception {
    List<Entry> entries = new ArrayList<>();
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.BOOLEAN.getWriteableName(), in -> DocValueFormat.BOOLEAN));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.DateTime.NAME, DocValueFormat.DateTime::new));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.Decimal.NAME, DocValueFormat.Decimal::new));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.GEOHASH.getWriteableName(), in -> DocValueFormat.GEOHASH));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.GEOTILE.getWriteableName(), in -> DocValueFormat.GEOTILE));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.IP.getWriteableName(), in -> DocValueFormat.IP));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.RAW.getWriteableName(), in -> DocValueFormat.RAW));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.BINARY.getWriteableName(), in -> DocValueFormat.BINARY));
    NamedWriteableRegistry registry = new NamedWriteableRegistry(entries);
    BytesStreamOutput out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.BOOLEAN);
    StreamInput in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.BOOLEAN, in.readNamedWriteable(DocValueFormat.class));
    DocValueFormat.Decimal decimalFormat = new DocValueFormat.Decimal("###.##");
    out = new BytesStreamOutput();
    out.writeNamedWriteable(decimalFormat);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    DocValueFormat vf = in.readNamedWriteable(DocValueFormat.class);
    assertEquals(DocValueFormat.Decimal.class, vf.getClass());
    assertEquals("###.##", ((DocValueFormat.Decimal) vf).pattern);
    DateFormatter formatter = DateFormatter.forPattern("epoch_second");
    DocValueFormat.DateTime dateFormat = new DocValueFormat.DateTime(formatter, ZoneOffset.ofHours(1), Resolution.MILLISECONDS);
    out = new BytesStreamOutput();
    out.writeNamedWriteable(dateFormat);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    vf = in.readNamedWriteable(DocValueFormat.class);
    assertEquals(DocValueFormat.DateTime.class, vf.getClass());
    assertEquals("epoch_second", ((DocValueFormat.DateTime) vf).formatter.pattern());
    assertEquals(ZoneOffset.ofHours(1), ((DocValueFormat.DateTime) vf).timeZone);
    assertEquals(Resolution.MILLISECONDS, ((DocValueFormat.DateTime) vf).resolution);
    DocValueFormat.DateTime nanosDateFormat = new DocValueFormat.DateTime(formatter, ZoneOffset.ofHours(1), Resolution.NANOSECONDS);
    out = new BytesStreamOutput();
    out.writeNamedWriteable(nanosDateFormat);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    vf = in.readNamedWriteable(DocValueFormat.class);
    assertEquals(DocValueFormat.DateTime.class, vf.getClass());
    assertEquals("epoch_second", ((DocValueFormat.DateTime) vf).formatter.pattern());
    assertEquals(ZoneOffset.ofHours(1), ((DocValueFormat.DateTime) vf).timeZone);
    assertEquals(Resolution.NANOSECONDS, ((DocValueFormat.DateTime) vf).resolution);
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.GEOHASH);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.GEOHASH, in.readNamedWriteable(DocValueFormat.class));
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.GEOTILE);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.GEOTILE, in.readNamedWriteable(DocValueFormat.class));
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.IP);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.IP, in.readNamedWriteable(DocValueFormat.class));
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.RAW);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.RAW, in.readNamedWriteable(DocValueFormat.class));
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.BINARY);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.BINARY, in.readNamedWriteable(DocValueFormat.class));
}
Also used : StreamInput(org.opensearch.common.io.stream.StreamInput) InetAddresses(org.opensearch.common.network.InetAddresses) InetAddressPoint(org.apache.lucene.document.InetAddressPoint) BytesRef(org.apache.lucene.util.BytesRef) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Resolution(org.opensearch.index.mapper.DateFieldMapper.Resolution) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) Entry(org.opensearch.common.io.stream.NamedWriteableRegistry.Entry) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ArrayList(java.util.ArrayList) List(java.util.List) ZoneOffset(java.time.ZoneOffset) DateFormatter(org.opensearch.common.time.DateFormatter) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) GeoTileUtils.longEncode(org.opensearch.search.aggregations.bucket.geogrid.GeoTileUtils.longEncode) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ArrayList(java.util.ArrayList) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) Entry(org.opensearch.common.io.stream.NamedWriteableRegistry.Entry) StreamInput(org.opensearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) DateFormatter(org.opensearch.common.time.DateFormatter) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)

Example 13 with NamedWriteableRegistry

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

the class GeoTileGridTests method testSerializationPreBounds.

public void testSerializationPreBounds() throws Exception {
    Version noBoundsSupportVersion = VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, LegacyESVersion.V_7_5_0);
    GeoTileGridAggregationBuilder 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);
            GeoTileGridAggregationBuilder readBuilder = new GeoTileGridAggregationBuilder(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) GeoTileGridAggregationBuilder(org.opensearch.search.aggregations.bucket.geogrid.GeoTileGridAggregationBuilder) 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)

Example 14 with NamedWriteableRegistry

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

the class AggregatorFactoriesBuilderTests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    // register aggregations as NamedWriteable
    SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    namedXContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) Before(org.junit.Before)

Example 15 with NamedWriteableRegistry

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

the class CollapseBuilderTests method init.

@BeforeClass
public static void init() {
    SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) BeforeClass(org.junit.BeforeClass)

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