Beispiel #1
0
        public void BackgroundOperationCountMatchesBackgroundFileSystemTaskRunner()
        {
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1);
            Mock <ISparseCollection> mockSparseDb = new Mock <ISparseCollection>(MockBehavior.Strict);

            mockSparseDb.Setup(x => x.GetAll()).Returns(new HashSet <string>());
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                           this.Repo.Context,
                           this.Repo.GitObjects,
                           RepoMetadata.Instance,
                           new MockBlobSizes(),
                           gitIndexProjection: null,
                           backgroundFileSystemTaskRunner: backgroundTaskRunner,
                           fileSystemVirtualizer: null,
                           placeholderDatabase: mockPlaceholderDb.Object,
                           sparseCollection: mockSparseDb.Object))
                {
                    fileSystemCallbacks.BackgroundOperationCount.ShouldEqual(backgroundTaskRunner.Count);

                    fileSystemCallbacks.OnFileConvertedToFull("Path1.txt");
                    fileSystemCallbacks.OnFileConvertedToFull("Path2.txt");
                    backgroundTaskRunner.Count.ShouldEqual(2);
                    fileSystemCallbacks.BackgroundOperationCount.ShouldEqual(backgroundTaskRunner.Count);
                }

            mockPlaceholderDb.VerifyAll();
            mockSparseDb.VerifyAll();
        }
Beispiel #2
0
        public void GetMetadataForHeartBeatDoesNotChangeEventLevelWhenNoPlaceholderHaveBeenCreated()
        {
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(0);
            mockPlaceholderDb.Setup(x => x.GetFilePlaceholdersCount()).Returns(() => 0);
            mockPlaceholderDb.Setup(x => x.GetFolderPlaceholdersCount()).Returns(() => 0);
            Mock <ISparseCollection> mockSparseDb = new Mock <ISparseCollection>(MockBehavior.Strict);

            mockSparseDb.Setup(x => x.GetAll()).Returns(new HashSet <string>());
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                           this.Repo.Context,
                           this.Repo.GitObjects,
                           RepoMetadata.Instance,
                           new MockBlobSizes(),
                           gitIndexProjection: null,
                           backgroundFileSystemTaskRunner: backgroundTaskRunner,
                           fileSystemVirtualizer: null,
                           placeholderDatabase: mockPlaceholderDb.Object,
                           sparseCollection: mockSparseDb.Object))
                {
                    EventMetadata metadata   = fileSystemCallbacks.GetAndResetHeartBeatMetadata(out bool writeToLogFile);
                    EventLevel    eventLevel = writeToLogFile ? EventLevel.Informational : EventLevel.Verbose;
                    eventLevel.ShouldEqual(EventLevel.Verbose);

                    // "ModifiedPathsCount" should be 1 because ".gitattributes" is always present
                    metadata.ShouldContain("ModifiedPathsCount", 1);
                    metadata.ShouldContain("FilePlaceholderCount", 0);
                    metadata.ShouldContain(nameof(RepoMetadata.Instance.EnlistmentId), RepoMetadata.Instance.EnlistmentId);
                }

            mockPlaceholderDb.VerifyAll();
            mockSparseDb.VerifyAll();
        }
        public void OnEnumerateDirectorySetsFileModes()
        {
            const string TestFile644Name = "test644.txt";
            const string TestFile664Name = "test664.txt";
            const string TestFile755Name = "test755.txt";
            const string TestFolderName  = "testFolder";
            string       testFile644Path = Path.Combine(TestFolderName, TestFile644Name);
            string       testFile664Path = Path.Combine(TestFolderName, TestFile664Name);
            string       testFile755Path = Path.Combine(TestFolderName, TestFile755Name);
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1);
            Mock <ISparseCollection> mockSparseDb = new Mock <ISparseCollection>(MockBehavior.Strict);

            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())

                    // Don't include TestFolderName as MockGitIndexProjection returns the same list of files regardless of what folder name
                    // it is passed
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { TestFile644Name, TestFile664Name, TestFile755Name }))
                        using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization))
                            using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                       this.Repo.Context,
                                       this.Repo.GitObjects,
                                       RepoMetadata.Instance,
                                       new MockBlobSizes(),
                                       gitIndexProjection,
                                       backgroundTaskRunner,
                                       virtualizer,
                                       mockPlaceholderDb.Object,
                                       mockSparseDb.Object))
                            {
                                gitIndexProjection.MockFileTypesAndModes.TryAdd(
                                    testFile644Path,
                                    ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.Regular, GitIndexProjection.FileMode644));
                                gitIndexProjection.MockFileTypesAndModes.TryAdd(
                                    testFile664Path,
                                    ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.Regular, GitIndexProjection.FileMode664));
                                gitIndexProjection.MockFileTypesAndModes.TryAdd(
                                    testFile755Path,
                                    ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.Regular, GitIndexProjection.FileMode755));

                                string error;
                                fileSystemCallbacks.TryStart(out error).ShouldEqual(true);

                                Guid enumerationGuid = Guid.NewGuid();
                                gitIndexProjection.EnumerationInMemory = true;
                                mockVirtualization.OnEnumerateDirectory(1, TestFolderName, triggeringProcessId: 1, triggeringProcessName: "UnitTests").ShouldEqual(Result.Success);
                                mockVirtualization.CreatedPlaceholders.ShouldContain(
                                    kvp => kvp.Key.Equals(testFile644Path, StringComparison.OrdinalIgnoreCase) && kvp.Value == GitIndexProjection.FileMode644);
                                mockVirtualization.CreatedPlaceholders.ShouldContain(
                                    kvp => kvp.Key.Equals(testFile664Path, StringComparison.OrdinalIgnoreCase) && kvp.Value == GitIndexProjection.FileMode664);
                                mockVirtualization.CreatedPlaceholders.ShouldContain(
                                    kvp => kvp.Key.Equals(testFile755Path, StringComparison.OrdinalIgnoreCase) && kvp.Value == GitIndexProjection.FileMode755);
                                fileSystemCallbacks.Stop();
                            }

            mockPlaceholderDb.VerifyAll();
            mockSparseDb.VerifyAll();
        }
