private async Task <StrongFingerprint> PublishValueForRandomStrongFingerprintAsync( Context context, string cacheNamespace, BackingOption backingOption, TimeSpan expiryMinimum, TimeSpan expiryRange) { StrongFingerprint publishedFingerprint = await CreateBackedRandomStrongFingerprintAsync(context, cacheNamespace); Func <DisposableDirectory, ICache> createCache = dir => CreateBareBuildCache( dir, cacheNamespace, FileSystem, Logger, backingOption, ItemStorageOption, expiryMinimum, expiryRange); Func <ICacheSession, Task> publishAsync = async(ICacheSession session) => { ContentHashListWithDeterminism valueToPublish = await CreateRandomContentHashListWithDeterminismAsync(context, true, session); AddOrGetContentHashListResult addOrGetResult = await session.AddOrGetContentHashListAsync( context, publishedFingerprint, valueToPublish, Token); // Ensure the new value was successfully published and that it was the winning value for that key Assert.True(addOrGetResult.Succeeded); Assert.Null(addOrGetResult.ContentHashListWithDeterminism.ContentHashList); }; await RunTestAsync(context, publishAsync, createCache); return(publishedFingerprint); }
protected override ICache CreateCache( DisposableDirectory testDirectory, string cacheNamespace, IAbsFileSystem fileSystem, ILogger logger, BackingOption backingOption, StorageOption storageOption, TimeSpan?expiryMinimum = null, TimeSpan?expiryRange = null) { var innerCache = base.CreateCache(testDirectory, cacheNamespace, fileSystem, logger, backingOption, storageOption, expiryMinimum, expiryRange); return(TestDistributedCacheFactory.CreateCache( logger, innerCache, cacheNamespace, nameof(DistributedWriteNeverBuildCacheSimulationTests), ReadThroughMode.None)); }
private ICache CreateBareBuildCache( DisposableDirectory testDirectory, string cacheNamespace, IAbsFileSystem fileSystem, ILogger logger, BackingOption backingOption, StorageOption storageOption, TimeSpan?expiryMinimum = null, TimeSpan?expiryRange = null) { var vssCredentialsFactory = new VssCredentialsFactory(new VsoCredentialHelper()); IBuildCacheHttpClientFactory buildCacheHttpClientFactory = new BuildCacheHttpClientFactory(new Uri(@"http://*****:*****@"http://localhost:22084"), vssCredentialsFactory, TimeSpan.FromMinutes(BuildCacheServiceConfiguration.DefaultHttpSendTimeoutMinutes), WellKnownDomainIds.OriginalDomainId, false); // Using a consistent path in the test directory allows tests to share content between // multiple callers. Using FileSystemContentStore *will* require the callers to be serialized // because of its need for exclusive access (and the DirectoryLock enforcing it). var writeThroughContentStoreFunc = backingOption == BackingOption.WriteThrough ? (Func <IContentStore>)null : () => new FileSystemContentStore( fileSystem, SystemClock.Instance, testDirectory.Path / "_writeThroughStore", new ConfigurationModel(new ContentStoreConfiguration(new MaxSizeQuota("100MB")))); return(new BuildCacheCache( fileSystem, cacheNamespace, buildCacheHttpClientFactory, backingContentStoreHttpClientFactory, BuildCacheServiceConfiguration.DefaultMaxFingerprintSelectorsToFetch, TimeSpan.FromDays(BuildCacheServiceConfiguration.DefaultDaysToKeepUnreferencedContent), TimeSpan.FromMinutes(BuildCacheServiceConfiguration.DefaultPinInlineThresholdMinutes), TimeSpan.FromMinutes(BuildCacheServiceConfiguration.DefaultIgnorePinThresholdHours), expiryMinimum.GetValueOrDefault(TimeSpan.FromDays(BuildCacheServiceConfiguration.DefaultDaysToKeepContentBags)), expiryRange.GetValueOrDefault(TimeSpan.FromDays(BuildCacheServiceConfiguration.DefaultRangeOfDaysToKeepContentBags)), logger, true, 5, 20, new ByteDomainId(BuildCacheServiceConfiguration.DefaultDomainId), forceUpdateOnAddContentHashList: false, writeThroughContentStoreFunc, backingOption == BackingOption.WriteBehind, storageOption == StorageOption.Blob)); }
private ICache CreateCache( DisposableDirectory testDirectory, string cacheNamespace, IAbsFileSystem fileSystem, ILogger logger, BackingOption backingOption, StorageOption storageOption, TimeSpan?expiryMinimum, TimeSpan?expiryRange, ReadThroughMode readThroughMode) { var innerCache = base.CreateCache(testDirectory, cacheNamespace, fileSystem, logger, backingOption, storageOption, expiryMinimum, expiryRange); return(TestDistributedCacheFactory.CreateCache( logger, innerCache, cacheNamespace, nameof(ReadThroughDistributedWriteBehindBuildCacheSimulationTests), readThroughMode)); }
public async Task IncorporateOnlyStaleFingerprints(BackingOption initialBackingOption) { if (initialBackingOption != BackingOption.WriteThrough && ItemStorageOption != StorageOption.Blob) { // The item-store implementation only exposes expiration to its client when the values are backed // (i.e. Written-Through to BlobStore). // Since the goal is to move everyone towards the Blob implementation, // it's not worth investing in this gap for the Item implementation at this time. return; } TimeSpan staleExpiryMinimum = TimeSpan.FromDays(1); TimeSpan freshExpiryMinimum = TimeSpan.FromDays(7); TimeSpan expiryRange = TimeSpan.FromDays(2); // Setup // Publish 2 (sets of) fingerprints, one with an expiration of 1-3 days and one with an expiration of 7-9 days var context = new Context(Logger); string cacheNamespace = Guid.NewGuid().ToString(); StrongFingerprint staleFingerprint = await PublishValueForRandomStrongFingerprintAsync( context, cacheNamespace, initialBackingOption, staleExpiryMinimum, expiryRange); StrongFingerprint freshFingerprint = await PublishValueForRandomStrongFingerprintAsync( context, cacheNamespace, initialBackingOption, freshExpiryMinimum, expiryRange); IEnumerable <StrongFingerprint> fingerprints = new[] { staleFingerprint, freshFingerprint }; TimeSpan testExpiryMinimum = TimeSpan.FromDays(5); TimeSpan testExpiryRange = TimeSpan.FromDays(7); var startTime = DateTime.UtcNow; // Reference the fingerprints from a client configured to extend stale (younger than 5 days) fingerprints to 5-12 days. await ReferenceStrongFingerprintsAsync( context, cacheNamespace, fingerprints, testExpiryMinimum, testExpiryRange); // Assert that the stale fingerprint has 5-12 days to live await AssertExpirationInRangeAsync( context, cacheNamespace, staleFingerprint, startTime + testExpiryMinimum, startTime + testExpiryMinimum + testExpiryRange); // Assert that the fresh fingerprint has 7-9 days to live await AssertExpirationInRangeAsync( context, cacheNamespace, freshFingerprint, startTime + freshExpiryMinimum, startTime + freshExpiryMinimum + expiryRange); }
protected override ICache CreateCache( DisposableDirectory testDirectory, string cacheNamespace, IAbsFileSystem fileSystem, ILogger logger, BackingOption backingOption, StorageOption storageOption, TimeSpan?expiryMinimum = null, TimeSpan?expiryRange = null) { return(CreateCache( testDirectory, cacheNamespace, fileSystem, logger, backingOption, storageOption, expiryMinimum, expiryRange, readThroughMode: ReadThroughMode.ReadThrough)); }
protected virtual ICache CreateCache( DisposableDirectory testDirectory, string cacheNamespace, IAbsFileSystem fileSystem, ILogger logger, BackingOption backingOption, StorageOption storageOption, TimeSpan?expiryMinimum = null, TimeSpan?expiryRange = null) { return(CreateBareBuildCache(testDirectory, cacheNamespace, fileSystem, logger, backingOption, storageOption, expiryMinimum, expiryRange)); }
protected BuildCacheSimulationTests(ILogger logger, BackingOption backingOption, StorageOption itemStorageOption) : base(() => new PassThroughFileSystem(logger), logger) { _backingOption = backingOption; ItemStorageOption = itemStorageOption; }