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); } }
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); }
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); }
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); }
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)); } }
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); }
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); } }
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); } }
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(); } }
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); } }