public void testFooSizeLimited() throws Exception
    {
        final Foo fooCompare = SerializableObjects.newFoo(
                new Integer[] { 90210, -90210, 0 },
                new String[] { "ab", "cd" },
                new Bar[] { SerializableObjects.bar, SerializableObjects.negativeBar,
                        SerializableObjects.bar, SerializableObjects.negativeBar,
                        SerializableObjects.bar, SerializableObjects.negativeBar },
                new EnumSample[] { EnumSample.TYPE0, EnumSample.TYPE2 },
                new ByteString[] { ByteString.copyFromUtf8("ef"), ByteString.copyFromUtf8("gh") },
                new Boolean[] { true, false },
                new Float[] { 1234.4321f, -1234.4321f, 0f },
                new Double[] { 12345678.87654321d, -12345678.87654321d, 0d },
                new Long[] { 7060504030201l, -7060504030201l, 0l });

        ByteArrayOutputStream out = new ByteArrayOutputStream();

        final LinkedBuffer buffer = LinkedBuffer.allocate(256);

        try
        {
            ProtostuffIOUtil.writeDelimitedTo(out, fooCompare, fooCompare.cachedSchema(),
                    buffer);
        }
        finally
        {
            buffer.clear();
        }

        byte[] data = out.toByteArray();

        ByteArrayInputStream in = new ByteArrayInputStream(data);
        Foo foo = new Foo();

        boolean hasException = true;
        try
        {
            ProtostuffIOUtil.mergeDelimitedFrom(in, foo, foo.cachedSchema(), buffer);
            hasException = false;
        }
        catch (ProtostuffException e)
        {
            assertTrue(e.getMessage().startsWith("size limit exceeded."));
        }

        assertTrue(hasException);
    }
Test for re-using a thread-local buffer across many serializations.

@author David Yu
@created Jan 15, 2011
protostuff-core/src/test/java/io/protostuff/BufferReuseTest.java