Examples of BytesStreamOutput


Examples of org.elasticsearch.common.io.stream.BytesStreamOutput

                        createReference("bar", DataTypes.SHORT)
                ));

        p.values(ImmutableList.<Aggregation>of());
        p.setRequiredGranularity(RowGranularity.SHARD);
        BytesStreamOutput out = new BytesStreamOutput();
        Projection.toStream(p, out);

        BytesStreamInput in = new BytesStreamInput(out.bytes());
        GroupProjection p2 = (GroupProjection) Projection.fromStream(in);
        assertEquals(p, p2);
    }
View Full Code Here

Examples of org.elasticsearch.common.io.stream.BytesStreamOutput

        FilterProjection p = new FilterProjection();
        p.outputs(ImmutableList.<Symbol>of(new InputColumn(1)));
        p.requiredGranularity(RowGranularity.SHARD);
        p.query(TestingHelpers.createFunction(AndOperator.NAME, DataTypes.BOOLEAN, Literal.newLiteral(true), Literal.newLiteral(false)));

        BytesStreamOutput out = new BytesStreamOutput();
        Projection.toStream(p, out);

        BytesStreamInput in = new BytesStreamInput(out.bytes());
        FilterProjection p2 = (FilterProjection) Projection.fromStream(in);

        assertEquals(p, p2);
    }
View Full Code Here

Examples of org.elasticsearch.common.io.stream.BytesStreamOutput

    public void testLongSerialization() throws Exception {
        FunctionIdent fi = new FunctionIdent("collect_set", ImmutableList.<DataType>of(DataTypes.LONG));
        AggregationFunction impl = (AggregationFunction) functions.get(fi);
        AggregationState state = impl.newState();

        BytesStreamOutput streamOutput = new BytesStreamOutput();
        state.writeTo(streamOutput);

        AggregationState newState = impl.newState();
        newState.readFrom(new BytesStreamInput(streamOutput.bytes()));
        assertEquals(state.value(), newState.value());
    }
View Full Code Here

Examples of org.elasticsearch.common.io.stream.BytesStreamOutput

    @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);

        BytesStreamInput in = new BytesStreamInput(out.bytes());

        DataType readType = DataTypes.fromStream(in);
        assertThat(readType, instanceOf(ArrayType.class));

        ArrayType readArrayType = (ArrayType)readType;
View Full Code Here

Examples of org.elasticsearch.common.io.stream.BytesStreamOutput

    @Test
    public void testStreaming() throws Throwable {
        Double[] p1 = new Double[] { 41.2, -37.4 };

        BytesStreamOutput out = new BytesStreamOutput();
        DataTypes.GEO_POINT.writeValueTo(out, p1);

        BytesStreamInput in = new BytesStreamInput(out.bytes());
        Double[] p2 = DataTypes.GEO_POINT.readValueFrom(in);

        assertThat(p1, equalTo(p2));
    }
View Full Code Here

Examples of org.elasticsearch.common.io.stream.BytesStreamOutput

                String uri = request.getUri();
                QueryStringDecoder decoder = new QueryStringDecoder(uri);
                logger.debug("Got Request for " + uri);
                HttpResponse response;

                BytesStreamOutput out = new BytesStreamOutput();
                if (fail) {
                    response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST);
                } else {
                    response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
                }
                try {
                    JsonGenerator generator = jsonFactory.createGenerator(out, JsonEncoding.UTF8);
                    generator.writeStartObject();
                    for (Map.Entry<String, List<String>> entry : decoder.getParameters().entrySet()) {
                        if (entry.getValue().size() == 1) {
                            generator.writeStringField(entry.getKey(), URLDecoder.decode(entry.getValue().get(0), "UTF-8"));
                        } else {
                            generator.writeArrayFieldStart(entry.getKey());
                            for (String value : entry.getValue()) {
                                generator.writeString(URLDecoder.decode(value, "UTF-8"));
                            }
                            generator.writeEndArray();
                        }
                    }
                    generator.writeEndObject();
                    generator.close();

                } catch (Exception ex) {
                    response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
                }
                response.setContent(ChannelBuffers.copiedBuffer(out.bytes().toUtf8(), CharsetUtil.UTF_8));

                responses.add(out.bytes().toUtf8());
                if (logger.isDebugEnabled()) {
                    logger.debug("Sending response: " + out.bytes().toUtf8());
                }

                ChannelFuture future = e.getChannel().write(response);
                future.addListener(ChannelFutureListener.CLOSE);
            }
View Full Code Here

Examples of org.elasticsearch.common.io.stream.BytesStreamOutput

    @Test
    public void testStreamer() throws Exception {
        Shape value = GeoShapeType.INSTANCE.value("POINT (10 10)");

        BytesStreamOutput out = new BytesStreamOutput();
        GeoShapeType.INSTANCE.writeValueTo(out, value);
        BytesStreamInput in = new BytesStreamInput(out.bytes());
        Shape streamedShape = GeoShapeType.INSTANCE.readValueFrom(in);

        assertThat(streamedShape, equalTo(value));
    }
View Full Code Here

Examples of org.elasticsearch.common.io.stream.BytesStreamOutput

public class SerializationTests {


    @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);
        BytesStreamInput inputStream = new BytesStreamInput(outputStream.bytes().copyBytesArray());

        PutChunkReplicaRequest requestIn = new PutChunkReplicaRequest();
        requestIn.readFrom(inputStream);

        assertEquals(requestOut.currentPos, requestIn.currentPos);
View Full Code Here

Examples of org.elasticsearch.common.io.stream.BytesStreamOutput

public class DataTypeTest {

    @Test
    public void testStreaming() throws Exception {
        BytesRef b1 = new BytesRef("hello");
        BytesStreamOutput out = new BytesStreamOutput();
        Streamer streamer = DataTypes.STRING.streamer();
        streamer.writeValueTo(out, b1);
        BytesStreamInput in = new BytesStreamInput(out.bytes());
        BytesRef b2 = (BytesRef) streamer.readValueFrom(in);
        assertEquals(b1, b2);
    }
View Full Code Here

Examples of org.elasticsearch.common.io.stream.BytesStreamOutput

    }

    @Test
    public void testStreamingNull() throws Exception {
        BytesRef b1 = null;
        BytesStreamOutput out = new BytesStreamOutput();
        Streamer streamer = DataTypes.STRING.streamer();
        streamer.writeValueTo(out, b1);
        BytesStreamInput in = new BytesStreamInput(out.bytes());
        BytesRef b2 = (BytesRef) streamer.readValueFrom(in);
        assertNull(b2);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.