コード例 #1
0
        public void SuccessForBatchObjectDownloadJob()
        {
            using (JsonEtwTracer tracer = CreateTracer())
            {
                MockEnlistment     enlistment     = new MockEnlistment();
                MockHttpGitObjects httpGitObjects = new MockHttpGitObjects(tracer, enlistment);
                httpGitObjects.AddBlobContent(FakeSha, FakeShaContents);
                MockPhysicalGitObjects gitObjects = new MockPhysicalGitObjects(tracer, enlistment, httpGitObjects);

                BlockingCollection <string> input = new BlockingCollection <string>();
                input.Add(FakeSha);
                input.CompleteAdding();

                BatchObjectDownloadJob dut = new BatchObjectDownloadJob(1, 1, input, new BlockingCollection <string>(), tracer, enlistment, httpGitObjects, gitObjects);
                dut.Start();
                dut.WaitForCompletion();

                string sha;
                input.TryTake(out sha).ShouldEqual(false);
                dut.AvailablePacks.Count.ShouldEqual(0);

                dut.AvailableObjects.Count.ShouldEqual(1);
                string output = dut.AvailableObjects.Take();
                output.ShouldEqual(FakeSha);
            }
        }
        public void CatchesFileNotFoundAfterFileDeleted()
        {
            MockFileSystemWithCallbacks fileSystem = new MockFileSystemWithCallbacks();

            fileSystem.OnFileExists     = () => true;
            fileSystem.OnOpenFileStream = (path, fileMode, fileAccess) =>
            {
                if (fileAccess == FileAccess.Write)
                {
                    return(new MemoryStream());
                }

                throw new FileNotFoundException();
            };

            MockHttpGitObjects httpObjects = new MockHttpGitObjects();

            using (httpObjects.InputStream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(ValidTestObjectFileContents)))
            {
                httpObjects.MediaType = GVFSConstants.MediaTypes.LooseObjectMediaType;
                GVFSGitObjects dut = this.CreateTestableGVFSGitObjects(httpObjects, fileSystem);

                dut.TryCopyBlobContentStream(
                    ValidTestObjectFileContents,
                    new CancellationToken(),
                    GVFSGitObjects.RequestSource.FileStreamCallback,
                    (stream, length) => Assert.Fail("Should not be able to call copy stream callback"))
                .ShouldEqual(false);
            }
        }
コード例 #3
0
        private GVFSGitObjects CreateTestableGVFSGitObjects(MockHttpGitObjects httpObjects)
        {
            MockTracer     tracer     = new MockTracer();
            GVFSEnlistment enlistment = new GVFSEnlistment(this.tempFolder, "notused", "notused", "notused", null);

            GVFSContext    context = new GVFSContext(tracer, null, null, enlistment);
            GVFSGitObjects dut     = new GVFSGitObjects(context, httpObjects);

            return(dut);
        }
コード例 #4
0
ファイル: GVFSGitObjectsTests.cs プロジェクト: noonnee/GVFS
        private GVFSGitObjects CreateTestableGVFSGitObjects(MockHttpGitObjects httpObjects)
        {
            MockTracer     tracer     = new MockTracer();
            GVFSEnlistment enlistment = new GVFSEnlistment(this.tempFolder, "https://fakeRepoUrl", "fakeGitBinPath", gvfsHooksRoot: null);

            GVFSContext    context = new GVFSContext(tracer, null, null, enlistment);
            GVFSGitObjects dut     = new GVFSGitObjects(context, httpObjects);

            return(dut);
        }
コード例 #5
0
        private GVFSGitObjects CreateTestableGVFSGitObjects(MockHttpGitObjects httpObjects, MockFileSystemWithCallbacks fileSystem)
        {
            MockTracer     tracer     = new MockTracer();
            GVFSEnlistment enlistment = new GVFSEnlistment(TestEnlistmentRoot, "https://fakeRepoUrl", "fakeGitBinPath", gvfsHooksRoot: null);
            GitRepo        repo       = new GitRepo(tracer, enlistment, fileSystem, () => new MockLibGit2Repo(tracer));

            GVFSContext    context = new GVFSContext(tracer, fileSystem, repo, enlistment);
            GVFSGitObjects dut     = new GVFSGitObjects(context, httpObjects);

            return(dut);
        }
コード例 #6
0
        public void FailsZeroBytePackDownloads()
        {
            MockHttpGitObjects httpObjects = new MockHttpGitObjects();

            using (httpObjects.InputStream = new MemoryStream())
            {
                httpObjects.MediaType = GVFSConstants.MediaTypes.PackFileMediaType;
                GVFSGitObjects dut = this.CreateTestableGVFSGitObjects(httpObjects);

                Assert.Throws <RetryableException>(() => dut.TryDownloadAndSaveCommits(new[] { "object0", "object1" }, 0));
            }
        }
