use of org.opensearch.common.io.stream.StreamOutput in project ml-commons by opensearch-project.
the class MLTrainingTaskRequestTest method fromActionRequest_WithNonMLTrainingTaskRequest.
@Test
public void fromActionRequest_WithNonMLTrainingTaskRequest() {
MLTrainingTaskRequest request = MLTrainingTaskRequest.builder().mlInput(mlInput).build();
ActionRequest actionRequest = new ActionRequest() {
@Override
public ActionRequestValidationException validate() {
return null;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
request.writeTo(out);
}
};
MLTrainingTaskRequest result = MLTrainingTaskRequest.fromActionRequest(actionRequest);
assertNotSame(request, result);
assertEquals(request.getMlInput().getAlgorithm(), result.getMlInput().getAlgorithm());
assertEquals(request.getMlInput().getParameters(), result.getMlInput().getParameters());
assertEquals(request.getMlInput().getInputDataset().getInputDataType(), result.getMlInput().getInputDataset().getInputDataType());
}
use of org.opensearch.common.io.stream.StreamOutput in project ml-commons by opensearch-project.
the class MLTrainingTaskRequestTest method fromActionRequest_Exception.
@Test(expected = UncheckedIOException.class)
public void fromActionRequest_Exception() {
ActionRequest actionRequest = new ActionRequest() {
@Override
public ActionRequestValidationException validate() {
return null;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
throw new IOException("test");
}
};
MLTrainingTaskRequest.fromActionRequest(actionRequest);
}
use of org.opensearch.common.io.stream.StreamOutput in project ml-commons by opensearch-project.
the class MLModelDeleteRequestTest method fromActionRequest_IOException.
@Test(expected = UncheckedIOException.class)
public void fromActionRequest_IOException() {
ActionRequest actionRequest = new ActionRequest() {
@Override
public ActionRequestValidationException validate() {
return null;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
throw new IOException("test");
}
};
MLModelDeleteRequest.fromActionRequest(actionRequest);
}
use of org.opensearch.common.io.stream.StreamOutput in project ml-commons by opensearch-project.
the class MLModelGetRequestTest method fromActionRequest_Success.
@Test
public void fromActionRequest_Success() {
MLModelGetRequest mlModelGetRequest = MLModelGetRequest.builder().modelId(modelId).build();
ActionRequest actionRequest = new ActionRequest() {
@Override
public ActionRequestValidationException validate() {
return null;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
mlModelGetRequest.writeTo(out);
}
};
MLModelGetRequest result = MLModelGetRequest.fromActionRequest(actionRequest);
assertNotSame(result, mlModelGetRequest);
assertEquals(result.getModelId(), mlModelGetRequest.getModelId());
}
use of org.opensearch.common.io.stream.StreamOutput in project OpenSearch by opensearch-project.
the class QueryShardContextTests method testToQueryFails.
public void testToQueryFails() {
QueryShardContext context = createQueryShardContext(IndexMetadata.INDEX_UUID_NA_VALUE, null);
Exception exc = expectThrows(Exception.class, () -> context.toQuery(new AbstractQueryBuilder() {
@Override
public String getWriteableName() {
return null;
}
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
}
@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
}
@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
throw new RuntimeException("boom");
}
@Override
protected boolean doEquals(AbstractQueryBuilder other) {
return false;
}
@Override
protected int doHashCode() {
return 0;
}
}));
assertThat(exc.getMessage(), equalTo("failed to create query: boom"));
}
Aggregations