Beispiel #1
0
        public void TestListBucketsResponseUnmarshallingAsync()
        {
            Tester.Reset();

            var context = CreateAsyncTestContext();
            var request = new ListBucketsRequest();

            ((RequestContext)context.RequestContext).OriginalRequest = request;
            ((RequestContext)context.RequestContext).Request         = new ListBucketsRequestMarshaller().Marshall(request);
            ((RequestContext)context.RequestContext).Unmarshaller    = ListBucketsResponseUnmarshaller.Instance;

            var response = MockWebResponse.CreateFromResource("ListBucketsResponse.txt")
                           as HttpWebResponse;

            context.ResponseContext.HttpResponse = new HttpWebRequestResponseData(response);

            var asyncResult = RuntimePipeline.InvokeAsync(context);

            asyncResult.AsyncWaitHandle.WaitOne();

            Assert.AreEqual(1, Tester.CallCount);
            Assert.IsInstanceOfType(context.ResponseContext.Response, typeof(ListBucketsResponse));

            var listBucketsResponse = context.ResponseContext.Response as ListBucketsResponse;

            Assert.AreEqual(4, listBucketsResponse.Buckets.Count);
        }
Beispiel #2
0
        public async Task TestRedirectAsync()
        {
            var context      = CreateTestContext();
            var httpResponse = context.ResponseContext.HttpResponse;

            Tester.Reset();
            Tester.Action2 = (callCount, executionContext) =>
            {
                if (callCount == 1)
                {
                    executionContext.ResponseContext.HttpResponse = new HttpWebRequestResponseData(
                        HttpWebResponseHelper.Create(HttpStatusCode.TemporaryRedirect,
                                                     new WebHeaderCollection {
                        { "location", RedirectLocation }
                    }));
                }
                else
                {
                    executionContext.ResponseContext.HttpResponse = httpResponse;
                }
            };
            Tester.Validate = (int callCount) =>
            {
                if (callCount == 2)
                {
                    Assert.AreEqual(RedirectLocation, context.RequestContext.Request.Endpoint.AbsoluteUri);
                }
            };

            await RuntimePipeline.InvokeAsync <AmazonWebServiceResponse>(context);

            Assert.AreEqual(2, Tester.CallCount);
        }
        public void TestSuppressed404Async()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                var errorResponse = (HttpWebResponse)MockWebResponse.CreateFromResource("404Response.txt");
                throw new HttpErrorResponseException(new HttpWebRequestResponseData(errorResponse));
            };

            var context = CreateAsyncTestContext();
            var request = new GetBucketPolicyRequest
            {
                BucketName = "nonexistentbucket"
            };

            ((RequestContext)context.RequestContext).OriginalRequest = request;
            ((RequestContext)context.RequestContext).Request         = new GetBucketPolicyRequestMarshaller().Marshall(request);
            ((RequestContext)context.RequestContext).Unmarshaller    = GetBucketPolicyResponseUnmarshaller.Instance;

            var asyncResult = RuntimePipeline.InvokeAsync(context);

            asyncResult.AsyncWaitHandle.WaitOne();

            Assert.IsNull(((RuntimeAsyncResult)asyncResult).Exception);
            Assert.AreEqual(1, Tester.CallCount);
        }
Beispiel #4
0
        public void TestRedirectAsync()
        {
            var context = CreateAsyncTestContext();

            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                if (callCount == 1)
                {
                    throw new WebException("Redirect", null, WebExceptionStatus.Success,
                                           HttpWebResponseHelper.Create(HttpStatusCode.TemporaryRedirect,
                                                                        new WebHeaderCollection {
                        { "location", RedirectLocation }
                    }));
                }
            };
            Tester.Validate = (int callCount) =>
            {
                if (callCount == 2)
                {
                    Assert.AreEqual(RedirectLocation, context.RequestContext.Request.Endpoint.AbsoluteUri);
                }
            };

            var asyncResult = RuntimePipeline.InvokeAsync(context);

            asyncResult.AsyncWaitHandle.WaitOne();
            Assert.AreEqual(2, Tester.CallCount);
        }
