Search in sources :

Example 26 with StreamOutput

use of org.opensearch.common.io.stream.StreamOutput in project OpenSearch by opensearch-project.

the class ScriptExceptionTests method testRoundTrip.

/**
 * ensure we can round trip in serialization
 */
public void testRoundTrip() throws IOException {
    ScriptException e = new ScriptException("messageData", new Exception("causeData"), Arrays.asList("stack1", "stack2"), "sourceData", "langData");
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    StreamOutput output = new DataOutputStreamOutput(new DataOutputStream(bytes));
    e.writeTo(output);
    output.close();
    StreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(bytes.toByteArray()));
    ScriptException e2 = new ScriptException(input);
    input.close();
    assertEquals(e.getMessage(), e2.getMessage());
    assertEquals(e.getScriptStack(), e2.getScriptStack());
    assertEquals(e.getScript(), e2.getScript());
    assertEquals(e.getLang(), e2.getLang());
    assertNull(e.getPos());
    // Ensure non-null position also works
    e = new ScriptException(e.getMessage(), e.getCause(), e.getScriptStack(), e.getScript(), e.getLang(), new ScriptException.Position(1, 0, 2));
    bytes = new ByteArrayOutputStream();
    output = new DataOutputStreamOutput(new DataOutputStream(bytes));
    e.writeTo(output);
    output.close();
    input = new InputStreamStreamInput(new ByteArrayInputStream(bytes.toByteArray()));
    e2 = new ScriptException(input);
    input.close();
    assertEquals(e.getPos(), e2.getPos());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) StreamInput(org.opensearch.common.io.stream.StreamInput) InputStreamStreamInput(org.opensearch.common.io.stream.InputStreamStreamInput) DataOutputStreamOutput(org.opensearch.common.io.stream.DataOutputStreamOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataOutputStreamOutput(org.opensearch.common.io.stream.DataOutputStreamOutput) StreamOutput(org.opensearch.common.io.stream.StreamOutput) IOException(java.io.IOException) InputStreamStreamInput(org.opensearch.common.io.stream.InputStreamStreamInput)

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