Search in sources :

Example 71 with BytesStreamOutput

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

the class FilterProjectionTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    SqlExpressions sqlExpressions = new SqlExpressions(T3.SOURCES, T3.TR_1);
    FilterProjection p = new FilterProjection(sqlExpressions.normalize(sqlExpressions.asSymbol("a = 'foo'")), ImmutableList.of(new InputColumn(1)));
    p.requiredGranularity(RowGranularity.SHARD);
    BytesStreamOutput out = new BytesStreamOutput();
    Projection.toStream(p, out);
    StreamInput in = StreamInput.wrap(out.bytes());
    FilterProjection p2 = (FilterProjection) Projection.fromStream(in);
    assertEquals(p, p2);
}
Also used : InputColumn(io.crate.analyze.symbol.InputColumn) StreamInput(org.elasticsearch.common.io.stream.StreamInput) SqlExpressions(io.crate.testing.SqlExpressions) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 72 with BytesStreamOutput

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

the class TopNProjectionTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    ImmutableList<Symbol> outputs = ImmutableList.of(new Value(DataTypes.BOOLEAN), new Value(DataTypes.INTEGER));
    TopNProjection p = new TopNProjection(5, 10, outputs);
    BytesStreamOutput out = new BytesStreamOutput();
    Projection.toStream(p, out);
    StreamInput in = StreamInput.wrap(out.bytes());
    TopNProjection p2 = (TopNProjection) Projection.fromStream(in);
    assertEquals(p, p2);
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Value(io.crate.analyze.symbol.Value) 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 73 with BytesStreamOutput

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

the class WriterProjectionTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    WriterProjection p = new WriterProjection(ImmutableList.<Symbol>of(new InputColumn(1)), Literal.of("/foo.json"), WriterProjection.CompressionType.GZIP, MapBuilder.<ColumnIdent, Symbol>newMapBuilder().put(new ColumnIdent("partitionColumn"), Literal.of(1)).map(), ImmutableList.of("foo"), WriterProjection.OutputFormat.JSON_OBJECT);
    BytesStreamOutput out = new BytesStreamOutput();
    Projection.toStream(p, out);
    StreamInput in = StreamInput.wrap(out.bytes());
    WriterProjection p2 = (WriterProjection) Projection.fromStream(in);
    assertEquals(p, p2);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) InputColumn(io.crate.analyze.symbol.InputColumn) 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 74 with BytesStreamOutput

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

the class NodeFetchRequestTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    IntObjectHashMap<IntContainer> toFetch = new IntObjectHashMap<>();
    IntHashSet docIds = new IntHashSet(3);
    toFetch.put(1, docIds);
    NodeFetchRequest orig = new NodeFetchRequest(UUID.randomUUID(), 1, true, toFetch);
    BytesStreamOutput out = new BytesStreamOutput();
    orig.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    NodeFetchRequest streamed = new NodeFetchRequest();
    streamed.readFrom(in);
    assertThat(orig.jobId(), is(streamed.jobId()));
    assertThat(orig.fetchPhaseId(), is(streamed.fetchPhaseId()));
    assertThat(orig.isCloseContext(), is(streamed.isCloseContext()));
    assertThat(orig.toFetch().toString(), is(streamed.toFetch().toString()));
}
Also used : IntContainer(com.carrotsearch.hppc.IntContainer) IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) IntHashSet(com.carrotsearch.hppc.IntHashSet) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 75 with BytesStreamOutput

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

the class ParameterSymbolTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    ParameterSymbol ps1 = new ParameterSymbol(2, DataTypes.INTEGER);
    BytesStreamOutput out = new BytesStreamOutput();
    ps1.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    ParameterSymbol ps2 = new ParameterSymbol(in);
    assertThat(ps2.index(), is(ps1.index()));
    assertThat(ps2.valueType(), is(ps1.valueType()));
}
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)

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