Package org.elasticsearch.common.io.stream

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


        }
        if (randomBoolean()) {
            mltRequest.fields(randomStrings(5));
        }

        BytesStreamOutput out = new BytesStreamOutput();
        out.setVersion(randomVersion());
        mltRequest.writeTo(out);

        BytesStreamInput in = new BytesStreamInput(out.bytes());
        in.setVersion(out.getVersion());
        MoreLikeThisRequest mltRequest2 = new MoreLikeThisRequest();
        mltRequest2.readFrom(in);

        assertThat(mltRequest2.index(), equalTo(mltRequest.index()));
        assertThat(mltRequest2.type(), equalTo(mltRequest.type()));
        assertThat(mltRequest2.id(), equalTo(mltRequest.id()));
        assertThat(mltRequest2.boostTerms(), equalTo(mltRequest.boostTerms()));
        assertThat(mltRequest2.maxDocFreq(), equalTo(mltRequest.maxDocFreq()));
        assertThat(mltRequest2.minDocFreq(), equalTo(mltRequest.minDocFreq()));
        assertThat(mltRequest2.maxQueryTerms(), equalTo(mltRequest.maxQueryTerms()));
        assertThat(mltRequest2.minWordLength(), equalTo(mltRequest.minWordLength()));
        assertThat(mltRequest2.maxWordLength(), equalTo(mltRequest.maxWordLength()));
        assertThat(mltRequest2.percentTermsToMatch(), equalTo(mltRequest.percentTermsToMatch()));
        assertThat(mltRequest2.searchTypes(), equalTo(mltRequest.searchTypes()));
        assertThat(mltRequest2.searchType(), equalTo(mltRequest.searchType()));
        assertThat(mltRequest2.searchIndices(), equalTo(mltRequest.searchIndices()));
        assertThat(mltRequest2.routing(), equalTo(mltRequest.routing()));
        assertThat(mltRequest2.searchFrom(), equalTo(mltRequest.searchFrom()));
        assertThat(mltRequest2.searchSize(), equalTo(mltRequest.searchSize()));
        if (mltRequest.searchScroll() == null) {
            assertThat(mltRequest2.searchScroll(), nullValue());
        } else {
            assertThat(mltRequest2.searchFrom(), notNullValue());
            assertThat(mltRequest2.searchScroll().keepAlive(), equalTo(mltRequest.searchScroll().keepAlive()));
        }

        if (mltRequest.searchSource() == null) {
            assertThat(mltRequest2.searchSource().length(), equalTo(0));
        } else {
            assertThat(mltRequest2.searchSource().length(), equalTo(mltRequest.searchSource().length()));
            assertThat(mltRequest2.searchSourceUnsafe(), equalTo(mltRequest.searchSourceUnsafe()));
        }

        if (mltRequest.stopWords() != null && mltRequest.stopWords().length > 0) {
            assertThat(mltRequest2.stopWords(), equalTo(mltRequest.stopWords()));
        } else {
            assertThat(mltRequest2.stopWords(), nullValue());
        }
        if (mltRequest.fields() == null) {
            assertThat(mltRequest2.fields(), equalTo(Strings.EMPTY_ARRAY));
        } else {
            assertThat(mltRequest2.fields(), equalTo(mltRequest.fields()));
        }
        if (out.getVersion().onOrAfter(Version.V_1_2_0)) {
            assertThat(mltRequest2.include(), equalTo(mltRequest.include()));
        } else {
            assertThat(mltRequest2.include(), is(false));
        }
    }
View Full Code Here


*/
public class JsonVsCborTests extends ElasticsearchTestCase {

    @Test
    public void compareParsingTokens() throws IOException {
        BytesStreamOutput xsonOs = new BytesStreamOutput();
        XContentGenerator xsonGen = XContentFactory.xContent(XContentType.CBOR).createGenerator(xsonOs);

        BytesStreamOutput jsonOs = new BytesStreamOutput();
        XContentGenerator jsonGen = XContentFactory.xContent(XContentType.JSON).createGenerator(jsonOs);

        xsonGen.writeStartObject();
        jsonGen.writeStartObject();

        xsonGen.writeStringField("test", "value");
        jsonGen.writeStringField("test", "value");

        xsonGen.writeArrayFieldStart("arr");
        jsonGen.writeArrayFieldStart("arr");
        xsonGen.writeNumber(1);
        jsonGen.writeNumber(1);
        xsonGen.writeNull();
        jsonGen.writeNull();
        xsonGen.writeEndArray();
        jsonGen.writeEndArray();

        xsonGen.writeEndObject();
        jsonGen.writeEndObject();

        xsonGen.close();
        jsonGen.close();

        verifySameTokens(XContentFactory.xContent(XContentType.JSON).createParser(jsonOs.bytes().toBytes()), XContentFactory.xContent(XContentType.CBOR).createParser(xsonOs.bytes().toBytes()));
    }
View Full Code Here

