@@ -0,0 +1,2780 @@
+/*%0A * Copyright 2012-2014 TORCH GmbH%0A *%0A * This file is part of Graylog2.%0A *%0A * Graylog2 is free software: you can redistribute it and/or modify%0A * it under the terms of the GNU General Public License as published by%0A * the Free Software Foundation, either version 3 of the License, or%0A * (at your option) any later version.%0A *%0A * Graylog2 is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU General Public License for more details.%0A *%0A * You should have received a copy of the GNU General Public License%0A * along with Graylog2.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A */%0A%0Apackage org.graylog2.gelfclient.encoder;%0A%0Aimport io.netty.buffer.ByteBuf;%0Aimport io.netty.buffer.Unpooled;%0Aimport io.netty.channel.embedded.EmbeddedChannel;%0Aimport org.graylog2.gelfclient.GelfConfiguration;%0Aimport org.testng.annotations.Test;%0A%0Aimport java.util.Random;%0A%0Aimport static org.testng.AssertJUnit.assertEquals;%0Aimport static org.testng.AssertJUnit.assertNull;%0A%0Apublic class GelfMessageChunkEncoderTest %7B%0A    @Test%0A    public void testChunkedEncode() throws Exception %7B%0A        GelfConfiguration config = new GelfConfiguration();%0A        EmbeddedChannel channel = new EmbeddedChannel(new GelfMessageChunkEncoder(config));%0A        String largeMessage = largeMessage(1500);%0A%0A        channel.writeOutbound(Unpooled.wrappedBuffer(largeMessage.getBytes()));%0A%0A        ByteBuf chunk1 = (ByteBuf) channel.readOutbound();%0A        ByteBuf chunk2 = (ByteBuf) channel.readOutbound();%0A%0A        // Generates two messages%0A        assertNull(channel.readOutbound());%0A%0A        // Check for GELF chunked magic bytes%0A        assertEquals((byte) 0x1e, chunk1.readByte());%0A        assertEquals((byte) 0x0f, chunk1.readByte());%0A        assertEquals((byte) 0x1e, chunk2.readByte());%0A        assertEquals((byte) 0x0f, chunk2.readByte());%0A%0A        // 8 bytes for the message ID%0A        assertEquals(8, chunk1.readBytes(8).array().length);%0A        assertEquals(8, chunk2.readBytes(8).array().length);%0A%0A        // 1 byte sequence number%0A        assertEquals((byte) 0, chunk1.readByte());%0A        assertEquals((byte) 1, chunk2.readByte());%0A%0A        // 1 byte sequence count%0A        assertEquals((byte) 2, chunk1.readByte());%0A        assertEquals((byte) 2, chunk2.readByte());%0A%0A        // data bytes%0A        assertEquals(1420, chunk1.readableBytes());%0A        assertEquals(largeMessage.length() - 1420, chunk2.readableBytes());%0A    %7D%0A%0A    private String largeMessage(int limit) %7B%0A        Random r = new Random();%0A        String largeMessage = %22%22;%0A%0A        while (largeMessage.length() %3C limit) %7B%0A            largeMessage += r.nextInt();%0A        %7D%0A%0A        return largeMessage;%0A    %7D%0A%7D

Add test for the message chunk encoder.