Beispiel #4
0
 public void TestFileSystemOperationsInvalidateStatusCache()
 {
     using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
         using (MockFileSystemVirtualizer fileSystemVirtualizer = new MockFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects))
             using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" }))
                 using (MockGitStatusCache gitStatusCache = new MockGitStatusCache(this.Repo.Context, TimeSpan.Zero))
                     using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                this.Repo.Context,
                                this.Repo.GitObjects,
                                RepoMetadata.Instance,
                                new MockBlobSizes(),
                                gitIndexProjection: gitIndexProjection,
                                backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                fileSystemVirtualizer: fileSystemVirtualizer,
                                gitStatusCache: gitStatusCache))
                     {
                         this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileConvertedToFull, "OnFileConvertedToFull.txt", FileSystemTask.OperationType.OnFileConvertedToFull);
                         this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileCreated, "OnFileCreated.txt", FileSystemTask.OperationType.OnFileCreated);
                         this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileDeleted, "OnFileDeleted.txt", FileSystemTask.OperationType.OnFileDeleted);
                         this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileOverwritten, "OnFileDeleted.txt", FileSystemTask.OperationType.OnFileOverwritten);
                         this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileSuperseded, "OnFileSuperseded.txt", FileSystemTask.OperationType.OnFileSuperseded);
                         this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFolderCreated, "OnFileSuperseded.txt", FileSystemTask.OperationType.OnFolderCreated);
                         this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFolderDeleted, "OnFileSuperseded.txt", FileSystemTask.OperationType.OnFolderDeleted);
                         this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileConvertedToFull, "OnFileConvertedToFull.txt", FileSystemTask.OperationType.OnFileConvertedToFull);
                     }
 }
        public void TestFileSystemOperationsInvalidateStatusCache()
        {
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1);
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockFileSystemVirtualizer fileSystemVirtualizer = new MockFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects))
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" }))
                        using (MockGitStatusCache gitStatusCache = new MockGitStatusCache(this.Repo.Context, TimeSpan.Zero))
                            using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                       this.Repo.Context,
                                       this.Repo.GitObjects,
                                       RepoMetadata.Instance,
                                       new MockBlobSizes(),
                                       gitIndexProjection: gitIndexProjection,
                                       backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                       fileSystemVirtualizer: fileSystemVirtualizer,
                                       placeholderDatabase: mockPlaceholderDb.Object,
                                       gitStatusCache: gitStatusCache))
                            {
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileConvertedToFull, "OnFileConvertedToFull.txt", FileSystemTask.OperationType.OnFileConvertedToFull);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileCreated, "OnFileCreated.txt", FileSystemTask.OperationType.OnFileCreated);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileDeleted, "OnFileDeleted.txt", FileSystemTask.OperationType.OnFileDeleted);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileOverwritten, "OnFileDeleted.txt", FileSystemTask.OperationType.OnFileOverwritten);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileSuperseded, "OnFileSuperseded.txt", FileSystemTask.OperationType.OnFileSuperseded);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFolderCreated, "OnFileSuperseded.txt", FileSystemTask.OperationType.OnFolderCreated);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFolderDeleted, "OnFileSuperseded.txt", FileSystemTask.OperationType.OnFolderDeleted);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileConvertedToFull, "OnFileConvertedToFull.txt", FileSystemTask.OperationType.OnFileConvertedToFull);
                            }

            mockPlaceholderDb.VerifyAll();
        }
        public void OnEnumerateDirectorySetsFileModes()
        {
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test644.txt", "test664.txt", "test755.txt" }))
                        using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization))
                            using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                       this.Repo.Context,
                                       this.Repo.GitObjects,
                                       RepoMetadata.Instance,
                                       new MockBlobSizes(),
                                       gitIndexProjection,
                                       backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                       fileSystemVirtualizer: virtualizer))
                            {
                                gitIndexProjection.MockFileModes.TryAdd("test" + Path.DirectorySeparatorChar + "test644.txt", FileMode644);
                                gitIndexProjection.MockFileModes.TryAdd("test" + Path.DirectorySeparatorChar + "test664.txt", FileMode664);
                                gitIndexProjection.MockFileModes.TryAdd("test" + Path.DirectorySeparatorChar + "test755.txt", FileMode755);

                                string error;
                                fileSystemCallbacks.TryStart(out error).ShouldEqual(true);

                                Guid enumerationGuid = Guid.NewGuid();
                                gitIndexProjection.EnumerationInMemory = true;
                                mockVirtualization.OnEnumerateDirectory(1, "test", triggeringProcessId: 1, triggeringProcessName: "UnitTests").ShouldEqual(Result.Success);
                                mockVirtualization.CreatedPlaceholders.ShouldContain(
                                    kvp => kvp.Key.Equals(Path.Combine("test", "test644.txt"), StringComparison.OrdinalIgnoreCase) && kvp.Value == FileMode644);
                                mockVirtualization.CreatedPlaceholders.ShouldContain(
                                    kvp => kvp.Key.Equals(Path.Combine("test", "test664.txt"), StringComparison.OrdinalIgnoreCase) && kvp.Value == FileMode664);
                                mockVirtualization.CreatedPlaceholders.ShouldContain(
                                    kvp => kvp.Key.Equals(Path.Combine("test", "test755.txt"), StringComparison.OrdinalIgnoreCase) && kvp.Value == FileMode755);
                                fileSystemCallbacks.Stop();
                            }
        }
        public void UpdatePlaceholderToSymLink()
        {
            const string PlaceholderToLinkFileName          = "testUpdatePlaceholderToLink.txt";
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1);
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { PlaceholderToLinkFileName }))
                        using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization))
                            using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                       this.Repo.Context,
                                       this.Repo.GitObjects,
                                       RepoMetadata.Instance,
                                       new MockBlobSizes(),
                                       gitIndexProjection,
                                       backgroundTaskRunner,
                                       virtualizer,
                                       mockPlaceholderDb.Object))
                            {
                                gitIndexProjection.MockFileTypesAndModes.TryAdd(
                                    PlaceholderToLinkFileName,
                                    ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.SymLink, fileMode: 0));

                                string error;
                                fileSystemCallbacks.TryStart(out error).ShouldEqual(true);

                                UpdateFailureReason failureReason = UpdateFailureReason.NoFailure;

                                mockVirtualization.UpdatePlaceholderIfNeededResult       = Result.Success;
                                mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.NoFailure;
                                virtualizer
                                .UpdatePlaceholderIfNeeded(
                                    PlaceholderToLinkFileName,
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    0,
                                    15,
                                    string.Empty,
                                    UpdatePlaceholderType.AllowReadOnly,
                                    out failureReason)
                                .ShouldEqual(new FileSystemResult(FSResult.Ok, (int)mockVirtualization.UpdatePlaceholderIfNeededResult));
                                failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause);
                                mockVirtualization.UpdatedPlaceholders.Count.ShouldEqual(0, "UpdatePlaceholderIfNeeded should not be called when converting a placeholder to a link");
                                mockVirtualization.CreatedSymLinks.Count.ShouldEqual(1);
                                mockVirtualization.CreatedSymLinks.ShouldContain(entry => entry.Equals(PlaceholderToLinkFileName));

                                // Creating a symlink should schedule a background task
                                backgroundTaskRunner.Count.ShouldEqual(1);
                                backgroundTaskRunner.BackgroundTasks[0].Operation.ShouldEqual(GVFS.Virtualization.Background.FileSystemTask.OperationType.OnFileSymLinkCreated);
                                backgroundTaskRunner.BackgroundTasks[0].VirtualPath.ShouldEqual(PlaceholderToLinkFileName);

                                fileSystemCallbacks.Stop();
                            }

            mockPlaceholderDb.VerifyAll();
        }
