public void RunMemoryLeakTest()
        {
            ICoalescingBuffer<CountingKey, CountingValue> buffer = new CoalescingRingBuffer<CountingKey, CountingValue>(16);
            buffer.Offer(new CountingValue());

            buffer.Offer(new CountingKey(1), new CountingValue());
            buffer.Offer(new CountingKey(2), new CountingValue());
            buffer.Offer(new CountingKey(1), new CountingValue());

            buffer.Offer(new CountingValue());

            Assert.AreEqual(4, buffer.Size());
            buffer.Poll(new List<CountingValue>(), 1);
            buffer.Poll(new List<CountingValue>());
            Assert.True(buffer.IsEmpty());

            buffer.Offer(null); // to trigger the clean
        }
Exemple #2
0
        public void RunMemoryLeakTest()
        {
            ICoalescingBuffer <CountingKey, CountingValue> buffer = new CoalescingRingBuffer <CountingKey, CountingValue>(16);

            buffer.Offer(new CountingValue());

            buffer.Offer(new CountingKey(1), new CountingValue());
            buffer.Offer(new CountingKey(2), new CountingValue());
            buffer.Offer(new CountingKey(1), new CountingValue());

            buffer.Offer(new CountingValue());

            Assert.AreEqual(4, buffer.Size());
            buffer.Poll(new List <CountingValue>(), 1);
            buffer.Poll(new List <CountingValue>());
            Assert.True(buffer.IsEmpty());

            buffer.Offer(null); // to trigger the clean
        }
Exemple #3
0
        public void ShouldBeAbleToReuseCapacity()
        {
            ICoalescingBuffer <int, String> buffer = new CoalescingRingBuffer <int, String>(32);

            var producer = new Thread(
                () =>
            {
                for (var run = 0; run < 1000000; run++)
                {
                    for (var message = 0; message < 10; message++)
                    {
                        var success = buffer.Offer(message, message.ToString());

                        if (!success)
                        {
                            _hasOverflowed = true;
                            buffer.Offer(PoisonPill);
                            return;
                        }
                    }
                }

                buffer.Offer(PoisonPill);
            });


            var consumer = new Thread(
                () =>
            {
                var values = new List <String>(CAPACITY);
                while (true)
                {
                    buffer.Poll(values, CAPACITY);
                    if (values.Contains(PoisonPill))
                    {
                        return;
                    }
                }
            });

            producer.Start();
            consumer.Start();

            producer.Join();
            Assert.IsFalse(_hasOverflowed, "ring buffer has overflowed");
        }
        public void ShouldBeAbleToReuseCapacity()
        {
            ICoalescingBuffer<int, String> buffer = new CoalescingRingBuffer<int, String>(32);

            var producer = new Thread(
                () =>
                {
                    for (var run = 0; run < 1000000; run++)
                    {
                        for (var message = 0; message < 10; message++)
                        {
                            var success = buffer.Offer(message, message.ToString());

                            if (!success)
                            {
                                _hasOverflowed = true;
                                buffer.Offer(PoisonPill);
                                return;
                            }
                        }
                    }

                    buffer.Offer(PoisonPill);
                });

            var consumer = new Thread(
                () =>
                    {
                        var values = new List<String>(CAPACITY);
                        while (true)
                        {
                            buffer.Poll(values, CAPACITY);
                            if (values.Contains(PoisonPill))
                            {
                                return;
                            }
                        }
                    });

            producer.Start();
            consumer.Start();

            producer.Join();
            Assert.IsFalse(_hasOverflowed, "ring buffer has overflowed");
        }