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