Search in sources :

Example 91 with BytesStreamOutput

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

the class CountPhaseTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    Routing routing = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("n1", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", Arrays.asList(1, 2)).put("i2", Arrays.asList(1, 2)).map()).put("n2", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", Collections.singletonList(3)).map()).map());
    CountPhase countPhase = new CountPhase(1, routing, WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
    BytesStreamOutput out = new BytesStreamOutput(10);
    countPhase.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    CountPhase streamedNode = CountPhase.FACTORY.create();
    streamedNode.readFrom(in);
    assertThat(streamedNode.phaseId(), is(1));
    assertThat(streamedNode.nodeIds(), containsInAnyOrder("n1", "n2"));
    assertThat(streamedNode.routing(), equalTo(routing));
    assertThat(streamedNode.distributionInfo(), equalTo(DistributionInfo.DEFAULT_BROADCAST));
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) Routing(io.crate.metadata.Routing) Map(java.util.Map) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 92 with BytesStreamOutput

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

the class NestedLoopPhaseTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    TopNProjection topNProjection = new TopNProjection(10, 0, Collections.emptyList());
    UUID jobId = UUID.randomUUID();
    MergePhase mp1 = new MergePhase(jobId, 2, "merge", 1, Collections.emptyList(), ImmutableList.<DataType>of(DataTypes.STRING), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    MergePhase mp2 = new MergePhase(jobId, 3, "merge", 1, Collections.emptyList(), ImmutableList.<DataType>of(DataTypes.STRING), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    SqlExpressions sqlExpressions = new SqlExpressions(T3.SOURCES, T3.TR_1);
    Symbol joinCondition = sqlExpressions.normalize(sqlExpressions.asSymbol("t1.x = t1.i"));
    NestedLoopPhase node = new NestedLoopPhase(jobId, 1, "nestedLoop", ImmutableList.of(topNProjection), mp1, mp2, Sets.newHashSet("node1", "node2"), JoinType.INNER, joinCondition, 1, 1);
    BytesStreamOutput output = new BytesStreamOutput();
    node.writeTo(output);
    StreamInput input = StreamInput.wrap(output.bytes());
    NestedLoopPhase node2 = new NestedLoopPhase();
    node2.readFrom(input);
    assertThat(node.nodeIds(), Is.is(node2.nodeIds()));
    assertThat(node.jobId(), Is.is(node2.jobId()));
    assertThat(node.name(), is(node2.name()));
    assertThat(node.outputTypes(), is(node2.outputTypes()));
    assertThat(node.joinType(), is(node2.joinType()));
    assertThat(node.numLeftOutputs(), is(node2.numLeftOutputs()));
    assertThat(node.numRightOutputs(), is(node2.numRightOutputs()));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TopNProjection(io.crate.planner.projection.TopNProjection) UUID(java.util.UUID) SqlExpressions(io.crate.testing.SqlExpressions) NestedLoopPhase(io.crate.planner.node.dql.join.NestedLoopPhase) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 93 with BytesStreamOutput

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));
}
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 94 with BytesStreamOutput

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

use of org.elasticsearch.common.io.stream.BytesStreamOutput 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)

Aggregations

BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)222 StreamInput (org.elasticsearch.common.io.stream.StreamInput)147 Test (org.junit.Test)45 CrateUnitTest (io.crate.test.integration.CrateUnitTest)36 NamedWriteableAwareStreamInput (org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput)24 IOException (java.io.IOException)21 BytesArray (org.elasticsearch.common.bytes.BytesArray)21 BytesReference (org.elasticsearch.common.bytes.BytesReference)18 Version (org.elasticsearch.Version)15 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)14 ArrayList (java.util.ArrayList)12 BytesRef (org.apache.lucene.util.BytesRef)11 Map (java.util.Map)10 UUID (java.util.UUID)9 Symbol (io.crate.analyze.symbol.Symbol)8 HashMap (java.util.HashMap)8 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)8 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)7 StreamOutput (org.elasticsearch.common.io.stream.StreamOutput)7 List (java.util.List)6