Beispiel #8
0
        public void GetMetadataForHeartBeatDoesSetsEventLevelWToInformationalWhenPlaceholdersHaveBeenCreated()
        {
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);
            int placeholderCount = 0;

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(() => placeholderCount);
            mockPlaceholderDb.Setup(x => x.AddFile("test.txt", "1111122222333334444455555666667777788888")).Callback(() => ++ placeholderCount);
            mockPlaceholderDb.Setup(x => x.AddFile("test.txt", "2222233333444445555566666777778888899999")).Callback(() => ++ placeholderCount);
            mockPlaceholderDb.Setup(x => x.AddFile("test.txt", "3333344444555556666677777888889999900000")).Callback(() => ++ placeholderCount);
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                           this.Repo.Context,
                           this.Repo.GitObjects,
                           RepoMetadata.Instance,
                           new MockBlobSizes(),
                           gitIndexProjection: null,
                           backgroundFileSystemTaskRunner: backgroundTaskRunner,
                           fileSystemVirtualizer: null,
                           placeholderDatabase: mockPlaceholderDb.Object))
                {
                    fileSystemCallbacks.OnPlaceholderFileCreated("test.txt", "1111122222333334444455555666667777788888", "GVFS.UnitTests.exe");

                    EventLevel    eventLevel = EventLevel.Verbose;
                    EventMetadata metadata   = fileSystemCallbacks.GetMetadataForHeartBeat(ref eventLevel);
                    eventLevel.ShouldEqual(EventLevel.Informational);

                    // "ModifiedPathsCount" should be 1 because ".gitattributes" is always present
                    metadata.Count.ShouldEqual(6);
                    metadata.ShouldContain("ProcessName1", "GVFS.UnitTests.exe");
                    metadata.ShouldContain("ProcessCount1", 1);
                    metadata.ShouldContain("ModifiedPathsCount", 1);
                    metadata.ShouldContain("PlaceholderCount", 1);
                    metadata.ShouldContain(nameof(RepoMetadata.Instance.EnlistmentId), RepoMetadata.Instance.EnlistmentId);
                    metadata.ContainsKey("PhysicalDiskInfo").ShouldBeTrue();

                    // Create more placeholders
                    fileSystemCallbacks.OnPlaceholderFileCreated("test.txt", "2222233333444445555566666777778888899999", "GVFS.UnitTests.exe2");
                    fileSystemCallbacks.OnPlaceholderFileCreated("test.txt", "3333344444555556666677777888889999900000", "GVFS.UnitTests.exe2");

                    eventLevel = EventLevel.Verbose;
                    metadata   = fileSystemCallbacks.GetMetadataForHeartBeat(ref eventLevel);
                    eventLevel.ShouldEqual(EventLevel.Informational);

                    metadata.Count.ShouldEqual(6);

                    // Only processes that have created placeholders since the last heartbeat should be named
                    metadata.ShouldContain("ProcessName1", "GVFS.UnitTests.exe2");
                    metadata.ShouldContain("ProcessCount1", 2);
                    metadata.ShouldContain("ModifiedPathsCount", 1);
                    metadata.ShouldContain("PlaceholderCount", 3);
                    metadata.ShouldContain(nameof(RepoMetadata.Instance.EnlistmentId), RepoMetadata.Instance.EnlistmentId);
                    metadata.ContainsKey("PhysicalDiskInfo").ShouldBeTrue();
                }

            mockPlaceholderDb.VerifyAll();
        }
Beispiel #9
0
 private void CallbackSchedulesBackgroundTask(
     MockBackgroundFileSystemTaskRunner backgroundTaskRunner,
     Action <string> callback,
     string path,
     FileSystemTask.OperationType operationType)
 {
     callback(path);
     backgroundTaskRunner.Count.ShouldEqual(1);
     backgroundTaskRunner.BackgroundTasks[0].Operation.ShouldEqual(operationType);
     backgroundTaskRunner.BackgroundTasks[0].VirtualPath.ShouldEqual(path);
     backgroundTaskRunner.BackgroundTasks.Clear();
 }
        public void OnGetFileStreamReturnsSuccessWhenFileStreamAvailable()
        {
            const string TestFileName = "test.txt";
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1);
            Mock <ISparseCollection> mockSparseDb = new Mock <ISparseCollection>(MockBehavior.Strict);

            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { TestFileName }))
                        using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization))
                            using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                       this.Repo.Context,
                                       this.Repo.GitObjects,
                                       RepoMetadata.Instance,
                                       new MockBlobSizes(),
                                       gitIndexProjection,
                                       backgroundTaskRunner,
                                       virtualizer,
                                       mockPlaceholderDb.Object,
                                       mockSparseDb.Object))
                            {
                                string error;
                                fileSystemCallbacks.TryStart(out error).ShouldEqual(true);

                                byte[] contentId          = FileSystemVirtualizer.ConvertShaToContentId("0123456789012345678901234567890123456789");
                                byte[] placeholderVersion = MacFileSystemVirtualizer.PlaceholderVersionId;

                                uint fileLength = 100;
                                MockGVFSGitObjects mockGVFSGitObjects = this.Repo.GitObjects as MockGVFSGitObjects;
                                mockGVFSGitObjects.FileLength            = fileLength;
                                mockVirtualization.WriteFileReturnResult = Result.Success;

                                mockVirtualization.OnGetFileStream(
                                    commandId: 1,
                                    relativePath: TestFileName,
                                    providerId: placeholderVersion,
                                    contentId: contentId,
                                    triggeringProcessId: 2,
                                    triggeringProcessName: "UnitTest",
                                    fileHandle: IntPtr.Zero).ShouldEqual(Result.Success);

                                mockVirtualization.BytesWritten.ShouldEqual(fileLength);

                                fileSystemCallbacks.Stop();
                            }

            mockPlaceholderDb.VerifyAll();
            mockSparseDb.VerifyAll();
        }
        public void WritePlaceholderForSymLink()
        {
            const string WriteSymLinkFileName = "testWriteSymLink.txt";
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1);
            Mock <ISparseCollection> mockSparseDb = new Mock <ISparseCollection>(MockBehavior.Strict);

            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { WriteSymLinkFileName }))
                        using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization))
                            using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                       this.Repo.Context,
                                       this.Repo.GitObjects,
                                       RepoMetadata.Instance,
                                       new MockBlobSizes(),
                                       gitIndexProjection,
                                       backgroundTaskRunner,
                                       virtualizer,
                                       mockPlaceholderDb.Object,
                                       mockSparseDb.Object))
                            {
                                gitIndexProjection.MockFileTypesAndModes.TryAdd(
                                    WriteSymLinkFileName,
                                    ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.SymLink, fileMode: 0));

                                string error;
                                fileSystemCallbacks.TryStart(out error).ShouldEqual(true);

                                virtualizer.WritePlaceholderFile(
                                    WriteSymLinkFileName,
                                    endOfFile: 0,
                                    sha: string.Empty).ShouldEqual(new FileSystemResult(FSResult.Ok, (int)Result.Success));

                                mockVirtualization.CreatedPlaceholders.ShouldBeEmpty();
                                mockVirtualization.CreatedSymLinks.Count.ShouldEqual(1);
                                mockVirtualization.CreatedSymLinks.ShouldContain(entry => entry.Equals(WriteSymLinkFileName));

                                // Creating a symlink should schedule a background task
                                backgroundTaskRunner.Count.ShouldEqual(1);
                                backgroundTaskRunner.BackgroundTasks[0].Operation.ShouldEqual(GVFS.Virtualization.Background.FileSystemTask.OperationType.OnFileSymLinkCreated);
                                backgroundTaskRunner.BackgroundTasks[0].VirtualPath.ShouldEqual(WriteSymLinkFileName);

                                fileSystemCallbacks.Stop();
                            }

            mockPlaceholderDb.VerifyAll();
            mockSparseDb.VerifyAll();
        }
Beispiel #12
0
        public void GetMetadataForHeartBeatDoesSetsEventLevelWToInformationalWhenPlaceholdersHaveBeenCreated()
        {
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                           this.Repo.Context,
                           this.Repo.GitObjects,
                           RepoMetadata.Instance,
                           new MockBlobSizes(),
                           gitIndexProjection: null,
                           backgroundFileSystemTaskRunner: backgroundTaskRunner,
                           fileSystemVirtualizer: null))
                {
                    fileSystemCallbacks.OnPlaceholderFileCreated("test.txt", "1111122222333334444455555666667777788888", "GVFS.UnitTests.exe");

                    EventLevel    eventLevel = EventLevel.Verbose;
                    EventMetadata metadata   = fileSystemCallbacks.GetMetadataForHeartBeat(ref eventLevel);
                    eventLevel.ShouldEqual(EventLevel.Informational);

                    // "ModifiedPathsCount" should be 1 because ".gitattributes" is always present
                    metadata.Count.ShouldEqual(5);
                    metadata.ShouldContain("ProcessName1", "GVFS.UnitTests.exe");
                    metadata.ShouldContain("ProcessCount1", 1);
                    metadata.ShouldContain("ModifiedPathsCount", 1);
                    metadata.ShouldContain("PlaceholderCount", 1);
                    metadata.ShouldContain(nameof(RepoMetadata.Instance.EnlistmentId), RepoMetadata.Instance.EnlistmentId);

                    // Create more placeholders
                    fileSystemCallbacks.OnPlaceholderFileCreated("test.txt", "2222233333444445555566666777778888899999", "GVFS.UnitTests.exe2");
                    fileSystemCallbacks.OnPlaceholderFileCreated("test.txt", "3333344444555556666677777888889999900000", "GVFS.UnitTests.exe2");

                    eventLevel = EventLevel.Verbose;
                    metadata   = fileSystemCallbacks.GetMetadataForHeartBeat(ref eventLevel);
                    eventLevel.ShouldEqual(EventLevel.Informational);

                    metadata.Count.ShouldEqual(5);

                    // Only processes that have created placeholders since the last heartbeat should be named
                    metadata.ShouldContain("ProcessName1", "GVFS.UnitTests.exe2");
                    metadata.ShouldContain("ProcessCount1", 2);
                    metadata.ShouldContain("ModifiedPathsCount", 1);
                    metadata.ShouldContain("PlaceholderCount", 3);
                    metadata.ShouldContain(nameof(RepoMetadata.Instance.EnlistmentId), RepoMetadata.Instance.EnlistmentId);
                }
        }
Beispiel #13
0
        public void BackgroundOperationCountMatchesBackgroundFileSystemTaskRunner()
        {
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                           this.Repo.Context,
                           this.Repo.GitObjects,
                           RepoMetadata.Instance,
                           new MockBlobSizes(),
                           gitIndexProjection: null,
                           backgroundFileSystemTaskRunner: backgroundTaskRunner,
                           fileSystemVirtualizer: null))
                {
                    fileSystemCallbacks.BackgroundOperationCount.ShouldEqual(backgroundTaskRunner.Count);

                    fileSystemCallbacks.OnFileConvertedToFull("Path1.txt");
                    fileSystemCallbacks.OnFileConvertedToFull("Path2.txt");
                    backgroundTaskRunner.Count.ShouldEqual(2);
                    fileSystemCallbacks.BackgroundOperationCount.ShouldEqual(backgroundTaskRunner.Count);
                }
        }
