Example #1
0
        /// <summary>
        /// Write out the contents of data into the output stream
        /// </summary>
        /// <param name="os"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private NativePooledByteBuffer DoWrite(NativePooledByteBufferOutputStream os, byte[] data)
        {
            for (int i = 0; i < data.Length; i++)
            {
                os.Write(data, i, 1);
            }

            return((NativePooledByteBuffer)os.ToByteBuffer());
        }
Example #2
0
        public void TestToByteBufException()
        {
            NativePooledByteBufferOutputStream os1 = new NativePooledByteBufferOutputStream(_pool);

            os1.Dispose();

            try
            {
                os1.ToByteBuffer();
                Assert.Fail();
            }
            catch (InvalidStreamException)
            {
                // This is expected
            }
        }
Example #3
0
        public void TestClose()
        {
            NativePooledByteBufferOutputStream os = new NativePooledByteBufferOutputStream(_pool);

            os.Dispose();
            _stats.Refresh();
            var testStat = new Dictionary <int, Tuple <int, int> >()
            {
                { 32, new Tuple <int, int>(0, 0) },
                { 16, new Tuple <int, int>(0, 0) },
                { 8, new Tuple <int, int>(0, 0) },
                { 4, new Tuple <int, int>(0, 1) }
            };

            Assert.IsTrue(testStat.All(e => _stats.BucketStats.Contains(e)));
        }
Example #4
0
        public void TestBasic_2()
        {
            NativePooledByteBufferOutputStream os2 = new NativePooledByteBufferOutputStream(_pool, 8);
            NativePooledByteBuffer             sb2 = DoWrite(os2, _data);

            Assert.AreEqual(16, sb2._bufRef.Get().Size);
            AssertArrayEquals(_data, GetBytes(sb2), _data.Length);
            _stats.Refresh();
            var testStat = new Dictionary <int, Tuple <int, int> >()
            {
                { 32, new Tuple <int, int>(0, 0) },
                { 16, new Tuple <int, int>(1, 0) },
                { 8, new Tuple <int, int>(0, 1) },
                { 4, new Tuple <int, int>(0, 0) }
            };

            Assert.IsTrue(testStat.All(e => _stats.BucketStats.Contains(e)));
        }
Example #5
0
        public void TestWriteAfterToByteBuf()
        {
            NativePooledByteBufferOutputStream os1 = new NativePooledByteBufferOutputStream(_pool);

            byte[] _data1 = new byte[9];
            byte[] _data2 = new byte[3];
            Array.Copy(_data, _data1, _data1.Length);
            Array.Copy(_data, _data2, _data2.Length);
            NativePooledByteBuffer buf1 = DoWrite(os1, _data1);
            NativePooledByteBuffer buf2 = DoWrite(os1, _data2);

            Assert.AreEqual(12, buf2.Size);

            CloseableReference <NativeMemoryChunk> chunk = buf1._bufRef;

            Assert.AreEqual(3, chunk.GetUnderlyingReferenceTestOnly().GetRefCountTestOnly());
            os1.Dispose();
            buf1.Dispose();
            buf2.Dispose();
            Assert.AreEqual(0, chunk.GetUnderlyingReferenceTestOnly().GetRefCountTestOnly());
        }