Search in sources :

Example 26 with StreamInput

use of org.elasticsearch.common.io.stream.StreamInput 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);
        }
    }
}
Also used : NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 27 with StreamInput

use of org.elasticsearch.common.io.stream.StreamInput 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);
        }
    }
}
Also used : AbstractPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 28 with StreamInput

use of org.elasticsearch.common.io.stream.StreamInput 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);
        }
    }
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 29 with StreamInput

use of org.elasticsearch.common.io.stream.StreamInput in project elasticsearch by elastic.

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) DataOutputStreamOutput(org.elasticsearch.common.io.stream.DataOutputStreamOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) DataOutputStreamOutput(org.elasticsearch.common.io.stream.DataOutputStreamOutput) IOException(java.io.IOException) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput)

Example 30 with StreamInput

use of org.elasticsearch.common.io.stream.StreamInput 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);
        }
    }
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Aggregations

StreamInput (org.elasticsearch.common.io.stream.StreamInput)183 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)146 Test (org.junit.Test)52 CrateUnitTest (io.crate.test.integration.CrateUnitTest)37 NamedWriteableAwareStreamInput (org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput)30 BytesArray (org.elasticsearch.common.bytes.BytesArray)24 Version (org.elasticsearch.Version)21 IOException (java.io.IOException)13 BytesReference (org.elasticsearch.common.bytes.BytesReference)10 UUID (java.util.UUID)9 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)9 Symbol (io.crate.analyze.symbol.Symbol)8 BytesRef (org.apache.lucene.util.BytesRef)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ShardId (org.elasticsearch.index.shard.ShardId)6 List (java.util.List)5 AliasFilter (org.elasticsearch.search.internal.AliasFilter)5 Aggregation (io.crate.analyze.symbol.Aggregation)4