Esempio n. 1
0
        public void Performs()
        {
            var journalRepo = SeedJournal();

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            var algo   = new LeastFrequentlyUsedWithAgingSort();
            var result = algo
                         .Sort(journalRepo.GetAllJournalEntries())
                         .ToList();

            result.Should().NotBeEmpty();
            stopWatch.Stop();
            stopWatch.Elapsed.Should().BeLessThan(TimeSpan.FromSeconds(10));
        }
        public void WhenPackageIsLocked_ThenDoNotConsiderItForRemoval()
        {
            var lfu = new LeastFrequentlyUsedWithAgingSort();

            //If this entry wasn't locked, we would expect it to be removed
            var lockedEntry = CreateEntry("package-locked", "1.0", 20, ("task-1", 1));

            lockedEntry.AddLock(new ServerTaskId("task-0"), new CacheAge(1));

            //This entry would not be removed if the locked entry wasn't locked, because it has multiple, more recent usages.
            var unlockedEntry = CreateEntry("package-unlocked",
                                            "1.0",
                                            20,
                                            ("task-2", 12),
                                            ("task-3", 15));

            var entries          = new List <JournalEntry>(new[] { lockedEntry, unlockedEntry });
            var packagesToRemove = lfu.Sort(entries);

            packagesToRemove.Select(p => p.Package).Should().Equal(CreatePackageIdentity("package-unlocked", "1.0"));
        }