Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnNullIfQueueIsEmpty()
        public virtual void ShouldReturnNullIfQueueIsEmpty()
        {
            // given
            int chunkSize = 8;
            LinkedList <ByteBuf> byteBufs = new LinkedList <ByteBuf>();

            ChunkingNetworkChannel channel = new ChunkingNetworkChannel(Buffers, chunkSize, byteBufs);

            // when
            channel.PutLong(1L);
            channel.PutLong(1L);

            // then
            assertNotNull(byteBufs.RemoveFirst());
            assertNull(byteBufs.RemoveFirst());

            // when
            channel.PutLong(2L);

            // then
            assertNotNull(byteBufs.RemoveFirst());
            assertNull(byteBufs.RemoveFirst());

            // when
            channel.Flush();

            // then
            assertNotNull(byteBufs.RemoveFirst());
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSerializeIntoChunksOfGivenSize()
        public virtual void ShouldSerializeIntoChunksOfGivenSize()
        {
            // given
            int chunkSize = 8;
            LinkedList <ByteBuf>   byteBufs = new LinkedList <ByteBuf>();
            ChunkingNetworkChannel channel  = new ChunkingNetworkChannel(Buffers, chunkSize, byteBufs);

            // and data is written
            sbyte[] array = new sbyte[10];
            channel.Put(( sbyte )1);
            channel.PutInt(1);
            channel.PutFloat(1.0f);
            channel.PutDouble(1.0d);
            channel.PutShort(( short )1);
            channel.PutLong(1);
            channel.Put(array, array.Length);
            channel.Flush();

            // when
            ByteBuf combinedByteBuf = Buffers.buffer();
            ByteBuf byteBuf;

            while ((byteBuf = byteBufs.RemoveFirst()) != null)
            {
                assertEquals(chunkSize, byteBuf.capacity());
                combinedByteBuf.writeBytes(byteBuf);
            }

            //then
            assertEquals(( sbyte )1, combinedByteBuf.readByte());
            assertEquals(1, combinedByteBuf.readInt());
            assertEquals(1.0f, combinedByteBuf.readFloat());
            assertEquals(1.0d, combinedByteBuf.readDouble());
            assertEquals(( short )1, combinedByteBuf.readShort());
            assertEquals(1L, combinedByteBuf.readLong());
            sbyte[] bytes = new sbyte[array.Length];
            combinedByteBuf.readBytes(bytes);
            assertArrayEquals(array, bytes);
            assertEquals(0, combinedByteBuf.readableBytes());
        }