Пример #1
0
        public async Task FlushBySizeTest()
        {
            var buffer             = new BufferWithFifoEviction <string>(1000, new StringLengthCostAssigner());
            var bufferFlushingTask = new DummyBufferFlushingTask(buffer, TimeSpan.MaxValue, 3, "No-Name");

            await bufferFlushingTask.Run();

            Assert.Equal(0, bufferFlushingTask.SentOut.Count);

            buffer.Add("msg1");
            buffer.Add("msg2");
            await bufferFlushingTask.Run();

            Assert.Equal(0, bufferFlushingTask.SentOut.Count);

            buffer.Add("msg3");
            await bufferFlushingTask.Run();

            Assert.Equal(1, bufferFlushingTask.SentOut.Count);

            Assert.Equal(3, bufferFlushingTask.SentOut[0].Count);
            Assert.Equal(new List <string>()
            {
                "msg1", "msg2", "msg3"
            }, bufferFlushingTask.SentOut[0]);
        }
Пример #2
0
        public void InsertMoreElementAndDrainToTest()
        {
            int offset = 5;
            BufferWithFifoEviction <string> buffer = new BufferWithFifoEviction <string>(5, new StringLengthCostAssigner());

            for (int i = 0; i < buffer.Capacity; i++)
            {
                string a = i.ToString(CultureInfo.CurrentCulture);
                Assert.True(buffer.Add(a));
            }

            long limit = buffer.Capacity + offset;

            for (int i = 5; i < limit; i++)
            {
                string a = i.ToString(CultureInfo.CurrentCulture);
                Assert.True(buffer.Add(a));
            }

            Assert.Equal(5, buffer.Count);

            var drainedItems = new List <string>();

            buffer.DrainTo(drainedItems);
            for (int i = 0; i < buffer.Capacity; i++)
            {
                long expected = i + offset;
                Assert.Equal(expected.ToString(CultureInfo.CurrentCulture), drainedItems[i]);
            }
        }
 public void TryToInsertMoreElementTest()
 {
     var buffer = new BufferWithFifoEviction<string>(2, new StringLengthCostAssigner());
     Assert.True(buffer.Add(BuildStringOfSize(2)));
     Assert.True(buffer.Add(BuildStringOfSize(1)));
     Assert.True(buffer.Add(BuildStringOfSize(1)));
     Assert.False(buffer.Add(BuildStringOfSize(5)));
     Assert.Equal(2, buffer.Count);
 }
