public void RetryForHttpStatus502FromS3Accelerate()
        {
            var s3Client = new MockS3Client(new BasicAWSCredentials("access_key", "secret_key"),
                                            new Amazon.S3.AmazonS3Config
            {
                ServiceURL    = @"http://S3Accelerate502ErrorResponse",
                MaxErrorRetry = MAX_RETRIES
            });

            IExecutionContext executionContext = null;

            s3Client.Pipeline.AddHandlerAfter <RetryHandler>(new CallbackHandler
            {
                OnPreInvoke = (context) =>
                {
                    executionContext = context;
                }
            });

            var exception = Utils.AssertExceptionExpected <AmazonS3Exception>(() =>
            {
                var putObjectResponse = s3Client.PutObject(
                    new PutObjectRequest
                {
                    BucketName  = "bucketName",
                    Key         = "key",
                    ContentBody = "Test Content"
                });
            });

            Assert.AreEqual(HttpStatusCode.BadGateway, exception.StatusCode);
            Assert.AreEqual("zKxM2OZ8xQLqXp6UUteraUD5L8V-zNeiRAM9x7GsjPDHwXn7YJv8Jw==", exception.AmazonCloudFrontId);
            Assert.AreEqual(MAX_RETRIES, executionContext.RequestContext.Retries);
        }
Exemple #2
0
        private void TestAddressingForConfig(string bucketName, RegionEndpoint regionEndpoint, bool?usePathStyle,
                                             bool useAccelerate, bool useDualstack, string expectedUri)
        {
            var clientConfig = new AmazonS3Config
            {
                RegionEndpoint        = regionEndpoint,
                UseAccelerateEndpoint = useAccelerate,
                UseDualstackEndpoint  = useDualstack
            };

            if (usePathStyle.HasValue)
            {
                clientConfig.ForcePathStyle = usePathStyle.Value;
            }

            var client   = new MockS3Client(clientConfig);
            var response = client.ListObjects(new ListObjectsRequest
            {
                BucketName = bucketName
            });

            var expected = new Uri(expectedUri);
            var actual   = client.LastRequestUri;

            Assert.AreEqual(expected.AbsoluteUri, actual.AbsoluteUri);
        }
        public void RetryForHttpStatus200WithErrorResponse()
        {
            var s3Client = new MockS3Client(new BasicAWSCredentials("access_key", "secret_key"),
                                            new Amazon.S3.AmazonS3Config
            {
                ServiceURL    = @"http://S3200WithErrorResponse",
                MaxErrorRetry = MAX_RETRIES
            });

            IExecutionContext executionContext = null;

            s3Client.Pipeline.AddHandlerAfter <RetryHandler>(new CallbackHandler
            {
                OnPreInvoke = (context) =>
                {
                    executionContext = context;
                }
            });

            var exception = Utils.AssertExceptionExpected <AmazonS3Exception>(() =>
            {
                var completeMultipartUploadResponse = s3Client.CompleteMultipartUpload(
                    new CompleteMultipartUploadRequest
                {
                    BucketName = "bucketName",
                    Key        = "key",
                    PartETags  = new List <PartETag> {
                    },
                    UploadId   = "Upload123"
                });
            });

            Assert.AreEqual(MAX_RETRIES, executionContext.RequestContext.Retries);

            exception = Utils.AssertExceptionExpected <AmazonS3Exception>(() =>
            {
                var copyPartResponse = s3Client.CopyPart("source", "key",
                                                         "destination", "key", "Upload123");
            });
            Assert.AreEqual(MAX_RETRIES, executionContext.RequestContext.Retries);

            exception = Utils.AssertExceptionExpected <AmazonS3Exception>(() => {
                var copyObjectResponse = s3Client.CopyObject("source", "key",
                                                             "destination", "key");
            });
            Assert.AreEqual("InternalError", exception.ErrorCode);
            Assert.AreEqual("656c76696e6727732072657175657374", exception.RequestId);
            Assert.AreEqual("Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==", exception.AmazonId2);
            Assert.AreEqual("-UUNhfhfx0J622sdKihbDfqEvIa94CkVQvcb4AGlNmRbpbInOTYXSA==", exception.AmazonCloudFrontId);
            Assert.AreEqual(MAX_RETRIES, executionContext.RequestContext.Retries);
        }