Beispiel #14
0
        private void ValidateActionInvalidatesStatusCache(
            MockBackgroundFileSystemTaskRunner backgroundTaskRunner,
            MockGitStatusCache gitStatusCache,
            Action <string> action,
            string path,
            FileSystemTask.OperationType operationType)
        {
            action(path);

            backgroundTaskRunner.Count.ShouldEqual(1);
            backgroundTaskRunner.BackgroundTasks[0].Operation.ShouldEqual(operationType);
            backgroundTaskRunner.BackgroundTasks[0].VirtualPath.ShouldEqual(path);

            backgroundTaskRunner.ProcessTasks();

            gitStatusCache.InvalidateCallCount.ShouldEqual(1);

            gitStatusCache.ResetCalls();
            backgroundTaskRunner.BackgroundTasks.Clear();
        }
Beispiel #15
0
        public void OnGetFileStreamReturnsErrorWhenWriteFileContentsFails()
        {
            const string TestFileName = "test.txt";

            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { TestFileName }))
                        using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization))
                            using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                       this.Repo.Context,
                                       this.Repo.GitObjects,
                                       RepoMetadata.Instance,
                                       new MockBlobSizes(),
                                       gitIndexProjection,
                                       backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                       fileSystemVirtualizer: virtualizer))
                            {
                                string error;
                                fileSystemCallbacks.TryStart(out error).ShouldEqual(true);

                                byte[] contentId          = FileSystemVirtualizer.ConvertShaToContentId("0123456789012345678901234567890123456789");
                                byte[] placeholderVersion = MacFileSystemVirtualizer.PlaceholderVersionId;

                                uint fileLength = 100;
                                MockGVFSGitObjects mockGVFSGitObjects = this.Repo.GitObjects as MockGVFSGitObjects;
                                mockGVFSGitObjects.FileLength            = fileLength;
                                mockVirtualization.WriteFileReturnResult = Result.EIOError;

                                mockVirtualization.OnGetFileStream(
                                    commandId: 1,
                                    relativePath: TestFileName,
                                    providerId: placeholderVersion,
                                    contentId: contentId,
                                    triggeringProcessId: 2,
                                    triggeringProcessName: "UnitTest",
                                    fileHandle: IntPtr.Zero).ShouldEqual(Result.EIOError);

                                fileSystemCallbacks.Stop();
                            }
        }
Beispiel #16
0
        public void GetMetadataForHeartBeatDoesNotChangeEventLevelWhenNoPlaceholderHaveBeenCreated()
        {
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                           this.Repo.Context,
                           this.Repo.GitObjects,
                           RepoMetadata.Instance,
                           new MockBlobSizes(),
                           gitIndexProjection: null,
                           backgroundFileSystemTaskRunner: backgroundTaskRunner,
                           fileSystemVirtualizer: null))
                {
                    EventLevel    eventLevel = EventLevel.Verbose;
                    EventMetadata metadata   = fileSystemCallbacks.GetMetadataForHeartBeat(ref eventLevel);
                    eventLevel.ShouldEqual(EventLevel.Verbose);

                    // "ModifiedPathsCount" should be 1 because ".gitattributes" is always present
                    metadata.ShouldContain("ModifiedPathsCount", 1);
                    metadata.ShouldContain("PlaceholderCount", 0);
                    metadata.ShouldContain(nameof(RepoMetadata.Instance.EnlistmentId), RepoMetadata.Instance.EnlistmentId);
                }
        }
Beispiel #17
0
        public void OnEnumerateDirectoryReturnsSuccessWhenResultsInMemory()
        {
            const string TestFileName   = "test.txt";
            const string TestFolderName = "testFolder";
            string       testFilePath   = Path.Combine(TestFolderName, TestFileName);

            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())

                    // Don't include TestFolderName as MockGitIndexProjection returns the same list of files regardless of what folder name
                    // it is passed
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { TestFileName }))
                        using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization))
                            using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                       this.Repo.Context,
                                       this.Repo.GitObjects,
                                       RepoMetadata.Instance,
                                       new MockBlobSizes(),
                                       gitIndexProjection,
                                       backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                       fileSystemVirtualizer: virtualizer))
                            {
                                gitIndexProjection.MockFileTypesAndModes.TryAdd(
                                    testFilePath,
                                    ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.Regular, GitIndexProjection.FileMode644));

                                string error;
                                fileSystemCallbacks.TryStart(out error).ShouldEqual(true);

                                Guid enumerationGuid = Guid.NewGuid();
                                gitIndexProjection.EnumerationInMemory = true;
                                mockVirtualization.OnEnumerateDirectory(1, TestFolderName, triggeringProcessId: 1, triggeringProcessName: "UnitTests").ShouldEqual(Result.Success);
                                mockVirtualization.CreatedPlaceholders.ShouldContain(
                                    kvp => kvp.Key.Equals(testFilePath, StringComparison.OrdinalIgnoreCase) && kvp.Value == GitIndexProjection.FileMode644);
                                gitIndexProjection.ExpandedFolders.ShouldMatchInOrder(TestFolderName);
                                fileSystemCallbacks.Stop();
                            }
        }
Beispiel #18
0
        public void StartingAndStoppingSetsMountedState()
        {
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockFileSystemVirtualizer fileSystemVirtualizer = new MockFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects))
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" }))
                        using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                   this.Repo.Context,
                                   this.Repo.GitObjects,
                                   RepoMetadata.Instance,
                                   new MockBlobSizes(),
                                   gitIndexProjection: gitIndexProjection,
                                   backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                   fileSystemVirtualizer: fileSystemVirtualizer))
                        {
                            fileSystemCallbacks.IsMounted.ShouldBeFalse();

                            string error;
                            fileSystemCallbacks.TryStart(out error).ShouldBeTrue();
                            fileSystemCallbacks.IsMounted.ShouldBeTrue();

                            fileSystemCallbacks.Stop();
                            fileSystemCallbacks.IsMounted.ShouldBeFalse();
                        }
        }