Beispiel #5
0
        public async Task TestSignerWithBasicCredentialsAsync()
        {
            var pipeline = new RuntimePipeline(new MockHandler());            
            pipeline.AddHandler(new Signer());
            pipeline.AddHandler(new CredentialsRetriever(new BasicAWSCredentials("accessKey", "secretKey")));

            var context = CreateTestContext();
            var signer = new MockSigner();
            ((RequestContext)context.RequestContext).Signer = signer;
            await pipeline.InvokeAsync<AmazonWebServiceResponse>(context);

            Assert.IsTrue(context.RequestContext.IsSigned);
            Assert.AreEqual(1, signer.SignCount);
        }
Beispiel #6
0
        public async Task TestSignerWithBasicCredentialsAsync()
        {
            var pipeline = new RuntimePipeline(new MockHandler());

            pipeline.AddHandler(new Signer());
            pipeline.AddHandler(new CredentialsRetriever(new BasicAWSCredentials("accessKey", "secretKey")));

            var signer  = new MockSigner();
            var context = CreateTestContext(signer);
            await pipeline.InvokeAsync <AmazonWebServiceResponse>(context);

            Assert.IsTrue(context.RequestContext.IsSigned);
            Assert.AreEqual(1, signer.SignCount);
        }
Beispiel #7
0
        public void TestSignerWithBasicCredentialsAsync()
        {
            var pipeline = new RuntimePipeline(new MockHandler());
            pipeline.AddHandler(new Signer());
            pipeline.AddHandler(new CredentialsRetriever(new BasicAWSCredentials("accessKey", "secretKey")));

            var context = CreateAsyncTestContext();
            var signer = new MockSigner();
            ((RequestContext)context.RequestContext).Signer = signer;
            var asyncResult = pipeline.InvokeAsync(context);
            asyncResult.AsyncWaitHandle.WaitOne();

            Assert.IsTrue(context.RequestContext.IsSigned);
            Assert.AreEqual(1, signer.SignCount);
        }
        public void RetryForIOExceptionAsync()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                throw new IOException();
            };

            var request     = CreateAsyncTestContext();
            var asyncResult = RuntimePipeline.InvokeAsync(request);

            asyncResult.AsyncWaitHandle.WaitOne();

            Assert.IsTrue(((RuntimeAsyncResult)asyncResult).Exception is IOException);
            Assert.AreEqual(MAX_RETRIES + 1, Tester.CallCount);
        }
        public void RetryForWebExceptionAsync()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                throw new AmazonServiceException(new WebException("WebException", WebExceptionStatus.ConnectFailure));
            };

            var request     = CreateAsyncTestContext();
            var asyncResult = RuntimePipeline.InvokeAsync(request);

            asyncResult.AsyncWaitHandle.WaitOne();

            Assert.IsTrue(((RuntimeAsyncResult)asyncResult).Exception is AmazonServiceException);
            Assert.AreEqual(MAX_RETRIES + 1, Tester.CallCount);
        }
        public async Task RetryForWebExceptionAsync()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                throw new AmazonServiceException(new WebException("WebException", WebExceptionStatus.ConnectFailure));
            };

            await Utils.AssertExceptionExpectedAsync(() =>
            {
                var request = CreateTestContext();
                return(RuntimePipeline.InvokeAsync <AmazonWebServiceResponse>(request));
            },
                                                     typeof(AmazonServiceException));

            Assert.AreEqual(MAX_RETRIES + 1, Tester.CallCount);
        }
        public void RetryForHttpStatus500Async()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                throw new AmazonServiceException("Internal Server Error",
                                                 new WebException(), HttpStatusCode.InternalServerError);
            };

            var request     = CreateAsyncTestContext();
            var asyncResult = RuntimePipeline.InvokeAsync(request);

            asyncResult.AsyncWaitHandle.WaitOne();

            Assert.IsTrue(((RuntimeAsyncResult)asyncResult).Exception is AmazonServiceException);
            Assert.AreEqual(MAX_RETRIES + 1, Tester.CallCount);
        }
        protected IAsyncResult BeginInvoke <TRequest>(TRequest request, IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller, AsyncCallback callback, object state) where TRequest : AmazonWebServiceRequest
        {
            ThrowIfDisposed();
            AsyncExecutionContext executionContext = new AsyncExecutionContext(new AsyncRequestContext(Config.LogMetrics)
            {
                ClientConfig    = Config,
                Marshaller      = marshaller,
                OriginalRequest = request,
                Signer          = Signer,
                Unmarshaller    = unmarshaller,
                Callback        = callback,
                State           = state,
                IsAsync         = true
            }, new AsyncResponseContext());

            return(RuntimePipeline.InvokeAsync(executionContext));
        }
        public void RetryForHttpStatus421Async()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                throw new AmazonServiceException("Invalid Endpoint Exception",
                                                 new WebException(), (HttpStatusCode)421);
            };

            var request     = CreateAsyncTestContext();
            var asyncResult = RuntimePipeline.InvokeAsync(request);

            asyncResult.AsyncWaitHandle.WaitOne();

            Assert.IsTrue(((RuntimeAsyncResult)asyncResult).Exception is AmazonServiceException);
            Assert.AreEqual(MAX_INVALID_ENDPOINT_RETRIES, Tester.CallCount);
        }
        protected IAsyncResult BeginInvoke <TRequest>(TRequest request, IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller, AsyncOptions asyncOptions, Action <AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper) where TRequest : AmazonWebServiceRequest
        {
            ThrowIfDisposed();
            asyncOptions = (asyncOptions ?? new AsyncOptions());
            AsyncExecutionContext executionContext = new AsyncExecutionContext(new AsyncRequestContext(Config.LogMetrics)
            {
                ClientConfig    = Config,
                Marshaller      = marshaller,
                OriginalRequest = request,
                Signer          = Signer,
                Unmarshaller    = unmarshaller,
                Action          = callbackHelper,
                AsyncOptions    = asyncOptions,
                IsAsync         = true
            }, new AsyncResponseContext());

            return(RuntimePipeline.InvokeAsync(executionContext));
        }
        public void Test404Async()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                var errorResponse = (HttpWebResponse)MockWebResponse.CreateFromResource("404Response.txt");
                throw new HttpErrorResponseException(new HttpWebRequestResponseData(errorResponse));
            };

            var context = CreateAsyncTestContext();

            var asyncResult = RuntimePipeline.InvokeAsync(context);

            asyncResult.AsyncWaitHandle.WaitOne();
            Assert.IsTrue(((RuntimeAsyncResult)asyncResult).Exception.GetType()
                          == typeof(AmazonS3Exception));
            Assert.AreEqual(1, Tester.CallCount);
        }
        public async Task RetryForHttpStatus421Async()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                throw new AmazonServiceException("Invalid Endpoint Exception",
                                                 new WebException(), (HttpStatusCode)421);
            };

            await Utils.AssertExceptionExpectedAsync(() =>
            {
                var request = CreateTestContext();
                return(RuntimePipeline.InvokeAsync <AmazonWebServiceResponse>(request));
            },
                                                     typeof(AmazonServiceException));

            Assert.AreEqual(MAX_INVALID_ENDPOINT_RETRIES, Tester.CallCount);
        }
        public async Task RetryForHttpStatus500Async()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                throw new AmazonServiceException("Internal Server Error",
                                                 new WebException(), HttpStatusCode.InternalServerError);
            };

            await Utils.AssertExceptionExpectedAsync(() =>
            {
                var request = CreateTestContext();
                return(RuntimePipeline.InvokeAsync <AmazonWebServiceResponse>(request));
            },
                                                     typeof(AmazonServiceException));

            Assert.AreEqual(MAX_RETRIES + 1, Tester.CallCount);
        }
        public async Task Test404Async()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                var errorResponse = (HttpWebResponse)MockWebResponse.CreateFromResource("404Response.txt");
                throw new HttpErrorResponseException(new HttpWebRequestResponseData(errorResponse));
            };

            var context = CreateTestContext();

            await Utils.AssertExceptionExpectedAsync(() =>
            {
                return(RuntimePipeline.InvokeAsync <AmazonWebServiceResponse>(context));
            },
                                                     typeof(AmazonS3Exception));

            Assert.AreEqual(1, Tester.CallCount);
        }
        public void TestExceptionWithNoServerResponseBodyAsync()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                throw new WebException("Connection closed.",
                                       WebExceptionStatus.ConnectionClosed);
            };

            var context = CreateAsyncTestContext();

            var asyncResult = RuntimePipeline.InvokeAsync(context);

            asyncResult.AsyncWaitHandle.WaitOne();
            // Test the exact exception type.
            Assert.IsTrue(((RuntimeAsyncResult)asyncResult).Exception.GetType()
                          == typeof(AmazonServiceException));
            Assert.AreEqual(1, Tester.CallCount);
        }
        public async Task TestExceptionWithNoServerResponseBodyAsync()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                throw new WebException("Connection closed.",
                                       WebExceptionStatus.ConnectionClosed);
            };

            var context   = CreateTestContext();
            var exception = await Utils.AssertExceptionExpectedAsync(() =>
            {
                return(RuntimePipeline.InvokeAsync <AmazonWebServiceResponse>(context));
            },
                                                                     typeof(AmazonServiceException));

            // Test the exact exception type.
            Assert.IsTrue(exception.GetType() == typeof(AmazonServiceException));
            Assert.AreEqual(1, Tester.CallCount);
        }
