Search in sources :

Example 71 with StreamInput

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

the class GeoDistanceTests method testGeoDistanceSerialization.

public void testGeoDistanceSerialization() throws IOException {
    // make sure that ordinals don't change, because we rely on then in serialization
    assertThat(GeoDistance.PLANE.ordinal(), equalTo(0));
    assertThat(GeoDistance.ARC.ordinal(), equalTo(1));
    assertThat(GeoDistance.values().length, equalTo(2));
    GeoDistance geoDistance = randomFrom(GeoDistance.PLANE, GeoDistance.ARC);
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        geoDistance.writeTo(out);
        try (StreamInput in = out.bytes().streamInput()) {
            ;
            GeoDistance copy = GeoDistance.readFromStream(in);
            assertEquals(copy.toString() + " vs. " + geoDistance.toString(), copy, geoDistance);
        }
    }
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 72 with StreamInput

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

the class StreamsTests method testBytesStreamInput.

public void testBytesStreamInput() throws IOException {
    byte[] stuff = new byte[] { 0, 1, 2, 3 };
    BytesRef stuffRef = new BytesRef(stuff, 2, 2);
    BytesArray stuffArray = new BytesArray(stuffRef);
    StreamInput input = stuffArray.streamInput();
    assertEquals(2, input.read());
    assertEquals(3, input.read());
    assertEquals(-1, input.read());
    input.close();
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesRef(org.apache.lucene.util.BytesRef)

Example 73 with StreamInput

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

the class BoundTransportAddressTests method testSerialization.

public void testSerialization() throws Exception {
    InetAddress[] inetAddresses = InetAddress.getAllByName("0.0.0.0");
    List<TransportAddress> transportAddressList = new ArrayList<>();
    for (InetAddress address : inetAddresses) {
        transportAddressList.add(new TransportAddress(address, randomIntBetween(9200, 9299)));
    }
    final BoundTransportAddress transportAddress = new BoundTransportAddress(transportAddressList.toArray(new TransportAddress[0]), transportAddressList.get(0));
    assertThat(transportAddress.boundAddresses().length, equalTo(transportAddressList.size()));
    // serialize
    BytesStreamOutput streamOutput = new BytesStreamOutput();
    transportAddress.writeTo(streamOutput);
    StreamInput in = streamOutput.bytes().streamInput();
    BoundTransportAddress serializedAddress;
    if (randomBoolean()) {
        serializedAddress = BoundTransportAddress.readBoundTransportAddress(in);
    } else {
        serializedAddress = new BoundTransportAddress();
        serializedAddress.readFrom(in);
    }
    assertThat(serializedAddress, not(sameInstance(transportAddress)));
    assertThat(serializedAddress.boundAddresses().length, equalTo(transportAddress.boundAddresses().length));
    assertThat(serializedAddress.publishAddress(), equalTo(transportAddress.publishAddress()));
    TransportAddress[] serializedBoundAddresses = serializedAddress.boundAddresses();
    TransportAddress[] boundAddresses = transportAddress.boundAddresses();
    for (int i = 0; i < serializedBoundAddresses.length; i++) {
        assertThat(serializedBoundAddresses[i], equalTo(boundAddresses[i]));
    }
}
Also used : ArrayList(java.util.ArrayList) StreamInput(org.elasticsearch.common.io.stream.StreamInput) InetAddress(java.net.InetAddress) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 74 with StreamInput

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

the class ByteSizeUnitTests method testSerialization.

public void testSerialization() throws IOException {
    for (ByteSizeUnit unit : ByteSizeUnit.values()) {
        try (BytesStreamOutput out = new BytesStreamOutput()) {
            unit.writeTo(out);
            try (StreamInput in = out.bytes().streamInput()) {
                ByteSizeUnit deserialized = ByteSizeUnit.readFrom(in);
                assertEquals(unit, deserialized);
            }
        }
    }
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 75 with StreamInput

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

the class ByteSizeValueTests method testSerialization.

public void testSerialization() throws IOException {
    ByteSizeValue byteSizeValue = new ByteSizeValue(randomNonNegativeLong(), randomFrom(ByteSizeUnit.values()));
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        byteSizeValue.writeTo(out);
        try (StreamInput in = out.bytes().streamInput()) {
            ByteSizeValue deserializedByteSizeValue = new ByteSizeValue(in);
            assertEquals(byteSizeValue.getBytes(), deserializedByteSizeValue.getBytes());
        }
    }
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

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