protected override Task RunTestAsync( Context context, DisposableDirectory testDirectory, Func <IMemoizationStore, IMemoizationSession, Task> funcAsync, Func <DisposableDirectory, IMemoizationStore> createStoreFunc = null) { return(RunTestAsync( context, testDirectory, async store => { var configuration = ContentStoreConfiguration.CreateWithMaxSizeQuotaMB(1); var configurationModel = new ConfigurationModel(configuration); using (var contentStore = new FileSystemContentStore( FileSystem, SystemClock.Instance, testDirectory.Path, configurationModel)) { try { var startupContentStoreResult = await contentStore.StartupAsync(context); startupContentStoreResult.ShouldBeSuccess(); var contentSessionResult = contentStore.CreateSession(context, Name, ImplicitPin.None); contentSessionResult.ShouldBeSuccess(); var sessionResult = store.CreateSession(context, Name, contentSessionResult.Session); sessionResult.ShouldBeSuccess(); using (var cacheSession = new OneLevelCacheSession(Name, ImplicitPin.None, sessionResult.Session, contentSessionResult.Session)) { try { var r = await cacheSession.StartupAsync(context); r.ShouldBeSuccess(); await funcAsync(store, cacheSession); } finally { var r = await cacheSession.ShutdownAsync(context); r.ShouldBeSuccess(); } } } finally { var shutdownContentStoreResult = await contentStore.ShutdownAsync(context); shutdownContentStoreResult.ShouldBeSuccess(); } } }, createStoreFunc)); }
public Task TestColdStorageWithBulkFunction() { return(RunTestAsync(async(context, store, directory) => { var originalPath = directory.Path / "original.txt"; var fileContents = GetRandomFileContents(); // Build destination IContentSession DisposableDirectory sessionDirectory = new DisposableDirectory(FileSystem); ConfigurationModel configurationModel = new ConfigurationModel(new ContentStoreConfiguration(new MaxSizeQuota("10MB"))); FileSystemContentStore destination = new FileSystemContentStore(FileSystem, SystemClock.Instance, sessionDirectory.Path, configurationModel); _ = await destination.StartupAsync(context); IContentSession contentSession = destination.CreateSession(context, "test_session", BuildXL.Cache.ContentStore.Interfaces.Stores.ImplicitPin.None).Session; _ = await contentSession.StartupAsync(context); // Create the file and hardlink it into the cache. FileSystem.WriteAllText(originalPath, fileContents); var contentHasher = HashInfoLookup.GetContentHasher(HashType.MD5); var contentHash = contentHasher.GetContentHash(Encoding.UTF8.GetBytes(fileContents)); await store.PutFileAsync(context, contentHash, new DisposableFile(context, FileSystem, originalPath), context.Token).ShouldBeSuccess(); FileSystem.DeleteFile(originalPath); FileSystem.FileExists(originalPath).Should().Be(false); ContentHashWithPath contentHashWithPath = new ContentHashWithPath(contentHash, originalPath); List <ContentHashWithPath> listFile = new List <ContentHashWithPath>(); listFile.Add(contentHashWithPath); // Hardlink back to original location trying to replace existing. var copyTask = await store.FetchThenPutBulkAsync( context, listFile, contentSession); await copyTask.ToLookupAwait(r => { return r.Item.Succeeded; }); FileSystem.FileExists(originalPath).Should().Be(false); // The file is in the destination. await contentSession.PlaceFileAsync(context, contentHash, originalPath, FileAccessMode.Write, FileReplacementMode.FailIfExists, FileRealizationMode.Copy, CancellationToken.None).ShouldBeSuccess(); FileSystem.FileExists(originalPath).Should().Be(true); FileSystem.ReadAllText(originalPath).Should().Be(fileContents); _ = await contentSession.ShutdownAsync(context); _ = await destination.ShutdownAsync(context); })); }
private async Task RunTestAsync(Context context, Func <IContentSession, Task> funcAsync) { using (var testDirectory = new DisposableDirectory(FileSystem)) { var rootPath = testDirectory.Path; var configuration = ContentStoreConfiguration.CreateWithMaxSizeQuotaMB(1); var configurationModel = new ConfigurationModel(configuration); using (var store = new FileSystemContentStore( FileSystem, SystemClock.Instance, rootPath, configurationModel)) { try { var startupStoreResult = await store.StartupAsync(context); startupStoreResult.ShouldBeSuccess(); var createResult = store.CreateSession(context, Name, ImplicitPin.None); createResult.ShouldBeSuccess(); using (var session = createResult.Session) { try { var startupSessionResult = await session.StartupAsync(context); startupSessionResult.ShouldBeSuccess(); await funcAsync(session); } finally { var shutdownSessionResult = await session.ShutdownAsync(context); shutdownSessionResult.ShouldBeSuccess(); } } } finally { var shutdownStoreResult = await store.ShutdownAsync(context); shutdownStoreResult.ShouldBeSuccess(); } } } }