Ejemplo n.º 1
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);
                }
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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();
                        }
        }
Ejemplo n.º 4
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();
        }