Search in sources :

Example 66 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 67 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 68 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)

Example 69 with StreamInput

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

the class AbstractStreamableTestCase method copyInstance.

/**
     * Round trip {@code instance} through binary serialization, setting the wire compatibility version to {@code version}.
     */
protected T copyInstance(T instance, Version version) throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        output.setVersion(version);
        instance.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), getNamedWriteableRegistry())) {
            in.setVersion(version);
            T newInstance = createBlankInstance();
            newInstance.readFrom(in);
            return newInstance;
        }
    }
}
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)

Example 70 with StreamInput

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

the class DeflateCompressTests method doTest.

private void doTest(byte[] bytes) throws IOException {
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    StreamInput rawIn = new ByteBufferStreamInput(bb);
    Compressor c = compressor;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    OutputStreamStreamOutput rawOs = new OutputStreamStreamOutput(bos);
    StreamOutput os = c.streamOutput(rawOs);
    Random r = random();
    int bufferSize = r.nextBoolean() ? 65535 : TestUtil.nextInt(random(), 1, 70000);
    int prepadding = r.nextInt(70000);
    int postpadding = r.nextInt(70000);
    byte[] buffer = new byte[prepadding + bufferSize + postpadding];
    // fill block completely with junk
    r.nextBytes(buffer);
    int len;
    while ((len = rawIn.read(buffer, prepadding, bufferSize)) != -1) {
        os.write(buffer, prepadding, len);
    }
    os.close();
    rawIn.close();
    // now we have compressed byte array
    byte[] compressed = bos.toByteArray();
    ByteBuffer bb2 = ByteBuffer.wrap(compressed);
    StreamInput compressedIn = new ByteBufferStreamInput(bb2);
    StreamInput in = c.streamInput(compressedIn);
    // randomize constants again
    bufferSize = r.nextBoolean() ? 65535 : TestUtil.nextInt(random(), 1, 70000);
    prepadding = r.nextInt(70000);
    postpadding = r.nextInt(70000);
    buffer = new byte[prepadding + bufferSize + postpadding];
    // fill block completely with junk
    r.nextBytes(buffer);
    ByteArrayOutputStream uncompressedOut = new ByteArrayOutputStream();
    while ((len = in.read(buffer, prepadding, bufferSize)) != -1) {
        uncompressedOut.write(buffer, prepadding, len);
    }
    uncompressedOut.close();
    assertArrayEquals(bytes, uncompressedOut.toByteArray());
}
Also used : ByteBufferStreamInput(org.elasticsearch.common.io.stream.ByteBufferStreamInput) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) Random(java.util.Random) ByteBufferStreamInput(org.elasticsearch.common.io.stream.ByteBufferStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) ByteBuffer(java.nio.ByteBuffer)

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