Search in sources :

Example 21 with StreamOutput

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());
}
Also used : ActionRequest(org.opensearch.action.ActionRequest) StreamOutput(org.opensearch.common.io.stream.StreamOutput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 22 with StreamOutput

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);
}
Also used : ActionRequest(org.opensearch.action.ActionRequest) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StreamOutput(org.opensearch.common.io.stream.StreamOutput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 23 with StreamOutput

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);
}
Also used : ActionRequest(org.opensearch.action.ActionRequest) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) StreamOutput(org.opensearch.common.io.stream.StreamOutput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 24 with StreamOutput

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());
}
Also used : ActionRequest(org.opensearch.action.ActionRequest) StreamOutput(org.opensearch.common.io.stream.StreamOutput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 25 with StreamOutput

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"));
}
Also used : StreamOutput(org.opensearch.common.io.stream.StreamOutput) IOException(java.io.IOException) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

StreamOutput (org.opensearch.common.io.stream.StreamOutput)26 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)19 Test (org.junit.Test)14 IOException (java.io.IOException)11 ActionRequest (org.opensearch.action.ActionRequest)10 UncheckedIOException (java.io.UncheckedIOException)7 ActionResponse (org.opensearch.action.ActionResponse)4 OutputStreamStreamOutput (org.opensearch.common.io.stream.OutputStreamStreamOutput)4 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)4 HashMap (java.util.HashMap)3 BytesReference (org.opensearch.common.bytes.BytesReference)3 StreamInput (org.opensearch.common.io.stream.StreamInput)3 List (java.util.List)2 CompositeBytesReference (org.opensearch.common.bytes.CompositeBytesReference)2 ReleasableBytesReference (org.opensearch.common.bytes.ReleasableBytesReference)2 MLTaskResponse (org.opensearch.ml.common.transport.MLTaskResponse)2 AggregationExecutionException (org.opensearch.search.aggregations.AggregationExecutionException)2 InternalMultiBucketAggregation (org.opensearch.search.aggregations.InternalMultiBucketAggregation)2 MultiBucketsAggregation (org.opensearch.search.aggregations.bucket.MultiBucketsAggregation)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1