Search in sources :

Example 1 with NamedWriteableAwareStreamInput

use of org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput 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 2 with NamedWriteableAwareStreamInput

use of org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput 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 3 with NamedWriteableAwareStreamInput

use of org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput 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 4 with NamedWriteableAwareStreamInput

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

the class ShardSearchTransportRequestTests method testSerialization.

public void testSerialization() throws Exception {
    ShardSearchTransportRequest shardSearchTransportRequest = createShardSearchTransportRequest();
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        shardSearchTransportRequest.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            ShardSearchTransportRequest deserializedRequest = new ShardSearchTransportRequest();
            deserializedRequest.readFrom(in);
            assertEquals(deserializedRequest.scroll(), shardSearchTransportRequest.scroll());
            assertEquals(deserializedRequest.filteringAliases(), shardSearchTransportRequest.filteringAliases());
            assertArrayEquals(deserializedRequest.indices(), shardSearchTransportRequest.indices());
            assertArrayEquals(deserializedRequest.types(), shardSearchTransportRequest.types());
            assertEquals(deserializedRequest.indicesOptions(), shardSearchTransportRequest.indicesOptions());
            assertEquals(deserializedRequest.isProfile(), shardSearchTransportRequest.isProfile());
            assertEquals(deserializedRequest.nowInMillis(), shardSearchTransportRequest.nowInMillis());
            assertEquals(deserializedRequest.source(), shardSearchTransportRequest.source());
            assertEquals(deserializedRequest.searchType(), shardSearchTransportRequest.searchType());
            assertEquals(deserializedRequest.shardId(), shardSearchTransportRequest.shardId());
            assertEquals(deserializedRequest.numberOfShards(), shardSearchTransportRequest.numberOfShards());
            assertEquals(deserializedRequest.cacheKey(), shardSearchTransportRequest.cacheKey());
            assertNotSame(deserializedRequest, shardSearchTransportRequest);
            assertEquals(deserializedRequest.filteringAliases(), shardSearchTransportRequest.filteringAliases());
            assertEquals(deserializedRequest.indexBoost(), shardSearchTransportRequest.indexBoost(), 0.0f);
        }
    }
}
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 5 with NamedWriteableAwareStreamInput

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

the class TaskResultTests method testBinaryRoundTrip.

public void testBinaryRoundTrip() throws IOException {
    NamedWriteableRegistry registry = new NamedWriteableRegistry(Collections.singletonList(new NamedWriteableRegistry.Entry(Task.Status.class, RawTaskStatus.NAME, RawTaskStatus::new)));
    TaskResult result = randomTaskResult();
    TaskResult read;
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        result.writeTo(out);
        try (StreamInput in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry)) {
            read = new TaskResult(in);
        }
    } catch (IOException e) {
        throw new IOException("Error processing [" + result + "]", e);
    }
    assertEquals(result, read);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) IOException(java.io.IOException) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Aggregations

NamedWriteableAwareStreamInput (org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput)28 StreamInput (org.elasticsearch.common.io.stream.StreamInput)27 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)23 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)9 AliasFilter (org.elasticsearch.search.internal.AliasFilter)5 IOException (java.io.IOException)4 BytesArray (org.elasticsearch.common.bytes.BytesArray)4 Version (org.elasticsearch.Version)3 BytesReference (org.elasticsearch.common.bytes.BytesReference)3 ShardId (org.elasticsearch.index.shard.ShardId)3 ArrayList (java.util.ArrayList)2 ShardValidateQueryRequest (org.elasticsearch.action.admin.indices.validate.query.ShardValidateQueryRequest)2 ValidateQueryRequest (org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest)2 ExplainRequest (org.elasticsearch.action.explain.ExplainRequest)2 ClusterState (org.elasticsearch.cluster.ClusterState)2 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)2 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 AllocateEmptyPrimaryAllocationCommand (org.elasticsearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand)2 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)2 SearchModule (org.elasticsearch.search.SearchModule)2