Пример #1
0
        public async Task GivenBufferListWhenFaultListFullShouldDrop()
        {
            var list = new BufferList <int>(new BufferListOptions(
                                                1,
                                                1,
                                                1,
                                                Timeout.InfiniteTimeSpan,
                                                TimeSpan.FromMilliseconds(10),
                                                TimeSpan.FromMilliseconds(100)));

            var dropped        = new List <int>(1);
            var autoResetEvent = new AutoResetEvent(false);
            var i = 0;

            list.Cleared += _ =>
            {
                if (++i == 2)
                {
                    autoResetEvent.Set();
                }
                throw new Exception();
            };
            list.Dropped += items => dropped.AddRange(items);

            list.Add(1);
            list.Add(2);
            await Task.Delay(250);

            dropped.Should().HaveCount(1);
            dropped.First().Should().Be(1);
            list.GetFailed().Should().HaveCount(1);
            list.GetFailed().First().Should().Be(2);
        }
Пример #2
0
        public async Task GivenBufferWhenFailedHasAnyShouldDispatchClearForFailedMessages()
        {
            var list           = new BufferList <int>(1, Timeout.InfiniteTimeSpan);
            var autoResetEvent = new AutoResetEvent(false);
            var i = 0;

            list.Cleared += removed =>
            {
                autoResetEvent.Set();
                if (++i == 1)
                {
                    throw new Exception();
                }
            };


            list.Add(1);
            autoResetEvent.WaitOne();
            await Task.Delay(300);

            list.GetFailed().Should().NotBeEmpty();
            list.Clear();
            list.GetFailed().Should().BeEmpty();
        }