Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }