예제 #1
0
        public void DownloadDirectoryProgressTest()
        {
            // disable clock skew testing, this is a multithreaded test
            using (RetryUtilities.DisableClockSkewCorrection())
            {
                var progressValidator = new DirectoryProgressValidator <DownloadDirectoryProgressArgs>();
                ConfigureProgressValidator(progressValidator);

                DownloadDirectory(progressValidator);
                progressValidator.AssertOnCompletion();
            }
        }
예제 #2
0
        private void PutStream(string destKey, int length, Stream stream)
        {
            PutObjectRequest request = new PutObjectRequest
            {
                BucketName  = bucketName,
                Key         = destKey,
                InputStream = stream,
            };

            request.Headers.ContentLength = length;
            using (RetryUtilities.DisableClockSkewCorrection())
            {
                Client.PutObject(request);
            }
        }
예제 #3
0
        public void TestSingleUploads()
        {
            // Test simple PutObject upload
            var key = "contentBodyPut" + random.Next();
            PutObjectRequest putObjectRequest = new PutObjectRequest()
            {
                BucketName  = bucketName,
                Key         = key,
                ContentBody = "This is the content body!",
            };

            SetMetadataAndHeaders(putObjectRequest);
            Client.PutObject(putObjectRequest);
            ValidateObjectMetadataAndHeaders(key);

            using (var tu = new TransferUtility(Client))
            {
                // Test small TransferUtility upload
                key = "transferUtilitySmall" + random.Next();
                UtilityMethods.GenerateFile(tempFile, smallFileSize);
                var smallRequest = new TransferUtilityUploadRequest
                {
                    BucketName = bucketName,
                    Key        = key,
                    FilePath   = tempFile
                };
                SetMetadataAndHeaders(smallRequest);
                tu.Upload(smallRequest);
                ValidateObjectMetadataAndHeaders(key);

                // Test large TransferUtility upload
                // disable clock skew testing, this is a multithreaded operation
                using (RetryUtilities.DisableClockSkewCorrection())
                {
                    key = "transferUtilityLarge" + random.Next();
                    UtilityMethods.GenerateFile(tempFile, largeFileSize);
                    var largeRequest = new TransferUtilityUploadRequest
                    {
                        BucketName = bucketName,
                        Key        = key,
                        FilePath   = tempFile
                    };
                    SetMetadataAndHeaders(largeRequest);
                    tu.Upload(largeRequest);
                    ValidateObjectMetadataAndHeaders(key);
                }
            }
        }
 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();
     }
 }
예제 #5
0
        public void PutObjectWithContentLength()
        {
            string sourceKey = "source";
            string destKey   = "dest";
            string contents  = "Sample contents";
            int    length    = contents.Length;

            Client.PutObject(new PutObjectRequest
            {
                BucketName  = bucketName,
                Key         = sourceKey,
                ContentBody = contents
            });

            // Disable clock skew testing when generating a presigned url
            using (RetryUtilities.DisableClockSkewCorrection())
            {
                string url = Client.GetPreSignedURL(new GetPreSignedUrlRequest
                {
                    BucketName = bucketName,
                    Key        = sourceKey,
                    Expires    = DateTime.Now + TimeSpan.FromHours(2)
                });

                HttpWebRequest httpRequest = HttpWebRequest.Create(url) as HttpWebRequest;
                using (HttpWebResponse httpResponse = httpRequest.GetResponse() as HttpWebResponse)
                    using (Stream stream = httpResponse.GetResponseStream())
                    {
                        PutStream(destKey, length, stream);
                    }
                string finalContents = GetContents(destKey);
                Assert.AreEqual(contents, finalContents);

                length     -= 2;
                httpRequest = HttpWebRequest.Create(url) as HttpWebRequest;
                using (HttpWebResponse httpResponse = httpRequest.GetResponse() as HttpWebResponse)
                    using (Stream stream = httpResponse.GetResponseStream())
                    {
                        PutStream(destKey, length, stream);
                    }
                finalContents = GetContents(destKey);
                Assert.AreEqual(contents.Substring(0, length), finalContents);
            }
        }
예제 #6
0
        public void TestSingleUploadWithSpacesInMetadata()
        {
            string metadataName  = "document";
            string metadataValue = " A  B  C  ";
            // Test simple PutObject upload
            var key = "contentBodyPut" + random.Next();
            PutObjectRequest putObjectRequest = new PutObjectRequest()
            {
                BucketName  = bucketName,
                Key         = key,
                ContentBody = "This is the content body!",
            };

            putObjectRequest.Metadata[metadataName] = metadataValue;

            Client.PutObject(putObjectRequest);
            using (var response = Client.GetObject(bucketName, key)) // Validate metadata
            {
                Assert.AreEqual(metadataValue.Trim(), response.Metadata[metadataName]);
            }

            using (var tu = new TransferUtility(Client))
            {
                // Test small TransferUtility upload
                key = "transferUtilitySmall" + random.Next();
                UtilityMethods.GenerateFile(tempFile, smallFileSize);
                var smallRequest = new TransferUtilityUploadRequest
                {
                    BucketName = bucketName,
                    Key        = key,
                    FilePath   = tempFile
                };

                smallRequest.Metadata[metadataName] = metadataValue;

                tu.Upload(smallRequest);
                using (var response = Client.GetObject(bucketName, key)) // Validate metadata
                {
                    Assert.AreEqual(metadataValue.Trim(), response.Metadata[metadataName]);
                }

                // Test large TransferUtility upload
                // disable clock skew testing, this is a multithreaded operation
                using (RetryUtilities.DisableClockSkewCorrection())
                {
                    key = "transferUtilityLarge" + random.Next();
                    UtilityMethods.GenerateFile(tempFile, largeFileSize);
                    var largeRequest = new TransferUtilityUploadRequest
                    {
                        BucketName = bucketName,
                        Key        = key,
                        FilePath   = tempFile
                    };
                    largeRequest.Metadata[metadataName] = metadataValue;

                    tu.Upload(largeRequest);
                    using (var response = Client.GetObject(bucketName, key)) // Validate metadata
                    {
                        Assert.AreEqual(metadataValue.Trim(), response.Metadata[metadataName]);
                    }
                }
            }
        }