Beispiel #21
0
        public async Task TestListBucketsResponseUnmarshallingAsync()
        {
            Tester.Reset();

            var context = CreateTestContext();
            var request = new ListBucketsRequest();

            ((RequestContext)context.RequestContext).OriginalRequest = request;
            ((RequestContext)context.RequestContext).Request         = new ListBucketsRequestMarshaller().Marshall(request);
            ((RequestContext)context.RequestContext).Unmarshaller    = ListBucketsResponseUnmarshaller.Instance;

            var response = GetListBucketsResponse();

            context.ResponseContext.HttpResponse = new HttpWebRequestResponseData(response);

            var listBucketsResponse = await RuntimePipeline.InvokeAsync <ListBucketsResponse>(context);

            Assert.AreEqual(1, Tester.CallCount);
            Assert.IsInstanceOfType(context.ResponseContext.Response, typeof(ListBucketsResponse));
            Assert.AreEqual(4, listBucketsResponse.Buckets.Count);
        }
        public async Task TestSuppressed404Async()
        {
            Tester.Reset();
            Tester.Action = (int callCount) =>
            {
                var errorResponse = (HttpWebResponse)MockWebResponse.CreateFromResource("404Response.txt");
                throw new HttpErrorResponseException(new HttpWebRequestResponseData(errorResponse));
            };

            var context = CreateTestContext();
            var request = new GetBucketPolicyRequest
            {
                BucketName = "nonexistentbucket"
            };

            ((RequestContext)context.RequestContext).OriginalRequest = request;
            ((RequestContext)context.RequestContext).Request         = new GetBucketPolicyRequestMarshaller().Marshall(request);
            ((RequestContext)context.RequestContext).Unmarshaller    = GetBucketPolicyResponseUnmarshaller.Instance;

            await RuntimePipeline.InvokeAsync <AmazonWebServiceResponse>(context);

            Assert.AreEqual(1, Tester.CallCount);
        }
Beispiel #23
0
        public void TestSignerWithBasicCredentialsAsync()
        {
            var pipeline = new RuntimePipeline(new MockHandler());
            pipeline.AddHandler(new Signer());
            pipeline.AddHandler(new CredentialsRetriever(new BasicAWSCredentials("accessKey", "secretKey")));

            var context = CreateAsyncTestContext();
            var signer = new MockSigner();
            ((RequestContext)context.RequestContext).Signer = signer;
            var asyncResult = pipeline.InvokeAsync(context);
            asyncResult.AsyncWaitHandle.WaitOne();

            Assert.IsTrue(context.RequestContext.IsSigned);
            Assert.AreEqual(1, signer.SignCount);
        }