        out.close();
    }

    @Test
    public void testSingleShortPage() throws Exception {
        BytesStreamOutput out = new BytesStreamOutput();

        int expectedSize = 10;
        byte[] expectedData = randomizedByteArrayWithSize(expectedSize);

        // write byte-by-byte
        for (int i = 0; i < expectedSize; i++) {
            out.writeByte(expectedData[i]);
        }

        assertEquals(expectedSize, out.size());
        assertArrayEquals(expectedData, out.bytes().toBytes());

        out.close();
    }
View Full Code Here

        out.close();
    }

    @Test
    public void testIllegalBulkWrite() throws Exception {
        BytesStreamOutput out = new BytesStreamOutput();

        // bulk-write with wrong args
        try {
            out.writeBytes(new byte[]{}, 0, 1);
            fail("expected IllegalArgumentException: length > (size-offset)");
        }
        catch (IllegalArgumentException iax1) {
            // expected
        }

        out.close();
    }
View Full Code Here

        out.close();
    }

    @Test
    public void testSingleShortPageBulkWrite() throws Exception {
        BytesStreamOutput out = new BytesStreamOutput();

        // first bulk-write empty array: should not change anything
        int expectedSize = 0;
        byte[] expectedData = randomizedByteArrayWithSize(expectedSize);
        out.writeBytes(expectedData);
        assertEquals(expectedSize, out.size());
        assertArrayEquals(expectedData, out.bytes().toBytes());

        // bulk-write again with actual bytes
        expectedSize = 10;
        expectedData = randomizedByteArrayWithSize(expectedSize);
        out.writeBytes(expectedData);
        assertEquals(expectedSize, out.size());
        assertArrayEquals(expectedData, out.bytes().toBytes());

        out.close();
    }
View Full Code Here

        out.close();
    }

    @Test
    public void testSingleFullPageBulkWrite() throws Exception {
        BytesStreamOutput out = new BytesStreamOutput();

        int expectedSize = BigArrays.BYTE_PAGE_SIZE;
        byte[] expectedData = randomizedByteArrayWithSize(expectedSize);

        // write in bulk
        out.writeBytes(expectedData);

        assertEquals(expectedSize, out.size());
        assertArrayEquals(expectedData, out.bytes().toBytes());

        out.close();
    }
View Full Code Here

        out.close();
    }

    @Test
    public void testSingleFullPageBulkWriteWithOffset() throws Exception {
        BytesStreamOutput out = new BytesStreamOutput();

        int initialOffset = 10;
        int additionalLength = BigArrays.BYTE_PAGE_SIZE;
        byte[] expectedData = randomizedByteArrayWithSize(initialOffset + additionalLength);

        // first create initial offset
        out.writeBytes(expectedData, 0, initialOffset);
        assertEquals(initialOffset, out.size());

        // now write the rest - more than fits into the remaining first page
        out.writeBytes(expectedData, initialOffset, additionalLength);
        assertEquals(expectedData.length, out.size());
        assertArrayEquals(expectedData, out.bytes().toBytes());

        out.close();
    }
View Full Code Here

        out.close();
    }

    @Test
    public void testSingleFullPageBulkWriteWithOffsetCrossover() throws Exception {
        BytesStreamOutput out = new BytesStreamOutput();

        int initialOffset = 10;
        int additionalLength = BigArrays.BYTE_PAGE_SIZE * 2;
        byte[] expectedData = randomizedByteArrayWithSize(initialOffset + additionalLength);
        out.writeBytes(expectedData, 0, initialOffset);
        assertEquals(initialOffset, out.size());

        // now write the rest - more than fits into the remaining page + a full page after
        // that,
        // ie. we cross over into a third
        out.writeBytes(expectedData, initialOffset, additionalLength);
        assertEquals(expectedData.length, out.size());
        assertArrayEquals(expectedData, out.bytes().toBytes());

        out.close();
    }
View Full Code Here

        out.close();
    }

    @Test
    public void testSingleFullPage() throws Exception {
        BytesStreamOutput out = new BytesStreamOutput();

        int expectedSize = BigArrays.BYTE_PAGE_SIZE;
        byte[] expectedData = randomizedByteArrayWithSize(expectedSize);

        // write byte-by-byte
        for (int i = 0; i < expectedSize; i++) {
            out.writeByte(expectedData[i]);
        }

        assertEquals(expectedSize, out.size());
        assertArrayEquals(expectedData, out.bytes().toBytes());

        out.close();
    }
View Full Code Here

        out.close();
    }

    @Test
    public void testOneFullOneShortPage() throws Exception {
        BytesStreamOutput out = new BytesStreamOutput();

        int expectedSize = BigArrays.BYTE_PAGE_SIZE + 10;
        byte[] expectedData = randomizedByteArrayWithSize(expectedSize);

        // write byte-by-byte
        for (int i = 0; i < expectedSize; i++) {
            out.writeByte(expectedData[i]);
        }

        assertEquals(expectedSize, out.size());
        assertArrayEquals(expectedData, out.bytes().toBytes());

        out.close();
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.common.io.stream.BytesStreamOutput

Copyright © 2018 www.massapicom. 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.