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