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
 private void ShowCache(DelayedGroupCache <MockItem> cache)
 {
     "-------cache info--------".Log();
     foreach (var delayedGroup in cache.DelayedGroups.Values)
     {
         string.Format("{0} count: {1}, LastItemDate: {2:yyyy-MM-dd HH:ss:mm}", delayedGroup.GroupKey, delayedGroup.Items.Count, delayedGroup.LastItemDate).Log();
     }
     "-------------------------".Log();
     "".Log();
 }
Beispiel #3
0
        public void PopExpiredGroups_Empty_Should_Return_Empty()
        {
            var delayedGroupCache = new DelayedGroupCache <MockItem>();
            var delaySpan         = TimeSpan.FromSeconds(2);

            delayedGroupCache.DelaySpan = delaySpan;
            var popAt            = _mockNow.AddSeconds(10);
            var popExpiredGroups = delayedGroupCache.PopExpiredGroups(popAt);

            ShowCache(delayedGroupCache);
            CheckGroups(popExpiredGroups, 0, 0);
        }
Beispiel #4
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 #5
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 #6
0
        public void AppendToGroups_ItemsNullOrEmpty_Should_NoEffect()
        {
            var delayedGroupCache = new DelayedGroupCache <MockItem>();

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