Search in sources :

Example 21 with BytesStreamOutput

use of org.opensearch.common.io.stream.BytesStreamOutput in project k-NN by opensearch-project.

the class GetModelResponseTests method testStreams.

public void testStreams() throws IOException {
    String modelId = "test-model";
    byte[] testModelBlob = "hello".getBytes();
    Model model = new Model(getModelMetadata(ModelState.CREATED), testModelBlob, modelId);
    GetModelResponse getModelResponse = new GetModelResponse(model);
    BytesStreamOutput streamOutput = new BytesStreamOutput();
    getModelResponse.writeTo(streamOutput);
    GetModelResponse getModelResponseCopy = new GetModelResponse(streamOutput.bytes().streamInput());
    assertEquals(getModelResponse.getModel(), getModelResponseCopy.getModel());
}
Also used : Model(org.opensearch.knn.indices.Model) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 22 with BytesStreamOutput

use of org.opensearch.common.io.stream.BytesStreamOutput in project k-NN by opensearch-project.

the class TrainingJobRouteDecisionInfoNodeResponseTests method testStreams.

public void testStreams() throws IOException {
    BytesStreamOutput streamOutput = new BytesStreamOutput();
    int trainingJobCount = 13;
    InetAddress inetAddress = InetAddresses.fromInteger(randomInt());
    DiscoveryNode discoveryNode = new DiscoveryNode("id", new TransportAddress(inetAddress, 9200), Version.CURRENT);
    TrainingJobRouteDecisionInfoNodeResponse original = new TrainingJobRouteDecisionInfoNodeResponse(discoveryNode, trainingJobCount);
    original.writeTo(streamOutput);
    TrainingJobRouteDecisionInfoNodeResponse copy = new TrainingJobRouteDecisionInfoNodeResponse(streamOutput.bytes().streamInput());
    assertEquals(original.getTrainingJobCount(), copy.getTrainingJobCount());
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportAddress(org.opensearch.common.transport.TransportAddress) InetAddress(java.net.InetAddress) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 23 with BytesStreamOutput

use of org.opensearch.common.io.stream.BytesStreamOutput in project k-NN by opensearch-project.

the class DeleteModelRequestTests method testStreams.

public void testStreams() throws IOException {
    String modelId = "test-model";
    DeleteModelRequest deleteModelRequest = new DeleteModelRequest(modelId);
    BytesStreamOutput streamOutput = new BytesStreamOutput();
    deleteModelRequest.writeTo(streamOutput);
    DeleteModelRequest deleteModelRequestCopy = new DeleteModelRequest(streamOutput.bytes().streamInput());
    assertEquals(deleteModelRequest.getModelID(), deleteModelRequestCopy.getModelID());
}
Also used : BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 24 with BytesStreamOutput

use of org.opensearch.common.io.stream.BytesStreamOutput in project k-NN by opensearch-project.

the class DeleteModelResponseTests method testXContentWithError.

public void testXContentWithError() throws IOException {
    String modelId = "test-model";
    DeleteModelResponse deleteModelResponse = new DeleteModelResponse(modelId, "not_found", "model id not found");
    BytesStreamOutput streamOutput = new BytesStreamOutput();
    deleteModelResponse.writeTo(streamOutput);
    String expectedResponseString = "{\"model_id\":\"test-model\",\"result\":\"not_found\",\"error\":\"model id not found\"}";
    XContentBuilder xContentBuilder = XContentFactory.contentBuilder(XContentType.JSON);
    deleteModelResponse.toXContent(xContentBuilder, null);
    assertEquals(expectedResponseString, Strings.toString(xContentBuilder));
}
Also used : BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 25 with BytesStreamOutput

use of org.opensearch.common.io.stream.BytesStreamOutput in project k-NN by opensearch-project.

the class DeleteModelResponseTests method testStreams.

public void testStreams() throws IOException {
    String modelId = "test-model";
    DeleteModelResponse deleteModelResponse = new DeleteModelResponse(modelId, "delete action failed", "error message");
    BytesStreamOutput streamOutput = new BytesStreamOutput();
    deleteModelResponse.writeTo(streamOutput);
    DeleteModelResponse deleteModelResponseCopy = new DeleteModelResponse(streamOutput.bytes().streamInput());
    assertEquals(deleteModelResponse.getModelID(), deleteModelResponseCopy.getModelID());
    assertEquals(deleteModelResponse.getResult(), deleteModelResponseCopy.getResult());
    assertEquals(deleteModelResponse.getErrorMessage(), deleteModelResponseCopy.getErrorMessage());
}
Also used : BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Aggregations

BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)385 StreamInput (org.opensearch.common.io.stream.StreamInput)192 NamedWriteableAwareStreamInput (org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)68 Test (org.junit.Test)64 IOException (java.io.IOException)44 BytesReference (org.opensearch.common.bytes.BytesReference)39 Version (org.opensearch.Version)31 ArrayList (java.util.ArrayList)27 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)26 HashMap (java.util.HashMap)22 ReleasableBytesReference (org.opensearch.common.bytes.ReleasableBytesReference)21 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)19 OpenSearchException (org.opensearch.OpenSearchException)17 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)15 BytesArray (org.opensearch.common.bytes.BytesArray)14 Map (java.util.Map)13 List (java.util.List)10 ClusterName (org.opensearch.cluster.ClusterName)10 TimeValue (org.opensearch.common.unit.TimeValue)10 Collections (java.util.Collections)9