Search in sources :

Example 81 with StreamInput

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

Example 82 with StreamInput

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

the class DistributedResultRequestTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    Streamer<?>[] streamers = new Streamer[] { DataTypes.STRING.streamer() };
    Object[][] rows = new Object[][] { { new BytesRef("ab") }, { null }, { new BytesRef("cd") } };
    UUID uuid = UUID.randomUUID();
    DistributedResultRequest r1 = new DistributedResultRequest(uuid, 1, (byte) 3, 1, streamers, new ArrayBucket(rows), false);
    BytesStreamOutput out = new BytesStreamOutput();
    r1.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    DistributedResultRequest r2 = new DistributedResultRequest();
    r2.readFrom(in);
    r2.streamers(streamers);
    assertTrue(r2.rowsCanBeRead());
    assertEquals(r1.rows().size(), r2.rows().size());
    assertThat(r1.isLast(), is(r2.isLast()));
    assertThat(r1.executionPhaseInputId(), is(r2.executionPhaseInputId()));
    assertThat(r2.rows(), contains(isRow("ab"), isNullRow(), isRow("cd")));
}
Also used : ArrayBucket(io.crate.data.ArrayBucket) Streamer(io.crate.Streamer) DistributedResultRequest(io.crate.executor.transport.distributed.DistributedResultRequest) StreamInput(org.elasticsearch.common.io.stream.StreamInput) UUID(java.util.UUID) BytesRef(org.apache.lucene.util.BytesRef) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 83 with StreamInput

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

the class ShardDeleteRequestTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    ShardId shardId = new ShardId("test", 1);
    UUID jobId = UUID.randomUUID();
    ShardDeleteRequest request = new ShardDeleteRequest(shardId, "42", jobId);
    request.add(123, new ShardDeleteRequest.Item("99"));
    request.add(5, new ShardDeleteRequest.Item("42"));
    BytesStreamOutput out = new BytesStreamOutput();
    request.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    ShardDeleteRequest request2 = new ShardDeleteRequest();
    request2.readFrom(in);
    assertThat(request, equalTo(request2));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) StreamInput(org.elasticsearch.common.io.stream.StreamInput) UUID(java.util.UUID) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 84 with StreamInput

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

the class ShardUpsertRequestTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    ShardId shardId = new ShardId("test", 1);
    String[] assignmentColumns = new String[] { "id", "name" };
    UUID jobId = UUID.randomUUID();
    Reference[] missingAssignmentColumns = new Reference[] { ID_REF, NAME_REF };
    ShardUpsertRequest request = new ShardUpsertRequest.Builder(false, false, assignmentColumns, missingAssignmentColumns, jobId, false).newRequest(shardId, "42");
    request.validateConstraints(false);
    request.add(123, new ShardUpsertRequest.Item("99", null, new Object[] { 99, new BytesRef("Marvin") }, null));
    request.add(5, new ShardUpsertRequest.Item("42", new Symbol[] { Literal.of(42), Literal.of("Deep Thought") }, null, 2L));
    BytesStreamOutput out = new BytesStreamOutput();
    request.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    ShardUpsertRequest request2 = new ShardUpsertRequest();
    request2.readFrom(in);
    assertThat(request, equalTo(request2));
}
Also used : Reference(io.crate.metadata.Reference) Symbol(io.crate.analyze.symbol.Symbol) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) ShardId(org.elasticsearch.index.shard.ShardId) StreamInput(org.elasticsearch.common.io.stream.StreamInput) UUID(java.util.UUID) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 85 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)

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