Search in sources :

Example 6 with BytesStreamOutput

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

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

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

Example 9 with BytesStreamOutput

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

the class RoutingTest method testStreamingWithLocations.

@Test
public void testStreamingWithLocations() throws Exception {
    Map<String, Map<String, List<Integer>>> locations = new TreeMap<>();
    Map<String, List<Integer>> indexMap = new TreeMap<>();
    indexMap.put("index-0", Arrays.asList(1, 2));
    locations.put("node-0", indexMap);
    BytesStreamOutput out = new BytesStreamOutput();
    Routing routing1 = new Routing(locations);
    routing1.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    Routing routing2 = new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of());
    routing2.readFrom(in);
    assertThat(routing1.locations(), is(routing2.locations()));
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) List(java.util.List) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with BytesStreamOutput

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

the class GeoReferenceTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    TableIdent tableIdent = new TableIdent("doc", "test");
    ReferenceIdent referenceIdent = new ReferenceIdent(tableIdent, "geo_column");
    GeoReference geoReferenceInfo = new GeoReference(referenceIdent, "some_tree", "1m", 3, 0.5d);
    BytesStreamOutput out = new BytesStreamOutput();
    Reference.toStream(geoReferenceInfo, out);
    StreamInput in = StreamInput.wrap(out.bytes());
    GeoReference geoReferenceInfo2 = Reference.fromStream(in);
    assertThat(geoReferenceInfo2, is(geoReferenceInfo));
    GeoReference geoReferenceInfo3 = new GeoReference(referenceIdent, "some_tree", null, null, null);
    out = new BytesStreamOutput();
    Reference.toStream(geoReferenceInfo3, out);
    in = StreamInput.wrap(out.bytes());
    GeoReference geoReferenceInfo4 = Reference.fromStream(in);
    assertThat(geoReferenceInfo4, is(geoReferenceInfo3));
}
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