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))));
}
}
}
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))));
}
}
}
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);
}
Aggregations