public void TestAccessAvailableRelease()
        {
            var pool = new ByteBufferPool(10, 100);

            Assert.Equal(10, pool.Available());

            var buffer1 = pool.Access();
            var buffer2 = pool.Access();
            var buffer3 = pool.Access();

            Assert.Equal(7, pool.Available());

            buffer1.Release();

            Assert.Equal(8, pool.Available());

            buffer2.Release();
            buffer3.Release();

            Assert.Equal(10, pool.Available());
        }
        public void TestPooledByteBuffer()
        {
            var testText = "Hello, PooledByteBuffer";

            var pool = new ByteBufferPool(10, 100);

            var buffer1 = pool.Access();

            buffer1.AsStream().Write(Converters.TextToBytes(testText));

            Assert.Equal(testText, Converters.BytesToText(buffer1.Flip().ToArray()));
        }
Beispiel #3
0
        public void TestBroadcastPooledByteBuffer()
        {
            var buffer1 = _pool.Access();
            var buffer2 = _pool.Access();
            var buffer3 = _pool.Access();

            var rawMessage1 = BuildRawMessageBuffer((MemoryStream)buffer1.AsStream(), _message1);

            BytesFrom(rawMessage1, (MemoryStream)buffer1.AsStream());
            var rawMessage2 = BuildRawMessageBuffer((MemoryStream)buffer2.AsStream(), _message2);

            BytesFrom(rawMessage2, (MemoryStream)buffer2.AsStream());
            var rawMessage3 = BuildRawMessageBuffer((MemoryStream)buffer3.AsStream(), _message3);

            BytesFrom(rawMessage3, (MemoryStream)buffer3.AsStream());

            _outbound.Broadcast(buffer1);
            _outbound.Broadcast(buffer2);
            _outbound.Broadcast(buffer3);

            foreach (var channel in _channelProvider.AllOtherNodeChannels.Values)
            {
                var mock = (MockManagedOutboundChannel)channel;

                Assert.Equal(_message1, mock.Writes[0]);
                Assert.Equal(_message2, mock.Writes[1]);
                Assert.Equal(_message3, mock.Writes[2]);
            }
        }
        public void TestAlwaysAccessible()
        {
            var pool  = new ByteBufferPool(1, 100);
            var count = new AtomicInteger(0);

            var work1 = new Thread(() =>
            {
                for (int c = 0; c < 10_000_000; ++c)
                {
                    var pooled = pool.Access();
                    pooled.Clear().Put(Converters.TextToBytes("I got it: 1!")).Flip();
                    pooled.Release();
                }

                count.IncrementAndGet();
            });

            var work2 = new Thread(() =>
            {
                for (int c = 0; c < 10_000_000; ++c)
                {
                    var pooled = pool.Access();
                    pooled.Clear().Put(Converters.TextToBytes("I got it: 2!")).Flip();
                    pooled.Release();
                }

                count.IncrementAndGet();
            });

            work1.Start();
            work2.Start();

            work1.Join();
            work2.Join();

            Assert.Equal(2, count.Get());
        }
Beispiel #5
0
        public void Broadcast(RawMessage message)
        {
            var buffer = _pool.Access();

            Broadcast(BytesFrom(message, buffer));
        }