/// <summary> /// Verifies the file was successfully uploaded. /// </summary> /// <param name="up">The upload parameters.</param> /// <param name="frontEnd">The front end.</param> /// <param name="fileContents">The file contents.</param> private void VerifyFileUploadedSuccessfully(UploadParameters up, InMemoryFrontEnd frontEnd, byte[] fileContents) { Assert.True(frontEnd.StreamExists(up.TargetStreamPath), "Uploaded stream does not exist"); Assert.Equal(1, frontEnd.StreamCount); Assert.Equal(fileContents.Length, frontEnd.GetStreamLength(up.TargetStreamPath)); var uploadedData = frontEnd.GetStreamContents(up.TargetStreamPath); AssertExtensions.AreEqual(fileContents, uploadedData, "Uploaded stream is not binary identical to input file"); }
private void VerifyTargetStreamIsComplete(UploadSegmentMetadata segmentMetadata, UploadMetadata metadata, InMemoryFrontEnd frontEnd) { Assert.Equal(SegmentUploadStatus.Complete, segmentMetadata.Status); Assert.True(frontEnd.StreamExists(segmentMetadata.Path), string.Format("Segment {0} was not uploaded", segmentMetadata.SegmentNumber)); Assert.Equal(segmentMetadata.Length, frontEnd.GetStreamLength(segmentMetadata.Path)); var actualContents = frontEnd.GetStreamContents(segmentMetadata.Path); var expectedContents = GetExpectedContents(segmentMetadata, metadata); AssertExtensions.AreEqual(expectedContents, actualContents, "Segment {0} has unexpected contents", segmentMetadata.SegmentNumber); }
public void DataLakeUploader_CancelUpload() { CancellationTokenSource myTokenSource = new CancellationTokenSource(); var cancelToken = myTokenSource.Token; var frontEnd = new InMemoryFrontEnd(); var mockedFrontend = new MockableFrontEnd(frontEnd); mockedFrontend.GetStreamLengthImplementation = (streamPath, isDownload) => { // sleep for 2 second to allow for the cancellation to actual happen Thread.Sleep(2000); return(frontEnd.GetStreamLength(streamPath, isDownload)); }; mockedFrontend.StreamExistsImplementation = (streamPath, isDownload) => { // sleep for 2 second to allow for the cancellation to actual happen Thread.Sleep(2000); return(frontEnd.StreamExists(streamPath, isDownload)); }; var up = CreateParameters(isResume: false); UploadProgress progress = null; var syncRoot = new object(); IProgress <UploadProgress> progressTracker = new Progress <UploadProgress>( (p) => { lock (syncRoot) { //it is possible that these come out of order because of race conditions (multiple threads reporting at the same time); only update if we are actually making progress if (progress == null || progress.UploadedByteCount < p.UploadedByteCount) { progress = p; } } }); var uploader = new DataLakeStoreUploader(up, mockedFrontend, cancelToken, progressTracker); Task uploadTask = Task.Run(() => { uploader.Execute(); Thread.Sleep(2000); }, cancelToken); myTokenSource.Cancel(); Assert.True(cancelToken.IsCancellationRequested); while (uploadTask.Status == TaskStatus.Running || uploadTask.Status == TaskStatus.WaitingToRun) { Thread.Sleep(250); } // Verify that the file did not get uploaded completely. Assert.False(frontEnd.StreamExists(up.TargetStreamPath), "Uploaded stream exists when it should not yet have been completely created"); }
/// <summary> /// Verifies the file was successfully uploaded. /// </summary> /// <param name="targetPathsAndData">The target paths and data for each path.</param> /// <param name="frontEnd">The front end to use.</param> private void VerifyFileUploadedSuccessfully(Dictionary <string, byte[]> targetPathsAndData, InMemoryFrontEnd frontEnd, bool isDownload) { var streamCount = targetPathsAndData.Keys.Count; Assert.Equal(streamCount, frontEnd.StreamCount); foreach (var path in targetPathsAndData.Keys) { Assert.True(frontEnd.StreamExists(path, isDownload), "Uploaded stream does not exist"); Assert.Equal(targetPathsAndData[path].Length, frontEnd.GetStreamLength(path, isDownload)); var uploadedData = frontEnd.GetStreamContents(path, isDownload); AssertExtensions.AreEqual(targetPathsAndData[path], uploadedData, "Uploaded stream is not binary identical to input file"); } }
/// <summary> /// Verifies the file was successfully uploaded. /// </summary> /// <param name="up">The upload parameters.</param> /// <param name="frontEnd">The front end.</param> /// <param name="fileContents">The file contents.</param> private void VerifyFileUploadedSuccessfully(UploadParameters up, InMemoryFrontEnd frontEnd, byte[] fileContents) { Assert.True(frontEnd.StreamExists(up.TargetStreamPath), "Uploaded stream does not exist"); Assert.Equal(1, frontEnd.StreamCount); Assert.Equal(fileContents.Length, frontEnd.GetStreamLength(up.TargetStreamPath)); var uploadedData = frontEnd.GetStreamContents(up.TargetStreamPath); AssertExtensions.AreEqual(fileContents, uploadedData, "Uploaded stream is not binary identical to input file"); }
private void VerifyTargetStreamIsComplete(UploadSegmentMetadata segmentMetadata, UploadMetadata metadata, InMemoryFrontEnd frontEnd) { Assert.Equal(SegmentUploadStatus.Complete, segmentMetadata.Status); Assert.True(frontEnd.StreamExists(segmentMetadata.Path), string.Format("Segment {0} was not uploaded", segmentMetadata.SegmentNumber)); Assert.Equal(segmentMetadata.Length, frontEnd.GetStreamLength(segmentMetadata.Path)); var actualContents = frontEnd.GetStreamContents(segmentMetadata.Path); var expectedContents = GetExpectedContents(segmentMetadata, metadata); AssertExtensions.AreEqual(expectedContents, actualContents, "Segment {0} has unexpected contents", segmentMetadata.SegmentNumber); }