コード例 #1
0
        public async Task IoExceptionRetryableRequestsTestAsync()
        {
            AmazonS3Config config = new AmazonS3Config
            {
                RegionEndpoint = Amazon.RegionEndpoint.USEast1,
                MaxErrorRetry  = 2
            };
            CSMTestUtilities testUtils = new CSMTestUtilities
            {
                Service             = "S3",
                ApiCall             = "CreateBucket",
                Domain              = "s3.amazonaws.com",
                Region              = "us-east-1",
                AttemptCount        = config.MaxErrorRetry + 1,
                SdkException        = "IOException",
                SdkExceptionMessage = "I/O",
                MaxRetriesExceeded  = 1,
                StashCount          = config.MaxErrorRetry + 3
            };
            var task = Task.Run(() => testUtils.UDPListener());

            AmazonS3Client client = new MockS3Client(config);

            var exception = await Record.ExceptionAsync(async() => await client.PutBucketAsync(new PutBucketRequest
            {
                BucketName = "TestBucket"
            }));

            Assert.NotNull(exception);
            Assert.IsType <IOException>(exception);
            Thread.Sleep(10);
            testUtils.EndTest();
            task.Wait();
            testUtils.Validate(task.Result);
        }
コード例 #2
0
        public void IoExceptionRetryableRequestsTest()
        {
            var            task   = Task.Run(() => UDPListener());
            AmazonS3Config config = new AmazonS3Config
            {
                RegionEndpoint = Amazon.RegionEndpoint.USEast1,
                MaxErrorRetry  = 2
            };

            AmazonS3Client client = new MockS3Client(config);

            try
            {
                client.PutBucketAsync(new PutBucketRequest
                {
                    BucketName = "TestBucket"
                }).Wait();
            }
            catch (Exception e)
            {
            }
            using (var udpClient = new UdpClient())
            {
                udpClient.Send(Encoding.UTF8.GetBytes("Exit"),
                               Encoding.UTF8.GetBytes("Exit").Length, "127.0.0.1", 31000);
                Thread.Sleep(10);
            }

            Assert.Equal(5, task.Result.Count);
            CSMTestUtilities testUtils = new CSMTestUtilities
            {
                Service             = "S3",
                ApiCall             = "CreateBucket",
                Domain              = "s3.amazonaws.com",
                Region              = "us-east-1",
                AttemptCount        = 3,
                SdkException        = "IOException",
                SdkExceptionMessage = "I/O"
            };

            foreach (var value in task.Result)
            {
                if (!value.Equals("Exit"))
                {
                    try
                    {
                        testUtils.Validate(JsonConvert.DeserializeObject <MonitoringAPICallEvent>(value));
                    }
                    catch (Exception e)
                    {
                        testUtils.Validate(JsonConvert.DeserializeObject <MonitoringAPICallAttempt>(value));
                    }
                }
                else
                {
                    break;
                }
            }
        }
コード例 #3
0
        public void SetUp()
        {
            cancellationTokenSource = new CancellationTokenSource();

            var settings = new SettingsHolder();

            mockSqsClient = new MockSqsClient();
            mockS3Client  = new MockS3Client();

            var transportConfiguration = new TransportConfiguration(settings);

            pump = new InputQueuePump(transportConfiguration, mockS3Client, mockSqsClient, new QueueCache(mockSqsClient, transportConfiguration));
        }
コード例 #4
0
        public async Task Should_upload_large_isolated_operations_request_to_s3()
        {
            var settings            = new SettingsHolder();
            var transportExtensions = new TransportExtensions <SqsTransport>(settings);

            transportExtensions.S3("someBucket", "somePrefix");

            var mockS3Client  = new MockS3Client();
            var mockSqsClient = new MockSqsClient();

            var transportConfiguration = new TransportConfiguration(settings);
            var dispatcher             = new MessageDispatcher(transportConfiguration, mockS3Client, mockSqsClient, null, new QueueCache(mockSqsClient, transportConfiguration), null);

            var transportOperations = new TransportOperations(
                new TransportOperation(
                    new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary <string, string>(), Encoding.Default.GetBytes(new string('x', 256 * 1024))),
                    new UnicastAddressTag("address1"),
                    DispatchConsistency.Isolated),
                new TransportOperation(
                    new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary <string, string>(), Encoding.Default.GetBytes(new string('x', 256 * 1024))),
                    new UnicastAddressTag("address2"),
                    DispatchConsistency.Isolated),
                new TransportOperation( /* Crazy long message id will cause the message to go over limits because attributes count as well */
                    new OutgoingMessage(new string('x', 256 * 1024), new Dictionary <string, string>(), Encoding.Default.GetBytes("{}")),
                    new UnicastAddressTag("address2"),
                    DispatchConsistency.Isolated));

            var transportTransaction = new TransportTransaction();
            var context = new ContextBag();

            await dispatcher.Dispatch(transportOperations, transportTransaction, context);

            Assert.AreEqual(3, mockSqsClient.RequestsSent.Count);
            Assert.AreEqual(3, mockS3Client.PutObjectRequestsSent.Count);

            var firstUpload  = mockS3Client.PutObjectRequestsSent.ElementAt(0);
            var secondUpload = mockS3Client.PutObjectRequestsSent.ElementAt(1);
            var thirdUpload  = mockS3Client.PutObjectRequestsSent.ElementAt(2);

            Assert.AreEqual("someBucket", firstUpload.BucketName);
            Assert.AreEqual("someBucket", secondUpload.BucketName);
            Assert.AreEqual("someBucket", thirdUpload.BucketName);
            StringAssert.Contains($@"""Body"":"""",""S3BodyKey"":""{firstUpload.Key}", mockSqsClient.RequestsSent.ElementAt(0).MessageBody);
            StringAssert.Contains($@"""Body"":"""",""S3BodyKey"":""{secondUpload.Key}", mockSqsClient.RequestsSent.ElementAt(1).MessageBody);
            StringAssert.Contains($@"""Body"":"""",""S3BodyKey"":""{thirdUpload.Key}", mockSqsClient.RequestsSent.ElementAt(2).MessageBody);
        }