use of org.elasticsearch.common.io.stream.BytesStreamOutput in project crate by crate.
the class DistributionInfoTest method testStreamingDefaultImpl.
@Test
public void testStreamingDefaultImpl() throws Exception {
DistributionInfo distributionInfo = DistributionInfo.DEFAULT_BROADCAST;
BytesStreamOutput out = new BytesStreamOutput(10);
distributionInfo.writeTo(out);
StreamInput in = StreamInput.wrap(out.bytes());
DistributionInfo streamed = DistributionInfo.fromStream(in);
assertThat(streamed, equalTo(distributionInfo));
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project crate by crate.
the class ArrayMapper method toXContent.
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
/*
* array mapping should look like:
*
* "fieldName": {
* "type": "array":
* "inner": {
* "type": "string"
* ...
* }
* }
*
*
* Use the innerMapper to generate the mapping for the inner type which will look like:
*
* "fieldName": {
* "type": "string",
* ...
* }
*
* and then parse the contents of the object to set it into the "inner" field of the outer array type.
*/
XContentBuilder innerBuilder = new XContentBuilder(builder.contentType().xContent(), new BytesStreamOutput(0));
innerBuilder.startObject();
innerBuilder = innerMapper.toXContent(innerBuilder, params);
innerBuilder.endObject();
innerBuilder.close();
XContentParser parser = builder.contentType().xContent().createParser(innerBuilder.bytes());
//noinspection StatementWithEmptyBody
while ((parser.nextToken() != XContentParser.Token.START_OBJECT)) {
// consume tokens until start of object
}
//noinspection unchecked
Map<String, Object> innerMap = (Map<String, Object>) parser.mapOrdered().get(innerMapper.simpleName());
assert innerMap != null : "innerMap was null";
builder.startObject(simpleName());
builder.field("type", contentType());
builder.field(INNER, innerMap);
return builder.endObject();
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project crate by crate.
the class JobRequestTest method testJobRequestStreaming.
@Test
public void testJobRequestStreaming() throws Exception {
JobRequest r1 = new JobRequest(UUID.randomUUID(), "n1", Collections.<NodeOperation>emptyList());
BytesStreamOutput out = new BytesStreamOutput();
r1.writeTo(out);
JobRequest r2 = new JobRequest();
r2.readFrom(StreamInput.wrap(out.bytes()));
assertThat(r1.coordinatorNodeId(), is(r2.coordinatorNodeId()));
assertThat(r1.jobId(), is(r2.jobId()));
assertThat(r1.nodeOperations().isEmpty(), is(true));
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project crate by crate.
the class TDigestStateTest method testStreaming.
@Test
public void testStreaming() throws Exception {
TDigestState digestState1 = new TDigestState(250, new double[] { 0.5, 0.8 });
BytesStreamOutput out = new BytesStreamOutput();
TDigestStateType digestStateType = TDigestStateType.INSTANCE;
Streamer streamer = digestStateType.create().streamer();
streamer.writeValueTo(out, digestState1);
StreamInput in = StreamInput.wrap(out.bytes());
TDigestState digestState2 = (TDigestState) streamer.readValueFrom(in);
assertEquals(digestState1.compression(), digestState2.compression(), 0.001d);
assertEquals(digestState1.fractions()[0], digestState2.fractions()[0], 0.001d);
assertEquals(digestState1.fractions()[1], digestState2.fractions()[1], 0.001d);
}
use of org.elasticsearch.common.io.stream.BytesStreamOutput in project elasticsearch by elastic.
the class BaseAggregationTestCase method testSerialization.
/**
* Test serialization and deserialization of the test AggregatorFactory.
*/
public void testSerialization() throws IOException {
AB testAgg = createTestAggregatorBuilder();
try (BytesStreamOutput output = new BytesStreamOutput()) {
output.writeNamedWriteable(testAgg);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
AggregationBuilder deserialized = in.readNamedWriteable(AggregationBuilder.class);
assertEquals(testAgg, deserialized);
assertEquals(testAgg.hashCode(), deserialized.hashCode());
assertNotSame(testAgg, deserialized);
}
}
}
Aggregations