Search in sources :

Example 96 with StreamInput

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

the class FunctionTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    Function fn = new Function(new FunctionInfo(new FunctionIdent(randomAsciiOfLength(10), ImmutableList.of(DataTypes.BOOLEAN)), TestingHelpers.randomPrimitiveType(), FunctionInfo.Type.SCALAR, randomFeatures()), Collections.singletonList(TestingHelpers.createReference(randomAsciiOfLength(2), DataTypes.BOOLEAN)));
    BytesStreamOutput output = new BytesStreamOutput();
    Symbols.toStream(fn, output);
    StreamInput input = StreamInput.wrap(output.bytes());
    Function fn2 = (Function) Symbols.fromStream(input);
    assertThat(fn, is(equalTo(fn2)));
    assertThat(fn.hashCode(), is(fn2.hashCode()));
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) StreamInput(org.elasticsearch.common.io.stream.StreamInput) FunctionInfo(io.crate.metadata.FunctionInfo) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 97 with StreamInput

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

the class ReferenceTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    TableIdent tableIdent = new TableIdent("doc", "test");
    ReferenceIdent referenceIdent = new ReferenceIdent(tableIdent, "object_column");
    Reference reference = new Reference(referenceIdent, RowGranularity.DOC, new ArrayType(DataTypes.OBJECT), ColumnPolicy.STRICT, Reference.IndexType.ANALYZED, false);
    BytesStreamOutput out = new BytesStreamOutput();
    Reference.toStream(reference, out);
    StreamInput in = StreamInput.wrap(out.bytes());
    Reference reference2 = Reference.fromStream(in);
    assertThat(reference2, is(reference));
}
Also used : ArrayType(io.crate.types.ArrayType) 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 98 with StreamInput

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

the class RoutingTest method testStreamingWithoutLocations.

@Test
public void testStreamingWithoutLocations() throws Exception {
    BytesStreamOutput out = new BytesStreamOutput();
    Routing routing1 = new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of());
    routing1.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    Routing routing2 = Routing.fromStream(in);
    assertThat(routing1.locations(), is(routing2.locations()));
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) List(java.util.List) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 99 with StreamInput

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

the class ArrayTypeTest method testArrayTypeSerialization.

@Test
public void testArrayTypeSerialization() throws Exception {
    // nested string array: [ ["x"], ["y"] ]
    ArrayType arrayType = new ArrayType(new ArrayType(StringType.INSTANCE));
    BytesStreamOutput out = new BytesStreamOutput();
    DataTypes.toStream(arrayType, out);
    StreamInput in = StreamInput.wrap(out.bytes());
    DataType readType = DataTypes.fromStream(in);
    assertThat(readType, instanceOf(ArrayType.class));
    ArrayType readArrayType = (ArrayType) readType;
    assertThat(readArrayType.innerType(), instanceOf(ArrayType.class));
    ArrayType readInnerArrayType = (ArrayType) readArrayType.innerType();
    assertThat(readInnerArrayType.innerType(), instanceOf(StringType.class));
    assertSame(readInnerArrayType.innerType(), StringType.INSTANCE);
}
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 100 with StreamInput

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

the class GeoPointTypeTest method testStreaming.

@Test
public void testStreaming() throws Throwable {
    Double[] p1 = new Double[] { 41.2, -37.4 };
    BytesStreamOutput out = new BytesStreamOutput();
    DataTypes.GEO_POINT.writeValueTo(out, p1);
    StreamInput in = StreamInput.wrap(out.bytes());
    Double[] p2 = DataTypes.GEO_POINT.readValueFrom(in);
    assertThat(p1, equalTo(p2));
}
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