Exemplo n.º 1
0
        public void WhenPackageIsRegistered_ThenUsageIsRecorded()
        {
            var thePackage    = CreatePackageIdentity("Package", "1.0");
            var deploymentOne = new ServerTaskId("Deployment-1");

            packageJournal.RegisterPackageUse(thePackage, deploymentOne, 1);

            Assert.AreEqual(1, journalRepository.GetUsage(thePackage).Count());
        }
Exemplo n.º 2
0
        public void WhenRetentionIsAppliedAndCacheSpaceIsSufficientButDiskSpaceIsNot_ThenPackageFileAndUsageAreRemoved()
        {
            var existingPackage = CreatePackageIdentity("PackageOne", "1.0");

            var retentionAlgorithm = Substitute.For <IRetentionAlgorithm>();

            retentionAlgorithm.GetPackagesToRemove(Arg.Any <IEnumerable <JournalEntry> >()).Returns(new List <PackageIdentity>()
            {
                existingPackage
            });

            var fileSystem = Substitute.For <ICalamariFileSystem>();

            fileSystem.FileExists(existingPackage.Path.Value).Returns(true);
            fileSystem.GetDiskFreeSpace(Arg.Any <string>(), out _)
            .Returns(x =>
            {
                x[1] = 0.5M;                    // 0.5MB free
                return(true);
            });

            var thisRepository = new InMemoryJournalRepository();
            var thisJournal    = new PackageJournal(thisRepository,
                                                    Substitute.For <ILog>(),
                                                    fileSystem,
                                                    retentionAlgorithm,
                                                    Substitute.For <ISemaphoreFactory>());

            thisJournal.RegisterPackageUse(existingPackage, new ServerTaskId("Deployment-1"), 1 * 1024 * 1024); //Package is 1 MB
            thisJournal.ApplyRetention();

            thisRepository.GetUsage(existingPackage).Should().BeEmpty();
            fileSystem.Received().DeleteFile(existingPackage.Path.Value, FailureOptions.IgnoreFailure);
        }
Exemplo n.º 3
0
        public void WhenRetentionIsApplied_ThenPackageFileAndUsageAreRemoved()
        {
            var packageOne = CreatePackageIdentity("PackageOne", "1.0");

            var retentionAlgorithm = Substitute.For <IRetentionAlgorithm>();

            retentionAlgorithm.GetPackagesToRemove(Arg.Any <IEnumerable <JournalEntry> >()).Returns(new List <PackageIdentity>()
            {
                packageOne
            });

            var fileSystem = Substitute.For <ICalamariFileSystem>();

            fileSystem.FileExists(packageOne.Path.Value).Returns(true);

            var thisRepository = new InMemoryJournalRepository();
            var thisJournal    = new PackageJournal(thisRepository,
                                                    Substitute.For <ILog>(),
                                                    fileSystem,
                                                    retentionAlgorithm,
                                                    Substitute.For <ISemaphoreFactory>());

            thisJournal.RegisterPackageUse(packageOne, new ServerTaskId("Deployment-1"), 1000);
            thisJournal.ApplyRetention();

            thisRepository.GetUsage(packageOne).Should().BeEmpty();
            fileSystem.Received().DeleteFile(packageOne.Path.Value, FailureOptions.IgnoreFailure);
        }