public JournalEntry(PackageIdentity package, ulong fileSizeBytes, PackageLocks packageLocks = null, PackageUsages packageUsages = null) { Package = package ?? throw new ArgumentNullException(nameof(package)); FileSizeBytes = fileSizeBytes; locks = packageLocks ?? new PackageLocks(); usages = packageUsages ?? new PackageUsages(); }
public LocalPackageInfo(PackageReference reference, PackageDownloadInfo downloadStatus, Dto.PackageHashes hashes, Dto.PackageMeta metadata, PackageSequenceInfo sequence) { LockProvider = new PackageLocks(); DownloadMeasure = new MeasureItem(MeasureType.Throughput); UploadMeasure = new MeasureItem(MeasureType.Throughput); Reference = reference ?? throw new ArgumentNullException(nameof(reference)); DownloadStatus = downloadStatus ?? throw new ArgumentNullException(nameof(downloadStatus)); Hashes = hashes ?? throw new ArgumentNullException(nameof(hashes)); Metadata = metadata ?? throw new ArgumentNullException(nameof(metadata)); Sequence = sequence ?? throw new ArgumentNullException(nameof(sequence)); if (!Reference.Id.Equals(DownloadStatus.PackageId)) { throw new ArgumentException("Invalid hash.", nameof(downloadStatus)); } if (!Reference.Id.Equals(Hashes.PackageId)) { throw new ArgumentException("Invalid hash.", nameof(hashes)); } if (!Reference.Id.Equals(Metadata.PackageId)) { throw new ArgumentException("Invalid hash.", nameof(metadata)); } if (!Metadata.PackageSize.Equals(Sequence.PackageSize)) { throw new ArgumentException("Invalid size of package sequence.", nameof(sequence)); } }
public void WhenStaleLocksAreExpired_TheLocksAreRemoved() { var thePackage = CreatePackageIdentity("Package", "1.0"); var packageLocks = new PackageLocks { new UsageDetails(new ServerTaskId("Deployment-1"), new CacheAge(1), new DateTime(2021, 1, 1)) }; var journalEntry = new JournalEntry(thePackage, 1, packageLocks); var journalEntries = new Dictionary <PackageIdentity, JournalEntry>() { { thePackage, journalEntry } }; var testJournal = new PackageJournal(new InMemoryJournalRepository(journalEntries), Substitute.For <ILog>(), Substitute.For <ICalamariFileSystem>(), Substitute.For <IRetentionAlgorithm>(), Substitute.For <ISemaphoreFactory>()); testJournal.ExpireStaleLocks(TimeSpan.FromDays(14)); Assert.IsFalse(journalRepository.HasLock(thePackage)); }
public void OnlyStaleLocksAreExpired() { var packageOne = CreatePackageIdentity("PackageOne", "1.0"); var packageTwo = CreatePackageIdentity("PackageTwo", "1.0"); var packageOneLocks = new PackageLocks { new UsageDetails(new ServerTaskId("Deployment-1"), new CacheAge(1), new DateTime(2021, 1, 1)), }; var packageTwoLocks = new PackageLocks { new UsageDetails(new ServerTaskId("Deployment-2"), new CacheAge(1), DateTime.Now), }; var packageOneJournalEntry = new JournalEntry(packageOne, 1, packageOneLocks); var packageTwoJournalEntry = new JournalEntry(packageTwo, 1, packageTwoLocks); var journalEntries = new Dictionary <PackageIdentity, JournalEntry>() { { packageOne, packageOneJournalEntry }, { packageTwo, packageTwoJournalEntry } }; var testJournalRepository = new InMemoryJournalRepository(journalEntries); var testJournal = new PackageJournal(testJournalRepository, Substitute.For <ILog>(), Substitute.For <ICalamariFileSystem>(), Substitute.For <IRetentionAlgorithm>(), Substitute.For <ISemaphoreFactory>()); testJournal.ExpireStaleLocks(TimeSpan.FromDays(14)); Assert.IsFalse(testJournalRepository.HasLock(packageOne)); Assert.IsTrue(testJournalRepository.HasLock(packageTwo)); }