Search in sources :

Example 51 with StreamInput

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

the class IngestStatsTests method serialize.

private IngestStats serialize(IngestStats stats) throws IOException {
    BytesStreamOutput out = new BytesStreamOutput();
    stats.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    return new IngestStats(in);
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 52 with StreamInput

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

the class SerializationTests method testPutChunkReplicaRequestSerialization.

@Test
public void testPutChunkReplicaRequestSerialization() throws Exception {
    BytesStreamOutput outputStream = new BytesStreamOutput();
    UUID transferId = UUID.randomUUID();
    PutChunkReplicaRequest requestOut = new PutChunkReplicaRequest();
    requestOut.index("foo");
    requestOut.transferId = transferId;
    requestOut.currentPos = 10;
    requestOut.isLast = false;
    requestOut.content = new BytesArray(new byte[] { 0x65, 0x66 });
    requestOut.sourceNodeId = "nodeId";
    requestOut.writeTo(outputStream);
    StreamInput inputStream = StreamInput.wrap(outputStream.bytes());
    PutChunkReplicaRequest requestIn = new PutChunkReplicaRequest();
    requestIn.readFrom(inputStream);
    assertEquals(requestOut.currentPos, requestIn.currentPos);
    assertEquals(requestOut.isLast, requestIn.isLast);
    assertEquals(requestOut.content, requestIn.content);
    assertEquals(requestOut.transferId, requestIn.transferId);
    assertEquals(requestOut.index(), requestIn.index());
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) StreamInput(org.elasticsearch.common.io.stream.StreamInput) UUID(java.util.UUID) PutChunkReplicaRequest(io.crate.blob.PutChunkReplicaRequest) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 53 with StreamInput

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

the class DeleteBlobRequestTest method testDeleteBlobRequestStreaming.

@Test
public void testDeleteBlobRequestStreaming() throws Exception {
    byte[] digest = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
    DeleteBlobRequest request = new DeleteBlobRequest("foo", digest);
    BytesStreamOutput out = new BytesStreamOutput();
    request.writeTo(out);
    DeleteBlobRequest fromStream = new DeleteBlobRequest();
    StreamInput in = StreamInput.wrap(out.bytes());
    fromStream.readFrom(in);
    assertThat(fromStream.index(), is("foo"));
    assertThat(fromStream.id(), is(Hex.encodeHexString(digest)));
}
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 54 with StreamInput

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

the class DeleteBlobResponseTest method testDeleteBlobResponseStreaming.

@Test
public void testDeleteBlobResponseStreaming() throws Exception {
    DeleteBlobResponse response = new DeleteBlobResponse();
    response.deleted = true;
    response.setShardInfo(new ActionWriteResponse.ShardInfo());
    BytesStreamOutput out = new BytesStreamOutput();
    response.writeTo(out);
    DeleteBlobResponse fromStream = new DeleteBlobResponse();
    StreamInput in = StreamInput.wrap(out.bytes());
    fromStream.readFrom(in);
    assertThat(fromStream.deleted, is(true));
}
Also used : ActionWriteResponse(org.elasticsearch.action.ActionWriteResponse) 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 55 with StreamInput

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

the class GeneratedReferenceTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    ReferenceIdent referenceIdent = new ReferenceIdent(T3.T1_INFO.ident(), "generated_column");
    String formattedGeneratedExpression = "concat(a, 'bar')";
    GeneratedReference generatedReferenceInfo = new GeneratedReference(referenceIdent, RowGranularity.DOC, StringType.INSTANCE, ColumnPolicy.STRICT, Reference.IndexType.ANALYZED, formattedGeneratedExpression, false);
    generatedReferenceInfo.generatedExpression(SQL_EXPRESSIONS.normalize(SQL_EXPRESSIONS.asSymbol(formattedGeneratedExpression)));
    generatedReferenceInfo.referencedReferences(ImmutableList.of(T3.T1_INFO.getReference(new ColumnIdent("a"))));
    BytesStreamOutput out = new BytesStreamOutput();
    Reference.toStream(generatedReferenceInfo, out);
    StreamInput in = StreamInput.wrap(out.bytes());
    GeneratedReference generatedReferenceInfo2 = Reference.fromStream(in);
    assertThat(generatedReferenceInfo2, is(generatedReferenceInfo));
}
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