Search in sources :

Example 21 with NamedWriteableAwareStreamInput

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

the class ADTaskProfileTests method testADTaskProfileResponse.

private void testADTaskProfileResponse(ADTaskProfileNodeResponse response) throws IOException {
    BytesStreamOutput output = new BytesStreamOutput();
    response.writeTo(output);
    NamedWriteableAwareStreamInput input = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), writableRegistry());
    ADTaskProfileNodeResponse parsedResponse = ADTaskProfileNodeResponse.readNodeResponse(input);
    if (response.getAdTaskProfile() != null) {
        assertTrue(response.getAdTaskProfile().equals(parsedResponse.getAdTaskProfile()));
    } else {
        assertNull(parsedResponse.getAdTaskProfile());
    }
}
Also used : NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 22 with NamedWriteableAwareStreamInput

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

the class ADCancelTaskTests method testADCancelTaskRequest.

public void testADCancelTaskRequest() throws IOException {
    ADCancelTaskRequest request = new ADCancelTaskRequest(randomAlphaOfLength(5), randomAlphaOfLength(5), randomAlphaOfLength(5), randomDiscoveryNode());
    BytesStreamOutput output = new BytesStreamOutput();
    request.writeTo(output);
    NamedWriteableAwareStreamInput input = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), writableRegistry());
    ADCancelTaskRequest parsedRequest = new ADCancelTaskRequest(input);
    assertEquals(request.getDetectorId(), parsedRequest.getDetectorId());
    assertEquals(request.getUserName(), parsedRequest.getUserName());
}
Also used : NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 23 with NamedWriteableAwareStreamInput

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

the class ADTaskTests method testAdTaskSerialization.

public void testAdTaskSerialization() throws IOException {
    ADTask adTask = TestHelpers.randomAdTask(randomAlphaOfLength(5), ADTaskState.STOPPED, Instant.now(), randomAlphaOfLength(5), true);
    BytesStreamOutput output = new BytesStreamOutput();
    adTask.writeTo(output);
    NamedWriteableAwareStreamInput input = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), writableRegistry());
    ADTask parsedADTask = new ADTask(input);
    assertEquals("AD task serialization doesn't work", adTask, parsedADTask);
}
Also used : NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 24 with NamedWriteableAwareStreamInput

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

the class ADTaskTests method testAdTaskSerializationWithNullDetector.

public void testAdTaskSerializationWithNullDetector() throws IOException {
    ADTask adTask = TestHelpers.randomAdTask(randomAlphaOfLength(5), ADTaskState.STOPPED, Instant.now(), randomAlphaOfLength(5), false);
    BytesStreamOutput output = new BytesStreamOutput();
    adTask.writeTo(output);
    NamedWriteableAwareStreamInput input = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), writableRegistry());
    ADTask parsedADTask = new ADTask(input);
    assertEquals("AD task serialization doesn't work", adTask, parsedADTask);
}
Also used : NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 25 with NamedWriteableAwareStreamInput

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

the class AnomalyDetectorSerializationTests method testHCDetector.

public void testHCDetector() throws IOException {
    AnomalyDetector detector = TestHelpers.randomAnomalyDetectorUsingCategoryFields("testId", ImmutableList.of("category_field"));
    BytesStreamOutput output = new BytesStreamOutput();
    detector.writeTo(output);
    NamedWriteableAwareStreamInput input = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), writableRegistry());
    AnomalyDetector parsedDetector = new AnomalyDetector(input);
    assertTrue(parsedDetector.equals(detector));
}
Also used : NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

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