Пример #4
0
        public void TryToInsertMoreElementTest()
        {
            var buffer = new BufferWithFifoEviction <string>(2, new StringLengthCostAssigner());

            Assert.True(buffer.Add(BuildStringOfSize(2)));
            Assert.True(buffer.Add(BuildStringOfSize(1)));
            Assert.True(buffer.Add(BuildStringOfSize(1)));
            Assert.False(buffer.Add(BuildStringOfSize(5)));
            Assert.Equal(2, buffer.Count);
        }
        public void FlushWithNPlusOneElementsTest()
        {
            var buffer             = new BufferWithFifoEviction <string>(1000, new StringLengthCostAssigner());
            var bufferFlushingTask = new DummyBufferFlushingTask(buffer, TimeSpan.MaxValue, 3, "No-Name");

            buffer.Add("msg1");
            buffer.Add("msg2");
            buffer.Add("msg3");
            buffer.Add("msg4");
            bufferFlushingTask.Run();
            Assert.Equal(4, bufferFlushingTask.SentOut[0].Count);
        }
        public void FlushWithNPlusOneElementsTest()
        {
            var buffer = new BufferWithFifoEviction<string>(1000, new StringLengthCostAssigner());
            var bufferFlushingTask = new DummyBufferFlushingTask(buffer, TimeSpan.MaxValue, 3, "No-Name");

            buffer.Add("msg1");
            buffer.Add("msg2");
            buffer.Add("msg3");
            buffer.Add("msg4");
            bufferFlushingTask.Run();
            Assert.Equal(4, bufferFlushingTask.SentOut[0].Count);
        }
        public void FlushWhenBufferCapacityIsSmallTest()
        {
            var buffer             = new BufferWithFifoEviction <string>(12, new StringLengthCostAssigner());
            var bufferFlushingTask = new DummyBufferFlushingTask(buffer, TimeSpan.MaxValue, 3, "No-Name");

            buffer.Add("msg1");
            buffer.Add("msg2");
            buffer.Add("msg3");
            buffer.Add("msg4");
            bufferFlushingTask.Run();
            Assert.Equal(3, bufferFlushingTask.SentOut[0].Count);
            Assert.Equal(new List <string>()
            {
                "msg2", "msg3", "msg4"
            }, bufferFlushingTask.SentOut[0]);
        }
        public void FlushBySizeTest()
        {
            var buffer = new BufferWithFifoEviction<string>(1000, new StringLengthCostAssigner());
            var bufferFlushingTask = new DummyBufferFlushingTask(buffer, TimeSpan.MaxValue, 3, "No-Name");

            bufferFlushingTask.Run();
            Assert.Equal(0, bufferFlushingTask.SentOut.Count);

            buffer.Add("msg1");
            buffer.Add("msg2");
            bufferFlushingTask.Run();
            Assert.Equal(0, bufferFlushingTask.SentOut.Count);

            buffer.Add("msg3");
            bufferFlushingTask.Run();
            Assert.Equal(1, bufferFlushingTask.SentOut.Count);

            Assert.Equal(bufferFlushingTask.SentOut[0].Count, 3);
            Assert.Equal(bufferFlushingTask.SentOut[0], new List<string>() { "msg1", "msg2", "msg3" });
        }
        public void DrainToTest()
        {           
            var buffer = new BufferWithFifoEviction<string>(10, new StringLengthCostAssigner());
            for (int i = 0; i < buffer.Capacity; i++)
            {
                string a = i.ToString(CultureInfo.CurrentCulture);
                Assert.True(buffer.Add(a));
            }

            Assert.Equal(10, buffer.Count);

            var drainedItems = new List<string>();
            buffer.DrainTo(drainedItems);
            for (int i = 0; i < drainedItems.Count; i++)
            {
                Assert.Equal(i.ToString(CultureInfo.CurrentCulture), drainedItems[i]);
            }
        }
Пример #10
0
        public void DrainToTest()
        {
            var buffer = new BufferWithFifoEviction <string>(10, new StringLengthCostAssigner());

            for (int i = 0; i < buffer.Capacity; i++)
            {
                string a = i.ToString(CultureInfo.CurrentCulture);
                Assert.True(buffer.Add(a));
            }

            Assert.Equal(10, buffer.Count);

            var drainedItems = new List <string>();

            buffer.DrainTo(drainedItems);
            for (int i = 0; i < drainedItems.Count; i++)
            {
                Assert.Equal(i.ToString(CultureInfo.CurrentCulture), drainedItems[i]);
            }
        }
 public void FlushWhenBufferCapacityIsSmallTest()
 {
     var buffer = new BufferWithFifoEviction<string>(12, new StringLengthCostAssigner());
     var bufferFlushingTask = new DummyBufferFlushingTask(buffer, TimeSpan.MaxValue, 3, "No-Name");
     buffer.Add("msg1");
     buffer.Add("msg2");
     buffer.Add("msg3");
     buffer.Add("msg4");
     bufferFlushingTask.Run();
     Assert.Equal(3, bufferFlushingTask.SentOut[0].Count);
     Assert.Equal(new List<string>() { "msg2", "msg3", "msg4" }, bufferFlushingTask.SentOut[0]);
 }      
        public void InsertMoreElementAndDrainToTest()
        {
            int offset = 5;
            BufferWithFifoEviction<string> buffer = new BufferWithFifoEviction<string>(5, new StringLengthCostAssigner());
            for (int i = 0; i < buffer.Capacity; i++)
            {
                string a = i.ToString(CultureInfo.CurrentCulture);
                Assert.True(buffer.Add(a));
            }

            long limit = buffer.Capacity + offset;
            for (int i = 5; i < limit; i++)
            {
                string a = i.ToString(CultureInfo.CurrentCulture);
                Assert.True(buffer.Add(a));
            }

            Assert.Equal(5, buffer.Count);

            var drainedItems = new List<string>();
            buffer.DrainTo(drainedItems);
            for (int i = 0; i < buffer.Capacity; i++)
            {
                long expected = i + offset;
                Assert.Equal(expected.ToString(CultureInfo.CurrentCulture), drainedItems[i]);
            }
        }