Package com.couchbase.client.deps.io.netty.buffer

Examples of com.couchbase.client.deps.io.netty.buffer.ByteBuf


        converter.decode("id", content, 0, 0, wrongFlags, ResponseStatus.SUCCESS);
    }

    @Test(expected = TranscodingException.class)
    public void shouldFailToDecodeWithWrongCommonFlags() {
        ByteBuf content = Unpooled.copiedBuffer("{}", CharsetUtil.UTF_8);
        int wrongFlags = TranscoderUtils.BINARY_COMMON_FLAGS;
        converter.decode("id", content, 0, 0, wrongFlags, ResponseStatus.SUCCESS);
    }
View Full Code Here


    }


    @Test
    public void shouldDecodeObjectWithEmptyArray() {
        ByteBuf content = Unpooled.copiedBuffer("{\"array\":[]}", CharsetUtil.UTF_8);
        JsonDocument decoded = converter.decode("id", content, 0, 0, TranscoderUtils.JSON_COMMON_FLAGS, ResponseStatus.SUCCESS);

        assertFalse(decoded.content().isEmpty());
        assertEquals(1, decoded.content().size());
        assertTrue(decoded.content().getArray("array").isEmpty());
View Full Code Here

        assertEquals(TranscoderUtils.JSON_COMPAT_FLAGS, (long) encoded.value2());
    }

    @Test
    public void shouldDecodeMixedJsonValues() throws Exception {
        ByteBuf content = Unpooled.copiedBuffer("{\"boolean\":true,\"integer\":1,\"string\":\"Hello World\"," +
            "\"double\":11.3322,\"long\":9223372036854775807}", CharsetUtil.UTF_8);
        JsonDocument decoded = converter.decode("id", content, 0, 0, TranscoderUtils.JSON_COMMON_FLAGS, ResponseStatus.SUCCESS);
        JsonObject found = decoded.content();

        assertFalse(found.isEmpty());
View Full Code Here

        assertEquals(TranscoderUtils.JSON_COMPAT_FLAGS, (long) encoded.value2());
    }

    @Test
    public void shouldDecodeNestedObjects() {
        ByteBuf content = Unpooled.copiedBuffer("{\"nested\":{\"item\":[\"foo\",\"bar\",1]},\"empty\":{}}", CharsetUtil.UTF_8);
        JsonDocument decoded = converter.decode("id", content, 0, 0, TranscoderUtils.JSON_COMMON_FLAGS, ResponseStatus.SUCCESS);

        assertFalse(decoded.content().isEmpty());
        assertFalse(decoded.content().getObject("nested").isEmpty());
        assertEquals(3, decoded.content().getObject("nested").getArray("item").size());
View Full Code Here

        assertEquals(TranscoderUtils.JSON_COMPAT_FLAGS, (long) encoded.value2());
    }

    @Test
    public void shouldDecodeNestedArray() {
        ByteBuf content = Unpooled.copiedBuffer("{\"1\":[[[\"Hello World\"]]]}", CharsetUtil.UTF_8);
        JsonDocument decoded = converter.decode("id", content, 0, 0, TranscoderUtils.JSON_COMMON_FLAGS, ResponseStatus.SUCCESS);

        assertFalse(decoded.content().isEmpty());
        assertFalse(decoded.content().getArray("1").isEmpty());
        assertEquals("Hello World", decoded.content().getArray("1").getArray(0).getArray(0).getString(0));
View Full Code Here

        assertEquals("Hello World", decoded.content().getArray("1").getArray(0).getArray(0).getString(0));
    }

    @Test
    public void shouldReleaseBufferWhenDecoded() {
        ByteBuf content = Unpooled.copiedBuffer("{}", CharsetUtil.UTF_8);
        JsonDocument decoded = converter.decode("id", content, 0, 0, TranscoderUtils.JSON_COMMON_FLAGS, ResponseStatus.SUCCESS);

        assertEquals(0, content.refCnt());
    }
View Full Code Here

        assertEquals(0, content.refCnt());
    }

    @Test(expected = TranscodingException.class)
    public void shouldReleaseBufferWhenError() {
        ByteBuf content = Unpooled.copiedBuffer("{}", CharsetUtil.UTF_8);
        int wrongFlags = 1234;
        try {
            converter.decode("id", content, 0, 0, wrongFlags,
                ResponseStatus.SUCCESS);
        } finally {
            assertEquals(0, content.refCnt());
        }
    }
View Full Code Here

        }
    }

    @Test
    public void shouldNotReleaseBufferWhenBufToJson() throws Exception {
        ByteBuf content = ReferenceCountUtil.releaseLater(
            Unpooled.copiedBuffer("{}", CharsetUtil.UTF_8));
        JsonObject decoded = converter.byteBufToJsonObject(content);
        assertEquals(1, content.refCnt());

        content = ReferenceCountUtil.releaseLater(
            Unpooled.copiedBuffer("thisIsNotJson", CharsetUtil.UTF_8));
        try {
            decoded = converter.byteBufToJsonObject(content);
            fail();
        } catch (JsonParseException e) {
            //NO-OP, exception expected
        } catch (Exception e) {
            fail(e.toString());
        } finally {
            assertEquals(1, content.refCnt());
        }
    }
View Full Code Here

        assertEquals(TranscoderUtils.JSON_COMPAT_FLAGS, (long) encoded.value2());
    }

    @Test
    public void shouldDecodeRawJson() {
        ByteBuf content = Unpooled.copiedBuffer("{\"test:\":true}", CharsetUtil.UTF_8);
        RawJsonDocument decoded = converter.decode("id", content, 0, 0, TranscoderUtils.JSON_COMPAT_FLAGS,
            ResponseStatus.SUCCESS);

        assertEquals("{\"test:\":true}", decoded.content());
    }
View Full Code Here

        assertEquals("{\"test:\":true}", decoded.content());
    }

    @Test
    public void shouldReleaseBufferWhenDecoded() {
        ByteBuf content = Unpooled.copiedBuffer("{\"test:\":true}", CharsetUtil.UTF_8);
        RawJsonDocument decoded = converter.decode("id", content, 0, 0, TranscoderUtils.JSON_COMPAT_FLAGS,
            ResponseStatus.SUCCESS);
        assertEquals(0, content.refCnt());
    }
View Full Code Here

TOP

Related Classes of com.couchbase.client.deps.io.netty.buffer.ByteBuf

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.