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