Example #1
0
        public void GetPeriodsAfterShouldReturnPeriodsPartiallyAfter()
        {
            var periodBefore = START_DATETIME.Length(5.secs()).Active();
            var period       = periodBefore.NewPeriodAfter(10.secs()).Length(5.secs()).Idle();

            using (PeriodStorage periodStorageSUT = GetStorage())
            {
                periodStorageSUT.Add(periodBefore);
                periodStorageSUT.Add(period);
                var expected = new ActivityPeriod[] { period };

                var beforeStart = period.Start - 1.secs();
                var found       = periodStorageSUT.GetPeriodsAfter(beforeStart);
                CollectionAssert.AreEquivalent(expected, found);

                var afterStart = period.Start + 1.secs();
                found = periodStorageSUT.GetPeriodsAfter(afterStart);
                CollectionAssert.AreEquivalent(expected, found);

                var atEnd = period.End;
                found = periodStorageSUT.GetPeriodsAfter(atEnd);
                CollectionAssert.AreEquivalent(new ActivityPeriod[] { }, found);

                var afterEnd = period.End + 1.secs();
                found = periodStorageSUT.GetPeriodsAfter(afterEnd);
                CollectionAssert.AreEquivalent(new ActivityPeriod[] { }, found);
            }
        }
Example #2
0
        private SortedSet <ActivityPeriod> GetMergeCandidates(ActivityPeriod currentPeriod)
        {
            var mergeTimeWindowStart = currentPeriod.Start - policies.IdleTimeout;
            var candidates           = periodStorage.GetPeriodsAfter(mergeTimeWindowStart)
                                       .Where(period => !period.Equals(currentPeriod));

            return(new SortedSet <ActivityPeriod>(candidates));
        }