コード例 #7
0
        public void FailsNullByteLooseObjectsDownloads()
        {
            MockHttpGitObjects httpObjects = new MockHttpGitObjects();

            using (httpObjects.InputStream = new MemoryStream(new byte[256]))
            {
                httpObjects.MediaType = GVFSConstants.MediaTypes.LooseObjectMediaType;
                GVFSGitObjects dut = this.CreateTestableGVFSGitObjects(httpObjects);

                Assert.Throws <RetryableException>(() => dut.TryDownloadAndSaveObject("aa", "bbcc"));
            }
        }
        private GVFSGitObjects CreateTestableGVFSGitObjects(MockHttpGitObjects httpObjects, MockFileSystemWithCallbacks fileSystem)
        {
            MockTracer     tracer     = new MockTracer();
            GVFSEnlistment enlistment = new GVFSEnlistment(TestEnlistmentRoot, "https://fakeRepoUrl", "fakeGitBinPath", authentication: null);

            enlistment.InitializeCachePathsFromKey(TestLocalCacheRoot, TestObjectRoot);
            GitRepo repo = new GitRepo(tracer, enlistment, fileSystem, () => new MockLibGit2Repo(tracer));

            GVFSContext    context = new GVFSContext(tracer, fileSystem, repo, enlistment);
            GVFSGitObjects dut     = new GVFSGitObjects(context, httpObjects);

            return(dut);
        }
コード例 #9
0
        public void SucceedsForNormalLookingLooseObjectDownloads()
        {
            MockHttpGitObjects httpObjects = new MockHttpGitObjects();

            using (httpObjects.InputStream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(ValidTestObjectFileContents)))
            {
                httpObjects.MediaType = GVFSConstants.MediaTypes.LooseObjectMediaType;
                GVFSGitObjects dut = this.CreateTestableGVFSGitObjects(httpObjects);

                dut.TryDownloadAndSaveObject(ValidTestObjectFileContents.Substring(0, 2), ValidTestObjectFileContents.Substring(2))
                .ShouldEqual(true);
            }
        }
コード例 #10
0
ファイル: GVFSGitObjectsTests.cs プロジェクト: noonnee/GVFS
        private void AssertRetryableExceptionOnDownload(
            MemoryStream inputStream,
            string mediaType,
            Action <GVFSGitObjects> download)
        {
            MockHttpGitObjects httpObjects = new MockHttpGitObjects();

            httpObjects.InputStream = inputStream;
            httpObjects.MediaType   = mediaType;
            GVFSGitObjects gitObjects = this.CreateTestableGVFSGitObjects(httpObjects);

            Assert.Throws <RetryableException>(() => download(gitObjects));
            inputStream.Dispose();
        }
        public void SucceedsForNormalLookingLooseObjectDownloads()
        {
            MockFileSystemWithCallbacks fileSystem = new Mock.FileSystem.MockFileSystemWithCallbacks();

            fileSystem.OnFileExists     = () => true;
            fileSystem.OnOpenFileStream = (path, mode, access) => new MemoryStream();
            MockHttpGitObjects httpObjects = new MockHttpGitObjects();

            using (httpObjects.InputStream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(ValidTestObjectFileContents)))
            {
                httpObjects.MediaType = GVFSConstants.MediaTypes.LooseObjectMediaType;
                GVFSGitObjects dut = this.CreateTestableGVFSGitObjects(httpObjects, fileSystem);

                dut.TryDownloadAndSaveObject(ValidTestObjectFileContents, GVFSGitObjects.RequestSource.FileStreamCallback)
                .ShouldEqual(GitObjects.DownloadAndSaveObjectResult.Success);
            }
        }
コード例 #12
0
        protected void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.Context != null)
                {
                    this.Context.Dispose();
                    this.Context = null;
                }

                if (this.HttpObjects != null)
                {
                    this.HttpObjects.Dispose();
                    this.HttpObjects = null;
                }
            }
        }
        private void AssertRetryableExceptionOnDownload(
            MemoryStream inputStream,
            string mediaType,
            Action <GVFSGitObjects> download)
        {
            MockHttpGitObjects httpObjects = new MockHttpGitObjects();

            httpObjects.InputStream = inputStream;
            httpObjects.MediaType   = mediaType;
            MockFileSystemWithCallbacks fileSystem = new MockFileSystemWithCallbacks();

            using (ReusableMemoryStream downloadDestination = new ReusableMemoryStream(string.Empty))
            {
                fileSystem.OnFileExists     = () => false;
                fileSystem.OnOpenFileStream = (path, mode, access) => downloadDestination;

                GVFSGitObjects gitObjects = this.CreateTestableGVFSGitObjects(httpObjects, fileSystem);

                Assert.Throws <RetryableException>(() => download(gitObjects));
                inputStream.Dispose();
            }
        }
コード例 #14
0
        public void ErrorsForBatchObjectDownloadJob()
        {
            using (JsonEtwTracer tracer = CreateTracer())
            {
                MockEnlistment         enlistment     = new MockEnlistment();
                MockHttpGitObjects     httpGitObjects = new MockHttpGitObjects(tracer, enlistment);
                MockPhysicalGitObjects gitObjects     = new MockPhysicalGitObjects(tracer, enlistment, httpGitObjects);

                BlockingCollection <string> input = new BlockingCollection <string>();
                input.Add(FakeSha);
                input.CompleteAdding();

                BatchObjectDownloadJob dut = new BatchObjectDownloadJob(1, 1, input, new BlockingCollection <string>(), tracer, enlistment, httpGitObjects, gitObjects);
                dut.Start();
                dut.WaitForCompletion();

                string sha;
                input.TryTake(out sha).ShouldEqual(false);

                IndexPackRequest request;
                dut.AvailablePacks.TryTake(out request).ShouldEqual(false);
            }
        }