Search in sources :

Example 16 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 17 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 18 with StreamInput

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

the class FailedShardsExceptionTest method testShardFailureReasonIsNull.

@Test
public void testShardFailureReasonIsNull() throws Exception {
    FailedShardsException exception = new FailedShardsException(new ShardOperationFailedException[] { new ShardOperationFailedException() {

        @Override
        public String index() {
            return null;
        }

        @Override
        public int shardId() {
            return 0;
        }

        @Override
        public String reason() {
            return null;
        }

        @Override
        public RestStatus status() {
            return null;
        }

        @Override
        public void readFrom(StreamInput in) throws IOException {
        }

        @Override
        public void writeTo(StreamOutput out) throws IOException {
        }

        @Override
        public Throwable getCause() {
            return null;
        }

        @Override
        public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
            return null;
        }
    }, null });
    assertThat(exception.getMessage(), is("query failed on shards 0 ( null )"));
}
Also used : RestStatus(org.elasticsearch.rest.RestStatus) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) IOException(java.io.IOException) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 19 with StreamInput

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

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

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