Search in sources :

Example 41 with NamedWriteableAwareStreamInput

use of org.opensearch.common.io.stream.NamedWriteableAwareStreamInput 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)

Example 42 with NamedWriteableAwareStreamInput

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

the class GeoTileGridValuesSourceBuilderTests method testBWCBounds.

public void testBWCBounds() throws IOException {
    Version noBoundsSupportVersion = VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, LegacyESVersion.V_7_5_0);
    GeoTileGridValuesSourceBuilder builder = new GeoTileGridValuesSourceBuilder("name");
    if (randomBoolean()) {
        builder.geoBoundingBox(GeoBoundingBoxTests.randomBBox());
    }
    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);
            GeoTileGridValuesSourceBuilder readBuilder = new GeoTileGridValuesSourceBuilder(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) 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 43 with NamedWriteableAwareStreamInput

use of org.opensearch.common.io.stream.NamedWriteableAwareStreamInput 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)

Aggregations

NamedWriteableAwareStreamInput (org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)43 StreamInput (org.opensearch.common.io.stream.StreamInput)37 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)32 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)21 Version (org.opensearch.Version)11 InputStreamStreamInput (org.opensearch.common.io.stream.InputStreamStreamInput)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)5 QueryBuilder (org.opensearch.index.query.QueryBuilder)5 SearchModule (org.opensearch.search.SearchModule)5 InputStream (java.io.InputStream)4 BytesRef (org.apache.lucene.util.BytesRef)4 ClusterState (org.opensearch.cluster.ClusterState)4 BytesReference (org.opensearch.common.bytes.BytesReference)4 AliasFilter (org.opensearch.search.internal.AliasFilter)4 ArrayList (java.util.ArrayList)3 LegacyESVersion (org.opensearch.LegacyESVersion)3 ShardId (org.opensearch.index.shard.ShardId)3 HashMap (java.util.HashMap)2