Beispiel #19
0
        public void GetMetadataForHeartBeatDoesSetsEventLevelToInformationalWhenPlaceholdersHaveBeenCreated()
        {
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);
            int filePlaceholderCount   = 0;
            int folderPlaceholderCount = 0;

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(() => filePlaceholderCount + folderPlaceholderCount);
            mockPlaceholderDb.Setup(x => x.AddFile("test.txt", "1111122222333334444455555666667777788888")).Callback(() => ++ filePlaceholderCount);
            mockPlaceholderDb.Setup(x => x.AddFile("test.txt", "2222233333444445555566666777778888899999")).Callback(() => ++ filePlaceholderCount);
            mockPlaceholderDb.Setup(x => x.AddFile("test.txt", "3333344444555556666677777888889999900000")).Callback(() => ++ filePlaceholderCount);
            mockPlaceholderDb.Setup(x => x.AddPartialFolder("foo")).Callback(() => ++ folderPlaceholderCount);
            mockPlaceholderDb.Setup(x => x.GetFilePlaceholdersCount()).Returns(() => filePlaceholderCount);
            mockPlaceholderDb.Setup(x => x.GetFolderPlaceholdersCount()).Returns(() => folderPlaceholderCount);
            Mock <ISparseCollection> mockSparseDb = new Mock <ISparseCollection>(MockBehavior.Strict);

            mockSparseDb.Setup(x => x.GetAll()).Returns(new HashSet <string>());
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                           this.Repo.Context,
                           this.Repo.GitObjects,
                           RepoMetadata.Instance,
                           new MockBlobSizes(),
                           gitIndexProjection: null,
                           backgroundFileSystemTaskRunner: backgroundTaskRunner,
                           fileSystemVirtualizer: null,
                           placeholderDatabase: mockPlaceholderDb.Object,
                           sparseCollection: mockSparseDb.Object))
                {
                    fileSystemCallbacks.OnPlaceholderFileCreated("test.txt", "1111122222333334444455555666667777788888", "GVFS.UnitTests.exe");

                    EventMetadata metadata   = fileSystemCallbacks.GetAndResetHeartBeatMetadata(out bool writeToLogFile);
                    EventLevel    eventLevel = writeToLogFile ? EventLevel.Informational : EventLevel.Verbose;
                    eventLevel.ShouldEqual(EventLevel.Informational);

                    // "ModifiedPathsCount" should be 1 because ".gitattributes" is always present
                    metadata.Count.ShouldEqual(8);
                    metadata.ContainsKey("FilePlaceholderCreation").ShouldBeTrue();
                    metadata.TryGetValue("FilePlaceholderCreation", out object fileNestedMetadata);
                    JsonConvert.SerializeObject(fileNestedMetadata).ShouldContain("\"ProcessName1\":\"GVFS.UnitTests.exe\"");
                    JsonConvert.SerializeObject(fileNestedMetadata).ShouldContain("\"ProcessCount1\":1");
                    metadata.ShouldContain("ModifiedPathsCount", 1);
                    metadata.ShouldContain("FilePlaceholderCount", 1);
                    metadata.ShouldContain("FolderPlaceholderCount", 0);
                    metadata.ShouldContain(nameof(RepoMetadata.Instance.EnlistmentId), RepoMetadata.Instance.EnlistmentId);
                    metadata.ContainsKey("PhysicalDiskInfo").ShouldBeTrue();

                    // Create more placeholders
                    fileSystemCallbacks.OnPlaceholderFileCreated("test.txt", "2222233333444445555566666777778888899999", "GVFS.UnitTests.exe2");
                    fileSystemCallbacks.OnPlaceholderFileCreated("test.txt", "3333344444555556666677777888889999900000", "GVFS.UnitTests.exe2");
                    fileSystemCallbacks.OnPlaceholderFolderCreated("foo", "GVFS.UnitTests.exe2");

                    // Hydrate a file
                    fileSystemCallbacks.OnPlaceholderFileHydrated("GVFS.UnitTests.exe2");

                    metadata   = fileSystemCallbacks.GetAndResetHeartBeatMetadata(out bool writeToLogFile2);
                    eventLevel = writeToLogFile2 ? EventLevel.Informational : EventLevel.Verbose;
                    eventLevel.ShouldEqual(EventLevel.Informational);

                    metadata.Count.ShouldEqual(8);

                    // Only processes that have created placeholders since the last heartbeat should be named
                    metadata.ContainsKey("FilePlaceholderCreation").ShouldBeTrue();
                    metadata.TryGetValue("FilePlaceholderCreation", out object fileNestedMetadata2);
                    JsonConvert.SerializeObject(fileNestedMetadata2).ShouldContain("\"ProcessName1\":\"GVFS.UnitTests.exe2\"");
                    JsonConvert.SerializeObject(fileNestedMetadata2).ShouldContain("\"ProcessCount1\":2");
                    metadata.ContainsKey("FolderPlaceholderCreation").ShouldBeTrue();
                    metadata.TryGetValue("FolderPlaceholderCreation", out object folderNestedMetadata2);
                    JsonConvert.SerializeObject(folderNestedMetadata2).ShouldContain("\"ProcessName1\":\"GVFS.UnitTests.exe2\"");
                    JsonConvert.SerializeObject(folderNestedMetadata2).ShouldContain("\"ProcessCount1\":1");
                    metadata.ContainsKey("FilePlaceholdersHydrated").ShouldBeTrue();
                    metadata.TryGetValue("FilePlaceholdersHydrated", out object hydrationNestedMetadata2);
                    JsonConvert.SerializeObject(hydrationNestedMetadata2).ShouldContain("\"ProcessName1\":\"GVFS.UnitTests.exe2\"");
                    JsonConvert.SerializeObject(hydrationNestedMetadata2).ShouldContain("\"ProcessCount1\":1");
                    metadata.ShouldContain("ModifiedPathsCount", 1);
                    metadata.ShouldContain("FilePlaceholderCount", 3);
                    metadata.ShouldContain("FolderPlaceholderCount", 1);
                    metadata.ShouldContain(nameof(RepoMetadata.Instance.EnlistmentId), RepoMetadata.Instance.EnlistmentId);
                    metadata.ContainsKey("PhysicalDiskInfo").ShouldBeTrue();
                }

            mockPlaceholderDb.VerifyAll();
            mockSparseDb.VerifyAll();
        }
