use of org.opensearch.common.io.stream.BytesStreamOutput in project OpenSearch by opensearch-project.
the class GrokProcessorGetActionTests method testRequest.
public void testRequest() throws Exception {
GrokProcessorGetAction.Request request = new GrokProcessorGetAction.Request(false);
BytesStreamOutput out = new BytesStreamOutput();
request.writeTo(out);
StreamInput streamInput = out.bytes().streamInput();
GrokProcessorGetAction.Request otherRequest = new GrokProcessorGetAction.Request(streamInput);
assertThat(otherRequest.validate(), nullValue());
}
use of org.opensearch.common.io.stream.BytesStreamOutput in project OpenSearch by opensearch-project.
the class DebugTests method testPainlessExplainErrorSerialization.
/**
* {@link PainlessExplainError} doesn't serialize but the headers still make it.
*/
public void testPainlessExplainErrorSerialization() throws IOException {
Map<String, Object> params = singletonMap("a", "jumped over the moon");
ScriptException e = expectThrows(ScriptException.class, () -> exec("Debug.explain(params.a)", params, true));
assertEquals(singletonList("jumped over the moon"), e.getMetadata("opensearch.to_string"));
assertEquals(singletonList("java.lang.String"), e.getMetadata("opensearch.java_class"));
assertEquals(singletonList("java.lang.String"), e.getMetadata("opensearch.painless_class"));
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.writeException(e);
try (StreamInput in = out.bytes().streamInput()) {
OpenSearchException read = (ScriptException) in.readException();
assertEquals(singletonList("jumped over the moon"), read.getMetadata("opensearch.to_string"));
assertEquals(singletonList("java.lang.String"), read.getMetadata("opensearch.java_class"));
assertEquals(singletonList("java.lang.String"), read.getMetadata("opensearch.painless_class"));
}
}
}
use of org.opensearch.common.io.stream.BytesStreamOutput in project OpenSearch by opensearch-project.
the class SearchContextId method encode.
public static String encode(List<SearchPhaseResult> searchPhaseResults, Map<String, AliasFilter> aliasFilter, Version version) {
final Map<ShardId, SearchContextIdForNode> shards = new HashMap<>();
for (SearchPhaseResult searchPhaseResult : searchPhaseResults) {
final SearchShardTarget target = searchPhaseResult.getSearchShardTarget();
shards.put(target.getShardId(), new SearchContextIdForNode(target.getClusterAlias(), target.getNodeId(), searchPhaseResult.getContextId()));
}
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(version);
Version.writeVersion(version, out);
out.writeMap(shards, (o, k) -> k.writeTo(o), (o, v) -> v.writeTo(o));
out.writeMap(aliasFilter, StreamOutput::writeString, (o, v) -> v.writeTo(o));
return Base64.getUrlEncoder().encodeToString(BytesReference.toBytes(out.bytes()));
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
use of org.opensearch.common.io.stream.BytesStreamOutput in project OpenSearch by opensearch-project.
the class RoundTripTests method toInputByteStream.
private StreamInput toInputByteStream(Version version, Writeable example) throws IOException {
BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(version);
example.writeTo(out);
StreamInput in = out.bytes().streamInput();
in.setVersion(version);
return in;
}
use of org.opensearch.common.io.stream.BytesStreamOutput in project OpenSearch by opensearch-project.
the class Streams method readFully.
/**
* Reads all bytes from the given {@link InputStream} and closes it afterwards.
*/
public static BytesReference readFully(InputStream in) throws IOException {
BytesStreamOutput out = new BytesStreamOutput();
org.opensearch.core.internal.io.Streams.copy(in, out);
return out.bytes();
}
Aggregations