use of org.elasticsearch.common.io.stream.BytesStreamOutput in project elasticsearch by elastic.
the class BasePipelineAggregationTestCase method testSerialization.
/**
* Test serialization and deserialization of the test AggregatorFactory.
*/
public void testSerialization() throws IOException {
AF testAgg = createTestAggregatorFactory();
try (BytesStreamOutput output = new BytesStreamOutput()) {
output.writeNamedWriteable(testAgg);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
PipelineAggregationBuilder deserializedQuery = in.readNamedWriteable(PipelineAggregationBuilder.class);
assertEquals(deserializedQuery, testAgg);
assertEquals(deserializedQuery.hashCode(), testAgg.hashCode());
assertNotSame(deserializedQuery, testAgg);
}
}
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project elasticsearch by elastic.
the class SearchRequestTests method testSerialization.
public void testSerialization() throws Exception {
SearchRequest searchRequest = createSearchRequest();
try (BytesStreamOutput output = new BytesStreamOutput()) {
searchRequest.writeTo(output);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
SearchRequest deserializedRequest = new SearchRequest();
deserializedRequest.readFrom(in);
assertEquals(deserializedRequest, searchRequest);
assertEquals(deserializedRequest.hashCode(), searchRequest.hashCode());
assertNotSame(deserializedRequest, searchRequest);
}
}
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project elasticsearch by elastic.
the class SearchHitTests method testSerializeShardTarget.
public void testSerializeShardTarget() throws Exception {
SearchShardTarget target = new SearchShardTarget("_node_id", new Index("_index", "_na_"), 0);
Map<String, SearchHits> innerHits = new HashMap<>();
SearchHit innerHit1 = new SearchHit(0, "_id", new Text("_type"), null);
innerHit1.shard(target);
SearchHit innerInnerHit2 = new SearchHit(0, "_id", new Text("_type"), null);
innerInnerHit2.shard(target);
innerHits.put("1", new SearchHits(new SearchHit[] { innerInnerHit2 }, 1, 1f));
innerHit1.setInnerHits(innerHits);
SearchHit innerHit2 = new SearchHit(0, "_id", new Text("_type"), null);
innerHit2.shard(target);
SearchHit innerHit3 = new SearchHit(0, "_id", new Text("_type"), null);
innerHit3.shard(target);
innerHits = new HashMap<>();
SearchHit hit1 = new SearchHit(0, "_id", new Text("_type"), null);
innerHits.put("1", new SearchHits(new SearchHit[] { innerHit1, innerHit2 }, 1, 1f));
innerHits.put("2", new SearchHits(new SearchHit[] { innerHit3 }, 1, 1f));
hit1.shard(target);
hit1.setInnerHits(innerHits);
SearchHit hit2 = new SearchHit(0, "_id", new Text("_type"), null);
hit2.shard(target);
SearchHits hits = new SearchHits(new SearchHit[] { hit1, hit2 }, 2, 1f);
BytesStreamOutput output = new BytesStreamOutput();
hits.writeTo(output);
InputStream input = output.bytes().streamInput();
SearchHits results = SearchHits.readSearchHits(new InputStreamStreamInput(input));
assertThat(results.getAt(0).getShard(), equalTo(target));
assertThat(results.getAt(0).getInnerHits().get("1").getAt(0).getShard(), notNullValue());
assertThat(results.getAt(0).getInnerHits().get("1").getAt(0).getInnerHits().get("1").getAt(0).getShard(), notNullValue());
assertThat(results.getAt(0).getInnerHits().get("1").getAt(1).getShard(), notNullValue());
assertThat(results.getAt(0).getInnerHits().get("2").getAt(0).getShard(), notNullValue());
assertThat(results.getAt(1).getShard(), equalTo(target));
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project elasticsearch by elastic.
the class SearchSortValuesTests method testSerialization.
public void testSerialization() throws IOException {
SearchSortValues sortValues = createTestItem();
try (BytesStreamOutput output = new BytesStreamOutput()) {
sortValues.writeTo(output);
try (StreamInput in = output.bytes().streamInput()) {
SearchSortValues deserializedCopy = new SearchSortValues(in);
assertEquals(sortValues, deserializedCopy);
assertEquals(sortValues.hashCode(), deserializedCopy.hashCode());
assertNotSame(sortValues, deserializedCopy);
}
}
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project elasticsearch by elastic.
the class ExtendedBoundsTests method testTransportRoundTrip.
public void testTransportRoundTrip() throws IOException {
ExtendedBounds orig = randomExtendedBounds();
BytesReference origBytes;
try (BytesStreamOutput out = new BytesStreamOutput()) {
orig.writeTo(out);
origBytes = out.bytes();
}
ExtendedBounds read;
try (StreamInput in = origBytes.streamInput()) {
read = new ExtendedBounds(in);
assertEquals("read fully", 0, in.available());
}
assertEquals(orig, read);
BytesReference readBytes;
try (BytesStreamOutput out = new BytesStreamOutput()) {
read.writeTo(out);
readBytes = out.bytes();
}
assertEquals(origBytes, readBytes);
}
Aggregations