Search in sources :

Example 1 with DistributedResultRequest

use of io.crate.executor.transport.distributed.DistributedResultRequest 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 2 with DistributedResultRequest

use of io.crate.executor.transport.distributed.DistributedResultRequest in project crate by crate.

the class DistributedResultRequestTest method testStreamingOfFailure.

@Test
public void testStreamingOfFailure() throws Exception {
    UUID uuid = UUID.randomUUID();
    Throwable throwable = new IllegalStateException("dummy");
    DistributedResultRequest r1 = new DistributedResultRequest(uuid, 1, (byte) 3, 1, throwable, true);
    BytesStreamOutput out = new BytesStreamOutput();
    r1.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    DistributedResultRequest r2 = new DistributedResultRequest();
    r2.readFrom(in);
    assertThat(r2.throwable(), instanceOf(throwable.getClass()));
    assertThat(r2.isKilled(), is(r1.isKilled()));
}
Also used : DistributedResultRequest(io.crate.executor.transport.distributed.DistributedResultRequest) 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

DistributedResultRequest (io.crate.executor.transport.distributed.DistributedResultRequest)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 UUID (java.util.UUID)2 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)2 StreamInput (org.elasticsearch.common.io.stream.StreamInput)2 Test (org.junit.Test)2 Streamer (io.crate.Streamer)1 ArrayBucket (io.crate.data.ArrayBucket)1 BytesRef (org.apache.lucene.util.BytesRef)1