Beispiel #20
0
        public void FileAndFolderCallbacksScheduleBackgroundTasks()
        {
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1);
            Mock <ISparseCollection> mockSparseDb = new Mock <ISparseCollection>(MockBehavior.Strict);

            mockSparseDb.Setup(x => x.GetAll()).Returns(new HashSet <string>());
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                           this.Repo.Context,
                           this.Repo.GitObjects,
                           RepoMetadata.Instance,
                           new MockBlobSizes(),
                           gitIndexProjection: null,
                           backgroundFileSystemTaskRunner: backgroundTaskRunner,
                           fileSystemVirtualizer: null,
                           placeholderDatabase: mockPlaceholderDb.Object,
                           sparseCollection: mockSparseDb.Object))
                {
                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileConvertedToFull(path),
                        "OnFileConvertedToFull.txt",
                        FileSystemTask.OperationType.OnFileConvertedToFull);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileCreated(path),
                        "OnFileCreated.txt",
                        FileSystemTask.OperationType.OnFileCreated);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileDeleted(path),
                        "OnFileDeleted.txt",
                        FileSystemTask.OperationType.OnFileDeleted);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileOverwritten(path),
                        "OnFileOverwritten.txt",
                        FileSystemTask.OperationType.OnFileOverwritten);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (oldPath, newPath) => fileSystemCallbacks.OnFileRenamed(oldPath, newPath),
                        "OnFileRenamed.txt",
                        "OnFileRenamed2.txt",
                        FileSystemTask.OperationType.OnFileRenamed);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (existingPath, newLink) => fileSystemCallbacks.OnFileHardLinkCreated(newLink, existingPath),
                        string.Empty,
                        "OnFileHardLinkCreated.txt",
                        FileSystemTask.OperationType.OnFileHardLinkCreated);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileSuperseded(path),
                        "OnFileSuperseded.txt",
                        FileSystemTask.OperationType.OnFileSuperseded);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFolderCreated(path, out _),
                        "OnFolderCreated.txt",
                        FileSystemTask.OperationType.OnFolderCreated);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFolderDeleted(path),
                        "OnFolderDeleted.txt",
                        FileSystemTask.OperationType.OnFolderDeleted);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (oldPath, newPath) => fileSystemCallbacks.OnFolderRenamed(oldPath, newPath),
                        "OnFolderRenamed.txt",
                        "OnFolderRenamed2.txt",
                        FileSystemTask.OperationType.OnFolderRenamed);
                }

            mockPlaceholderDb.VerifyAll();
            mockSparseDb.VerifyAll();
        }
        public void UpdatePlaceholderIfNeeded()
        {
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" }))
                        using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization))
                            using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                       this.Repo.Context,
                                       this.Repo.GitObjects,
                                       RepoMetadata.Instance,
                                       new MockBlobSizes(),
                                       gitIndexProjection,
                                       backgroundTaskRunner,
                                       virtualizer))
                            {
                                gitIndexProjection.MockFileModes.TryAdd("test" + Path.DirectorySeparatorChar + "test.txt", FileMode644);
                                string error;
                                fileSystemCallbacks.TryStart(out error).ShouldEqual(true);

                                UpdateFailureReason failureReason = UpdateFailureReason.NoFailure;

                                mockVirtualization.UpdatePlaceholderIfNeededResult       = Result.Success;
                                mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.NoFailure;
                                virtualizer
                                .UpdatePlaceholderIfNeeded(
                                    "test.txt",
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    0,
                                    15,
                                    string.Empty,
                                    UpdatePlaceholderType.AllowReadOnly,
                                    out failureReason)
                                .ShouldEqual(new FileSystemResult(FSResult.Ok, (int)mockVirtualization.UpdatePlaceholderIfNeededResult));
                                failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause);

                                mockVirtualization.UpdatePlaceholderIfNeededResult       = Result.EFileNotFound;
                                mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.NoFailure;
                                virtualizer
                                .UpdatePlaceholderIfNeeded(
                                    "test.txt",
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    0,
                                    15,
                                    string.Empty,
                                    UpdatePlaceholderType.AllowReadOnly,
                                    out failureReason)
                                .ShouldEqual(new FileSystemResult(FSResult.FileOrPathNotFound, (int)mockVirtualization.UpdatePlaceholderIfNeededResult));
                                failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause);

                                // TODO: What will the result be when the UpdateFailureCause is DirtyData
                                mockVirtualization.UpdatePlaceholderIfNeededResult       = Result.EInvalidOperation;
                                mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.DirtyData;

                                // TODO: The result should probably be VirtualizationInvalidOperation but for now it's IOError
                                virtualizer
                                .UpdatePlaceholderIfNeeded(
                                    "test.txt",
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    0,
                                    15,
                                    string.Empty,
                                    UpdatePlaceholderType.AllowReadOnly,
                                    out failureReason)
                                .ShouldEqual(new FileSystemResult(FSResult.IOError, (int)mockVirtualization.UpdatePlaceholderIfNeededResult));
                                failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause);
                                fileSystemCallbacks.Stop();
                            }
        }
Beispiel #22
0
        public void FileAndFolderCallbacksScheduleBackgroundTasks()
        {
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                           this.Repo.Context,
                           this.Repo.GitObjects,
                           RepoMetadata.Instance,
                           new MockBlobSizes(),
                           gitIndexProjection: null,
                           backgroundFileSystemTaskRunner: backgroundTaskRunner,
                           fileSystemVirtualizer: null))
                {
                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileConvertedToFull(path),
                        "OnFileConvertedToFull.txt",
                        FileSystemTask.OperationType.OnFileConvertedToFull);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileCreated(path),
                        "OnFileCreated.txt",
                        FileSystemTask.OperationType.OnFileCreated);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileDeleted(path),
                        "OnFileDeleted.txt",
                        FileSystemTask.OperationType.OnFileDeleted);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileOverwritten(path),
                        "OnFileOverwritten.txt",
                        FileSystemTask.OperationType.OnFileOverwritten);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (oldPath, newPath) => fileSystemCallbacks.OnFileRenamed(oldPath, newPath),
                        "OnFileRenamed.txt",
                        "OnFileRenamed2.txt",
                        FileSystemTask.OperationType.OnFileRenamed);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileSuperseded(path),
                        "OnFileSuperseded.txt",
                        FileSystemTask.OperationType.OnFileSuperseded);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFolderCreated(path),
                        "OnFolderCreated.txt",
                        FileSystemTask.OperationType.OnFolderCreated);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFolderDeleted(path),
                        "OnFolderDeleted.txt",
                        FileSystemTask.OperationType.OnFolderDeleted);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (oldPath, newPath) => fileSystemCallbacks.OnFolderRenamed(oldPath, newPath),
                        "OnFolderRenamed.txt",
                        "OnFolderRenamed2.txt",
                        FileSystemTask.OperationType.OnFolderRenamed);
                }
        }
