void Download(string fileName, long size, TransferProgressValidator <WriteObjectProgressArgs> progressValidator) { var key = fileName; var originalFilePath = Path.Combine(basePath, fileName); UtilityMethods.GenerateFile(originalFilePath, size); Client.PutObject(new PutObjectRequest { BucketName = bucketName, Key = key, FilePath = originalFilePath }); var downloadedFilePath = originalFilePath + ".dn"; var transferUtility = new TransferUtility(Client); var request = new TransferUtilityDownloadRequest { BucketName = bucketName, FilePath = downloadedFilePath, Key = key }; if (progressValidator != null) { request.WriteObjectProgressEvent += progressValidator.OnProgressEvent; } transferUtility.Download(request); UtilityMethods.CompareFiles(originalFilePath, downloadedFilePath); }
public void SimpleUploadProgressTest() { var context = SynchronizationContext.Current; var fileName = UtilityMethods.GenerateName(@"SimpleUploadTest\SmallFile"); var progressValidator = new TransferProgressValidator <UploadProgressArgs> { Validate = (p) => { Assert.AreEqual(p.FilePath, Path.Combine(basePath, fileName)); } }; Upload(fileName, 10 * MEG_SIZE, progressValidator); progressValidator.AssertOnCompletion(); }
public void MultipartUploadProgressTest() { var fileName = UtilityMethods.GenerateName(@"MultipartUploadTest\File"); var progressValidator = new TransferProgressValidator <UploadProgressArgs> { ValidateProgressInterval = false, Validate = (p) => { Assert.AreEqual(p.FilePath, Path.Combine(basePath, fileName)); } }; Upload(fileName, 20 * MEG_SIZE, progressValidator); progressValidator.AssertOnCompletion(); }
public async Task SimpleUploadProgressTest() { var context = SynchronizationContext.Current; var fileName = UtilityMethods.GenerateName(Path.Combine("SimpleUploadTest", "SmallFile")); var progressValidator = new TransferProgressValidator <UploadProgressArgs> { Validate = (p) => { Assert.Equal(p.FilePath, Path.Combine(basePath, fileName)); } }; await UploadAsync(fileName, 10 *MEG_SIZE, progressValidator).ConfigureAwait(false); progressValidator.AssertOnCompletion(); }
public async Task MultipartUploadProgressTest() { var fileName = UtilityMethods.GenerateName(Path.Combine("MultipartUploadTest", "File")); var progressValidator = new TransferProgressValidator <UploadProgressArgs> { ValidateProgressInterval = false, Validate = (p) => { Assert.Equal(p.FilePath, Path.Combine(basePath, fileName)); } }; await UploadAsync(fileName, 20 *MEG_SIZE, progressValidator).ConfigureAwait(false); progressValidator.AssertOnCompletion(); }
void Upload(string fileName, long size, TransferProgressValidator <UploadProgressArgs> progressValidator, AmazonS3Client client = null) { var key = fileName; Client.DeleteObject(new DeleteObjectRequest { BucketName = bucketName, Key = key }); var path = Path.Combine(basePath, fileName); UtilityMethods.GenerateFile(path, size); var config = new TransferUtilityConfig { //ConcurrentServiceRequests = 1, //MinSizeBeforePartUpload = MEG_SIZE }; var transferUtility = client != null ? new TransferUtility(client, config) : new TransferUtility(Client, config); var request = new TransferUtilityUploadRequest { BucketName = bucketName, FilePath = path, Key = key, ContentType = octetStreamContentType }; if (progressValidator != null) { request.UploadProgressEvent += progressValidator.OnProgressEvent; } transferUtility.Upload(request); var metadata = Client.GetObjectMetadata(new GetObjectMetadataRequest { BucketName = bucketName, Key = key }); Console.WriteLine("Expected Size: {0} , Actual Size {1}", size, metadata.ContentLength); Assert.AreEqual(octetStreamContentType, metadata.Headers.ContentType); Assert.AreEqual(size, metadata.ContentLength); ValidateFileContents(bucketName, key, path); }
public void DownloadProgressTest() { var fileName = UtilityMethods.GenerateName(@"DownloadTest\File"); var progressValidator = new TransferProgressValidator <WriteObjectProgressArgs> { Validate = (p) => { Assert.AreEqual(p.BucketName, bucketName); Assert.AreEqual(p.Key, fileName); Assert.IsNotNull(p.FilePath); Assert.IsTrue(p.FilePath.Contains(fileName)); } }; Download(fileName, 10 * MEG_SIZE, progressValidator); progressValidator.AssertOnCompletion(); }
private async Task UploadAsync(string fileName, long size, TransferProgressValidator <UploadProgressArgs> progressValidator, AmazonS3Client client = null) { var key = fileName; await Client.DeleteObjectAsync(new DeleteObjectRequest { BucketName = testBucketName, Key = key }).ConfigureAwait(false); var path = Path.Combine(basePath, fileName); UtilityMethods.GenerateFile(path, size); var config = new TransferUtilityConfig { //ConcurrentServiceRequests = 1, //MinSizeBeforePartUpload = MEG_SIZE }; var transferUtility = client != null ? new TransferUtility(client, config) : new TransferUtility(Client, config); var request = new TransferUtilityUploadRequest { BucketName = testBucketName, FilePath = path, Key = key, ContentType = OCTET_STREAM_CONTENT_TYPE }; if (progressValidator != null) { request.UploadProgressEvent += progressValidator.OnProgressEvent; } transferUtility.Upload(request); var metadata = await Client.GetObjectMetadataAsync(new GetObjectMetadataRequest { BucketName = testBucketName, Key = key }).ConfigureAwait(false); Console.WriteLine("Expected Size: {0} , Actual Size {1}", size, metadata.ContentLength); Assert.Equal(OCTET_STREAM_CONTENT_TYPE, metadata.Headers.ContentType); Assert.Equal(size, metadata.ContentLength); await ValidateFileContentsAsync(testBucketName, key, path).ConfigureAwait(false); }
public void MultipartUploadProgressTest() { // disable clock skew testing, this is a multithreaded test using (RetryUtilities.DisableClockSkewCorrection()) { var fileName = UtilityMethods.GenerateName(@"MultipartUploadTest\File"); var progressValidator = new TransferProgressValidator <UploadProgressArgs> { ValidateProgressInterval = false, Validate = (p) => { Assert.AreEqual(p.FilePath, Path.Combine(basePath, fileName)); } }; Upload(fileName, 20 * MEG_SIZE, progressValidator); progressValidator.AssertOnCompletion(); } }
public async Task DownloadProgressTest() { var fileName = UtilityMethods.GenerateName(Path.Combine("DownloadTest", "File")); var progressValidator = new TransferProgressValidator <WriteObjectProgressArgs> { Validate = (p) => { Assert.Equal(p.BucketName, testBucketName); Assert.Equal(p.Key, fileName); Assert.NotNull(p.FilePath); Assert.True(p.FilePath.Contains(fileName)); } }; await DownloadAsync(fileName, 10 *MEG_SIZE, progressValidator).ConfigureAwait(false); progressValidator.AssertOnCompletion(); }
public void DownloadProgressZeroLengthFileTest() { var fileName = UtilityMethods.GenerateName(@"DownloadTest\File"); var progressValidator = new TransferProgressValidator <WriteObjectProgressArgs> { Validate = (p) => { Assert.AreEqual(p.BucketName, bucketName); Assert.AreEqual(p.Key, fileName); Assert.IsNotNull(p.FilePath); Assert.IsTrue(p.FilePath.Contains(fileName)); Assert.AreEqual(p.TotalBytes, 0); Assert.AreEqual(p.TransferredBytes, 0); Assert.AreEqual(p.PercentDone, 100); } }; Download(fileName, 0, progressValidator); progressValidator.AssertOnCompletion(); }