Beispiel #1
0
        public void PopExpiredGroups_ExpiredGroups_Should_Return()
        {
            var delayedGroupCache = new DelayedGroupCache <MockItem>();
            var delaySpan         = TimeSpan.FromSeconds(2);
            var groupCount        = 5;
            var itemCount         = 3;
            var spanSecond        = 1;
            var startAt           = _mockNow;

            //0:00,0:01,0:02
            //     0:01,0:02,0:03
            //          0:02,0:03,0:04
            //               0:03,0:04,0:05
            //                    0:04,0:05,0:06
            //pop at: [0:06]
            //expired groups: early than [0:06] - 2 = [0.04] => group 0,1,2 should return

            delayedGroupCache.DelaySpan = delaySpan;
            var mockCommands = CreateGroupCommands(groupCount, itemCount, spanSecond, startAt);

            delayedGroupCache.AppendToGroups(mockCommands, item => item.GroupKey, item => item.CreateAt);
            var popAt            = mockCommands.Max(x => x.CreateAt);
            var popExpiredGroups = delayedGroupCache.PopExpiredGroups(popAt);

            ShowCache(delayedGroupCache);
            CheckGroups(popExpiredGroups, itemCount, 3);
        }
Beispiel #2
0
        public void AppendToGroups_GetGroupKeyNull_Should_Throws()
        {
            AssertHelper.ShouldThrows <ArgumentNullException>(() =>
            {
                var delayedGroupCache = new DelayedGroupCache <MockItem>();
                delayedGroupCache.AppendToGroups(new List <MockItem>(), null, item => item.CreateAt);
            });

            AssertHelper.ShouldThrows <ArgumentNullException>(() =>
            {
                var delayedGroupCache = new DelayedGroupCache <MockItem>();
                delayedGroupCache.AppendToGroups(new List <MockItem>(), item => item.GroupKey, null);
            });
        }
Beispiel #3
0
        public void AppendToGroups_ComputeGroups_Should_Ok()
        {
            var delayedGroupCache = new DelayedGroupCache <MockItem>();
            var groupCount        = 5;
            var itemCount         = 3;
            var spanSecond        = 1;
            var startAt           = _mockNow;
            //0:00,0:01,0:02
            //     0:01,0:02,0:03
            //          0:02,0:03,0:04
            //               0:03,0:04,0:05
            //                    0:04,0:05,0:06
            var mockCommands = CreateGroupCommands(groupCount, itemCount, spanSecond, startAt);

            delayedGroupCache.AppendToGroups(mockCommands, item => item.GroupKey, item => item.CreateAt);
            var delayedGroups = delayedGroupCache.DelayedGroups.Values.ToList();

            CheckGroups(delayedGroups, itemCount, groupCount);
        }
Beispiel #4
0
        public void AppendToGroups_ItemsNullOrEmpty_Should_NoEffect()
        {
            var delayedGroupCache = new DelayedGroupCache <MockItem>();

            delayedGroupCache.AppendToGroups(null, item => item.GroupKey, item => item.CreateAt);
        }