public Task PutStreamWritesToExpectedLocation() { return(TestStore(Context, Clock, async store => { using (var memoryStream = new MemoryStream(ThreadSafeRandom.GetBytes(ValueSize))) { await store.PutStreamAsync(Context, memoryStream, ContentHashType, null).ShouldBeSuccess(); } var cacheRoot = store.RootPathForTest; var contentHashRoot = cacheRoot / "Shared" / ContentHashType.ToString(); FileSystem.DirectoryExists(contentHashRoot).Should().BeTrue(); })); }
private async Task UpgradeLegacyVsoHashedContent(bool holdHandleToFile) { var context = new Context(Logger); using (var testDirectory = new DisposableDirectory(FileSystem)) { // Create an empty store. using (var store = Create(testDirectory.Path, _clock)) { await store.StartupAsync(context).ShouldBeSuccess(); await store.ShutdownAsync(context).ShouldBeSuccess(); } // Write a file into the cache corresponding to the generated content directory entry. string emptyFileVsoHashHex = _emptyFileVsoHash.ToHex(); var oldRoot = testDirectory.Path / "Shared" / ((int)HashType.DeprecatedVso0).ToString(); var oldPath = oldRoot / emptyFileVsoHashHex.Substring(0, 3) / (emptyFileVsoHashHex + ".blob"); var newPath = testDirectory.Path / "Shared" / ContentHashType.Serialize() / emptyFileVsoHashHex.Substring(0, 3) / (emptyFileVsoHashHex + ".blob"); FileSystem.CreateDirectory(oldPath.Parent); FileSystem.WriteAllBytes(oldPath, new byte[0]); // Load the store, checking that its content has been upgraded. // In this first pass, we might fail a file move. await TestStore( context, _clock, testDirectory, async store => { Assert.Equal(holdHandleToFile, FileSystem.FileExists(oldPath)); Assert.True(FileSystem.FileExists(newPath)); var contentHash = new ContentHash(ContentHashType, HexUtilities.HexToBytes(emptyFileVsoHashHex)); var contains = await store.ContainsAsync(context, contentHash, null); Assert.True(contains); }, preStartupAction : store => { if (holdHandleToFile) { store.ThrowOnUpgradeLegacyVsoHashedContentDirectoryRename = oldRoot; store.ThrowOnUpgradeLegacyVsoHashedContentDirectoryDelete = oldRoot; store.ThrowOnUpgradeLegacyVsoHashedContentFileRename = oldPath; } }); Assert.Equal(holdHandleToFile, FileSystem.DirectoryExists(oldRoot)); // Load the store, checking that its content has been upgraded. // In this second pass, we might do not fail any file move. await TestStore(context, _clock, testDirectory, async store => { // Make sure the cleanup completed. Assert.False(FileSystem.FileExists(oldPath)); Assert.True(FileSystem.FileExists(newPath)); var contentHash = new ContentHash(ContentHashType, HexUtilities.HexToBytes(emptyFileVsoHashHex)); var contentFileInfo = await store.GetCacheFileInfo(contentHash); Assert.NotNull(contentFileInfo); }); Assert.False(FileSystem.DirectoryExists(oldRoot)); } }