Beispiel #1
0
        public void CopyPooled()
        {
            var pool = new MockBufferPool();

            BufferPool.SetCustomBufferPool(pool);

            var msg = new Msg();

            msg.InitPool(100);

            Assert.IsFalse(msg.IsShared);

            var copy = new Msg();

            copy.Copy(ref msg);

            Assert.IsTrue(msg.IsShared);
            Assert.IsTrue(copy.IsShared);

            msg.Close();

            Assert.AreEqual(0, pool.ReturnCallCount);
            Assert.IsFalse(msg.IsInitialised);
            Assert.IsNull(msg.Data);

            copy.Close();

            Assert.AreEqual(1, pool.ReturnCallCount);
            Assert.IsFalse(copy.IsInitialised);
            Assert.IsNull(copy.Data);
        }
Beispiel #2
0
        public void CopyPooled()
        {
            var pool = new MockBufferPool();
            BufferPool.SetCustomBufferPool(pool);

            var msg = new Msg();
            msg.InitPool(100);

            Assert.IsFalse(msg.IsShared);

            var copy = new Msg();
            copy.Copy(ref msg);

            Assert.IsTrue(msg.IsShared);
            Assert.IsTrue(copy.IsShared);

            msg.Close();

            Assert.AreEqual(0, pool.ReturnCallCount);
            Assert.IsFalse(msg.IsInitialised);
            Assert.IsNull(msg.Data);

            copy.Close();

            Assert.AreEqual(1, pool.ReturnCallCount);
            Assert.IsFalse(copy.IsInitialised);
            Assert.IsNull(copy.Data);
        }
Beispiel #3
0
        public void InitPool()
        {
            var pool = new MockBufferPool();

            BufferPool.SetCustomBufferPool(pool);

            var counterPool = new MockCounterPool();

            AtomicCounterPool.SetCustomCounterPool(counterPool);

            var msg = new Msg();

            Assert.Equal(0, pool.TakeCallCount);
            Assert.Equal(0, counterPool.TakeCallCount);

            msg.InitPool(100);

            Assert.Equal(1, pool.TakeCallCount);
            Assert.Equal(100, pool.TakeSize[0]);
            Assert.Equal(1, counterPool.TakeCallCount);

            Assert.Equal(100, msg.Size);
            Assert.Equal(MsgType.Pool, msg.MsgType);
            Assert.Equal(MsgFlags.None, msg.Flags);
            Assert.NotNull(msg.UnsafeData);
            Assert.Equal(100, msg.UnsafeData !.Length);
            Assert.False(msg.HasMore);
            Assert.False(msg.IsDelimiter);
            Assert.False(msg.IsIdentity);
            Assert.True(msg.IsInitialised);

            Assert.Equal(0, pool.ReturnCallCount);
            Assert.Equal(0, counterPool.ReturnCallCount);

            var bytes = msg.UnsafeData;

            msg.Close();

            Assert.Equal(1, pool.ReturnCallCount);
            Assert.Same(bytes, pool.ReturnBuffer[0]);

            Assert.Equal(1, counterPool.ReturnCallCount);

            Assert.Equal(MsgType.Uninitialised, msg.MsgType);
            Assert.Null(msg.UnsafeData);
        }
Beispiel #4
0
        public void CopyPooled()
        {
            var pool = new MockBufferPool();

            BufferPool.SetCustomBufferPool(pool);

            var counterPool = new MockCounterPool();

            AtomicCounterPool.SetCustomCounterPool(counterPool);

            var msg = new Msg();

            msg.InitPool(100);

            Assert.False(msg.IsShared);

            var copy = new Msg();

            copy.Copy(ref msg);

            Assert.True(msg.IsShared);
            Assert.True(copy.IsShared);

            msg.Close();

            Assert.Equal(0, pool.ReturnCallCount);
            Assert.Equal(1, counterPool.ReturnCallCount);
            Assert.False(msg.IsInitialised);
            Assert.Null(msg.UnsafeData);

            copy.Close();

            Assert.Equal(1, pool.ReturnCallCount);
            Assert.Equal(2, counterPool.ReturnCallCount);
            Assert.False(copy.IsInitialised);
            Assert.Null(copy.UnsafeData);
        }
Beispiel #5
0
        public void InitPool()
        {
            var pool = new MockBufferPool();
            BufferPool.SetCustomBufferPool(pool);

            var msg = new Msg();

            Assert.AreEqual(0, pool.TakeCallCount);

            msg.InitPool(100);

            Assert.AreEqual(1, pool.TakeCallCount);
            Assert.AreEqual(100, pool.TakeSize[0]);

            Assert.AreEqual(100, msg.Size);
            Assert.AreEqual(MsgType.Pool, msg.MsgType);
            Assert.AreEqual(MsgFlags.None, msg.Flags);
            Assert.IsNotNull(msg.Data);
            Assert.AreEqual(100, msg.Data.Length);
            Assert.IsFalse(msg.HasMore);
            Assert.IsFalse(msg.IsDelimiter);
            Assert.IsFalse(msg.IsIdentity);
            Assert.IsTrue(msg.IsInitialised);

            Assert.AreEqual(0, pool.ReturnCallCount);

            var bytes = msg.Data;

            msg.Close();

            Assert.AreEqual(1, pool.ReturnCallCount);
            Assert.AreSame(bytes, pool.ReturnBuffer[0]);

            Assert.AreEqual(MsgType.Uninitialised, msg.MsgType);
            Assert.IsNull(msg.Data);
        }