Search in sources :

Example 26 with NamedWriteableAwareStreamInput

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

the class AnomalyResultTests method testSerializeAnomalyResultWithoutUser.

public void testSerializeAnomalyResultWithoutUser() throws IOException {
    AnomalyResult detectResult = TestHelpers.randomAnomalyDetectResult(0.8, randomAlphaOfLength(5), randomAlphaOfLength(5), false);
    BytesStreamOutput output = new BytesStreamOutput();
    detectResult.writeTo(output);
    NamedWriteableAwareStreamInput input = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), writableRegistry());
    AnomalyResult parsedDetectResult = new AnomalyResult(input);
    assertTrue(parsedDetectResult.equals(detectResult));
}
Also used : NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 27 with NamedWriteableAwareStreamInput

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

the class AnomalyResultTests method testSerializeAnomalyResult.

public void testSerializeAnomalyResult() throws IOException {
    AnomalyResult detectResult = TestHelpers.randomAnomalyDetectResult(0.8, randomAlphaOfLength(5), randomAlphaOfLength(5));
    BytesStreamOutput output = new BytesStreamOutput();
    detectResult.writeTo(output);
    NamedWriteableAwareStreamInput input = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), writableRegistry());
    AnomalyResult parsedDetectResult = new AnomalyResult(input);
    assertTrue(parsedDetectResult.equals(detectResult));
}
Also used : NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 28 with NamedWriteableAwareStreamInput

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

the class AnomalyResultTests method testSerializeAnomalyResultWithEntity.

public void testSerializeAnomalyResultWithEntity() throws IOException {
    AnomalyResult detectResult = TestHelpers.randomHCADAnomalyDetectResult(0.8, 0.5);
    BytesStreamOutput output = new BytesStreamOutput();
    detectResult.writeTo(output);
    NamedWriteableAwareStreamInput input = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), writableRegistry());
    AnomalyResult parsedDetectResult = new AnomalyResult(input);
    assertTrue(parsedDetectResult.equals(detectResult));
}
Also used : NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 29 with NamedWriteableAwareStreamInput

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

the class DetectionDateRangeTests method testSerializeDetectoinDateRange.

public void testSerializeDetectoinDateRange() throws IOException {
    DetectionDateRange dateRange = TestHelpers.randomDetectionDateRange();
    BytesStreamOutput output = new BytesStreamOutput();
    dateRange.writeTo(output);
    NamedWriteableAwareStreamInput input = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), writableRegistry());
    DetectionDateRange parsedDateRange = new DetectionDateRange(input);
    assertTrue(parsedDateRange.equals(dateRange));
}
Also used : NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 30 with NamedWriteableAwareStreamInput

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

the class PreviewAnomalyDetectorActionTests method testPreviewResponse.

@Test
public void testPreviewResponse() throws Exception {
    BytesStreamOutput out = new BytesStreamOutput();
    AnomalyDetector detector = TestHelpers.randomAnomalyDetector(ImmutableMap.of("testKey", "testValue"), Instant.now());
    AnomalyResult result = TestHelpers.randomHCADAnomalyDetectResult(0.8d, 0d);
    PreviewAnomalyDetectorResponse response = new PreviewAnomalyDetectorResponse(ImmutableList.of(result), detector);
    response.writeTo(out);
    NamedWriteableAwareStreamInput input = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), writableRegistry());
    PreviewAnomalyDetectorResponse newResponse = new PreviewAnomalyDetectorResponse(input);
    Assert.assertNotNull(newResponse.toXContent(TestHelpers.builder(), ToXContent.EMPTY_PARAMS));
}
Also used : NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) AnomalyResult(org.opensearch.ad.model.AnomalyResult) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) Test(org.junit.Test)

Aggregations

NamedWriteableAwareStreamInput (org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)74 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)63 StreamInput (org.opensearch.common.io.stream.StreamInput)37 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)21 Version (org.opensearch.Version)11 Test (org.junit.Test)8 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)8 AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)7 InputStreamStreamInput (org.opensearch.common.io.stream.InputStreamStreamInput)7 ADTask (org.opensearch.ad.model.ADTask)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 QueryBuilder (org.opensearch.index.query.QueryBuilder)5 SearchModule (org.opensearch.search.SearchModule)5 InputStream (java.io.InputStream)4 Map (java.util.Map)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