use of org.elasticsearch.common.io.stream.BytesStreamOutput in project elasticsearch by elastic.
the class IndexRequestTests method testSerializationOfEmptyRequestWorks.
// reindex makes use of index requests without a source so this needs to be handled
public void testSerializationOfEmptyRequestWorks() throws IOException {
IndexRequest request = new IndexRequest("index", "type");
assertNull(request.getContentType());
try (BytesStreamOutput out = new BytesStreamOutput()) {
request.writeTo(out);
try (StreamInput in = out.bytes().streamInput()) {
IndexRequest serialized = new IndexRequest();
serialized.readFrom(in);
assertNull(request.getContentType());
assertEquals("index", request.index());
assertEquals("type", request.type());
}
}
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project elasticsearch by elastic.
the class IndexRequestTests method testIndexRequestXContentSerialization.
public void testIndexRequestXContentSerialization() throws IOException {
IndexRequest indexRequest = new IndexRequest("foo", "bar", "1");
indexRequest.source("{}", XContentType.JSON);
assertEquals(XContentType.JSON, indexRequest.getContentType());
BytesStreamOutput out = new BytesStreamOutput();
indexRequest.writeTo(out);
StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
IndexRequest serialized = new IndexRequest();
serialized.readFrom(in);
assertEquals(XContentType.JSON, serialized.getContentType());
assertEquals(new BytesArray("{}"), serialized.source());
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project elasticsearch by elastic.
the class PutPipelineRequestTests method testSerializationWithXContent.
public void testSerializationWithXContent() throws IOException {
PutPipelineRequest request = new PutPipelineRequest("1", new BytesArray("{}".getBytes(StandardCharsets.UTF_8)), XContentType.JSON);
assertEquals(XContentType.JSON, request.getXContentType());
BytesStreamOutput output = new BytesStreamOutput();
request.writeTo(output);
StreamInput in = StreamInput.wrap(output.bytes().toBytesRef().bytes);
PutPipelineRequest serialized = new PutPipelineRequest();
serialized.readFrom(in);
assertEquals(XContentType.JSON, serialized.getXContentType());
assertEquals("{}", serialized.getSource().utf8ToString());
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project elasticsearch by elastic.
the class PutPipelineRequestTests method testSerializationBwc.
public void testSerializationBwc() throws IOException {
final byte[] data = Base64.getDecoder().decode("ADwDATECe30=");
final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2, Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
try (StreamInput in = StreamInput.wrap(data)) {
in.setVersion(version);
PutPipelineRequest request = new PutPipelineRequest();
request.readFrom(in);
assertEquals(XContentType.JSON, request.getXContentType());
assertEquals("{}", request.getSource().utf8ToString());
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(version);
request.writeTo(out);
assertArrayEquals(data, out.bytes().toBytesRef().bytes);
}
}
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project elasticsearch by elastic.
the class IndexGraveyardTests method testSerialization.
public void testSerialization() throws IOException {
final IndexGraveyard graveyard = createRandom();
final BytesStreamOutput out = new BytesStreamOutput();
graveyard.writeTo(out);
assertThat(new IndexGraveyard(out.bytes().streamInput()), equalTo(graveyard));
}
Aggregations