Beispiel #23
0
        public void IsReadyForExternalAcquireLockRequests()
        {
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockFileSystemVirtualizer fileSystemVirtualizer = new MockFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects))
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" }))
                        using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                   this.Repo.Context,
                                   this.Repo.GitObjects,
                                   RepoMetadata.Instance,
                                   new MockBlobSizes(),
                                   gitIndexProjection: gitIndexProjection,
                                   backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                   fileSystemVirtualizer: fileSystemVirtualizer))
                        {
                            string denyMessage;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for mount to complete");

                            string error;
                            fileSystemCallbacks.TryStart(out error).ShouldBeTrue();
                            gitIndexProjection.ProjectionParseComplete = false;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for GVFS to parse index and update placeholder files");

                            // Put something on the background queue
                            fileSystemCallbacks.OnFileCreated("NewFilePath.txt");
                            backgroundTaskRunner.Count.ShouldEqual(1);
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for background operations to complete and for GVFS to release the lock");

                            backgroundTaskRunner.BackgroundTasks.Clear();
                            gitIndexProjection.ProjectionParseComplete = true;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command"),
                                out denyMessage).ShouldBeTrue();
                            denyMessage.ShouldEqual("Waiting for GVFS to release the lock");

                            fileSystemCallbacks.Stop();
                        }
        }
Beispiel #24
0
        public void UpdatePlaceholderIfNeeded()
        {
            const string UpdatePlaceholderFileName = "testUpdatePlaceholder.txt";

            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { UpdatePlaceholderFileName }))
                        using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization))
                            using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                       this.Repo.Context,
                                       this.Repo.GitObjects,
                                       RepoMetadata.Instance,
                                       new MockBlobSizes(),
                                       gitIndexProjection,
                                       backgroundTaskRunner,
                                       virtualizer))
                            {
                                gitIndexProjection.MockFileTypesAndModes.TryAdd(
                                    UpdatePlaceholderFileName,
                                    ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.Regular, GitIndexProjection.FileMode644));

                                string error;
                                fileSystemCallbacks.TryStart(out error).ShouldEqual(true);

                                UpdateFailureReason failureReason = UpdateFailureReason.NoFailure;

                                mockVirtualization.UpdatePlaceholderIfNeededResult       = Result.Success;
                                mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.NoFailure;
                                virtualizer
                                .UpdatePlaceholderIfNeeded(
                                    UpdatePlaceholderFileName,
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    0,
                                    15,
                                    string.Empty,
                                    UpdatePlaceholderType.AllowReadOnly,
                                    out failureReason)
                                .ShouldEqual(new FileSystemResult(FSResult.Ok, (int)mockVirtualization.UpdatePlaceholderIfNeededResult));
                                failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause);
                                mockVirtualization.UpdatedPlaceholders.ShouldContain(path => path.Key.Equals(UpdatePlaceholderFileName) && path.Value == GitIndexProjection.FileMode644);
                                mockVirtualization.UpdatedPlaceholders.Clear();

                                mockVirtualization.UpdatePlaceholderIfNeededResult       = Result.EFileNotFound;
                                mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.NoFailure;
                                virtualizer
                                .UpdatePlaceholderIfNeeded(
                                    UpdatePlaceholderFileName,
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    0,
                                    15,
                                    string.Empty,
                                    UpdatePlaceholderType.AllowReadOnly,
                                    out failureReason)
                                .ShouldEqual(new FileSystemResult(FSResult.FileOrPathNotFound, (int)mockVirtualization.UpdatePlaceholderIfNeededResult));
                                failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause);

                                // TODO: What will the result be when the UpdateFailureCause is DirtyData
                                mockVirtualization.UpdatePlaceholderIfNeededResult       = Result.EInvalidOperation;
                                mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.DirtyData;

                                // TODO: The result should probably be VirtualizationInvalidOperation but for now it's IOError
                                virtualizer
                                .UpdatePlaceholderIfNeeded(
                                    UpdatePlaceholderFileName,
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    DateTime.Now,
                                    0,
                                    15,
                                    string.Empty,
                                    UpdatePlaceholderType.AllowReadOnly,
                                    out failureReason)
                                .ShouldEqual(new FileSystemResult(FSResult.IOError, (int)mockVirtualization.UpdatePlaceholderIfNeededResult));
                                failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause);
                                fileSystemCallbacks.Stop();
                            }
        }
Beispiel #25
0
        public void IsReadyForExternalAcquireLockRequests()
        {
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1);
            Mock <ISparseCollection> mockSparseDb = new Mock <ISparseCollection>(MockBehavior.Strict);

            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockFileSystemVirtualizer fileSystemVirtualizer = new MockFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects))
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" }))
                        using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                   this.Repo.Context,
                                   this.Repo.GitObjects,
                                   RepoMetadata.Instance,
                                   new MockBlobSizes(),
                                   gitIndexProjection: gitIndexProjection,
                                   backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                   fileSystemVirtualizer: fileSystemVirtualizer,
                                   placeholderDatabase: mockPlaceholderDb.Object,
                                   sparseCollection: mockSparseDb.Object))
                        {
                            string denyMessage;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command",
                                    gitCommandSessionId: "123"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for GVFS to parse index and update placeholder files");

                            string error;
                            fileSystemCallbacks.TryStart(out error).ShouldBeTrue();
                            gitIndexProjection.ProjectionParseComplete = false;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command",
                                    gitCommandSessionId: "123"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for GVFS to parse index and update placeholder files");

                            // Put something on the background queue
                            fileSystemCallbacks.OnFileCreated("NewFilePath.txt");
                            backgroundTaskRunner.Count.ShouldEqual(1);
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command",
                                    gitCommandSessionId: "123"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for GVFS to release the lock");

                            backgroundTaskRunner.BackgroundTasks.Clear();
                            gitIndexProjection.ProjectionParseComplete = true;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command",
                                    gitCommandSessionId: "123"),
                                out denyMessage).ShouldBeTrue();
                            denyMessage.ShouldEqual("Waiting for GVFS to release the lock");

                            fileSystemCallbacks.Stop();
                        }

            mockPlaceholderDb.VerifyAll();
            mockSparseDb.VerifyAll();
        }