Search in sources :

Example 56 with StreamInput

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

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

Example 58 with StreamInput

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

the class IndexReferenceTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    TableIdent tableIdent = new TableIdent("doc", "test");
    ReferenceIdent referenceIdent = new ReferenceIdent(tableIdent, "string_col");
    Reference reference = new Reference(referenceIdent, RowGranularity.DOC, StringType.INSTANCE);
    ReferenceIdent indexReferenceIdent = new ReferenceIdent(tableIdent, "index_column");
    IndexReference indexReferenceInfo = new IndexReference(indexReferenceIdent, Reference.IndexType.ANALYZED, ImmutableList.of(reference), "my_analyzer");
    BytesStreamOutput out = new BytesStreamOutput();
    Reference.toStream(indexReferenceInfo, out);
    StreamInput in = StreamInput.wrap(out.bytes());
    IndexReference indexReferenceInfo2 = Reference.fromStream(in);
    assertThat(indexReferenceInfo2, is(indexReferenceInfo));
}
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 59 with StreamInput

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

the class ExtendedStatsTest method testExtendedNetworkStatsSerializationDefault.

@Test
public void testExtendedNetworkStatsSerializationDefault() throws IOException {
    ExtendedNetworkStats statOut = new ExtendedNetworkStats();
    statOut.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    ExtendedNetworkStats statIn = ExtendedNetworkStats.readExtendedNetworkStats(in);
    assertThat(statOut.timestamp(), is(statIn.timestamp()));
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) Test(org.junit.Test)

Example 60 with StreamInput

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

the class ExtendedStatsTest method testExtendedOsStatsSerialization.

@Test
public void testExtendedOsStatsSerialization() throws IOException {
    ExtendedOsStats statOut = new ExtendedOsStats();
    statOut.loadAverage(new double[] { 1.1, 2.3 });
    statOut.timestamp(1L);
    statOut.uptime(2L);
    statOut.cpu(new ExtendedOsStats.Cpu((short) 1, (short) 2, (short) 3, (short) 4));
    statOut.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    ExtendedOsStats statIn = ExtendedOsStats.readExtendedOsStat(in);
    assertThat(statOut.uptime(), is(statIn.uptime()));
    assertThat(statOut.timestamp(), is(statIn.timestamp()));
    assertThat(Arrays.equals(statIn.loadAverage(), statIn.loadAverage()), is(true));
    assertThat(statOut.cpu().idle(), is(statIn.cpu().idle()));
    assertThat(statOut.cpu().stolen(), is(statIn.cpu().stolen()));
    assertThat(statOut.cpu().sys(), is(statIn.cpu().sys()));
    assertThat(statOut.cpu().user(), is(statIn.cpu().user()));
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) Test(org.junit.Test)

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