public async Task SingleInvalidRequestAsync() { AmazonDynamoDBConfig config = new AmazonDynamoDBConfig { RegionEndpoint = Amazon.RegionEndpoint.USEast1 }; CSMTestUtilities testUtils = new CSMTestUtilities { Service = "DynamoDB", ApiCall = "DeleteTable", AttemptCount = 1, Domain = "dynamodb.us-east-1.amazonaws.com", Region = "us-east-1", AWSException = "ResourceNotFoundException", AWSExceptionMessage = "Requested resource not found", HttpStatusCode = 400, MaxRetriesExceeded = 0, StashCount = 3 }; var task = Task.Run(() => testUtils.UDPListener()); AmazonDynamoDBClient client = new AmazonDynamoDBClient(config); var exception = await Record.ExceptionAsync(async() => await client.DeleteTableAsync(new DeleteTableRequest { TableName = "foobar" })); Assert.NotNull(exception); Assert.IsType <ResourceNotFoundException>(exception); Thread.Sleep(10); testUtils.EndTest(); task.Wait(); testUtils.Validate(task.Result); }
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); }
public async Task SingleSuccessfulRequestAsync() { AmazonDynamoDBConfig config = new AmazonDynamoDBConfig { RegionEndpoint = Amazon.RegionEndpoint.USEast1 }; CSMTestUtilities testUtils = new CSMTestUtilities { Service = "DynamoDB", ApiCall = "ListTables", AttemptCount = 1, Domain = "dynamodb.us-east-1.amazonaws.com", Region = "us-east-1", HttpStatusCode = 200, MaxRetriesExceeded = 0, StashCount = 3 }; var task = Task.Run(() => testUtils.UDPListener()); AmazonDynamoDBClient client = new AmazonDynamoDBClient(config); await client.ListTablesAsync(new ListTablesRequest { }); Thread.Sleep(10); testUtils.EndTest(); task.Wait(); testUtils.Validate(task.Result); }
public void SingleSuccessfulRequest() { ThreadPool.QueueUserWorkItem(UDPListener); CSMTestUtilities testUtils = new CSMTestUtilities { Service = "DynamoDB", ApiCall = "ListTables", AttemptCount = 1, Domain = "dynamodb.us-east-1.amazonaws.com", Region = "us-east-1", HttpStatusCode = 200, MaxRetriesExceeded = 0, StashCount = 3 }; AmazonDynamoDBConfig config = new AmazonDynamoDBConfig { RegionEndpoint = Amazon.RegionEndpoint.USEast1 }; AmazonDynamoDBClient client = new AmazonDynamoDBClient(config); client.ListTables(new ListTablesRequest { }); Thread.Sleep(10); testUtils.EndTest(); testUtils.Validate(stash); }
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; } } }
public void SingleInvalidRequest() { var task = Task.Run(() => UDPListener()); AmazonDynamoDBConfig config = new AmazonDynamoDBConfig { RegionEndpoint = Amazon.RegionEndpoint.USEast1 }; AmazonDynamoDBClient client = new AmazonDynamoDBClient(config); try { client.DeleteTableAsync(new DeleteTableRequest { TableName = "foobar" }).Wait(); } catch (Exception e) { } finally { 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(3, task.Result.Count); CSMTestUtilities testUtils = new CSMTestUtilities { Service = "DynamoDB", ApiCall = "DeleteTable", Domain = "dynamodb.us-east-1.amazonaws.com", Region = "us-east-1", AWSException = "ResourceNotFoundException", AWSExceptionMessage = "Requested resource not found", HttpStatusCode = 400 }; 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; } } } }
public void SingleSuccessfulRequest() { ThreadPool.QueueUserWorkItem(UDPListener); AmazonDynamoDBConfig config = new AmazonDynamoDBConfig { RegionEndpoint = Amazon.RegionEndpoint.USEast1 }; AmazonDynamoDBClient client = new AmazonDynamoDBClient(config); var result = client.BeginListTables(new ListTablesRequest(), null, null); client.EndListTables(result); 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(3, stash.Count); CSMTestUtilities testUtils = new CSMTestUtilities { Service = "DynamoDB", ApiCall = "ListTables", Domain = "dynamodb.us-east-1.amazonaws.com", Region = "us-east-1", HttpStatusCode = 200 }; foreach (var value in stash) { if (!value.Equals("Exit")) { try { testUtils.Validate(JsonConvert.DeserializeObject <MonitoringAPICallEvent>(value)); } catch (Exception e) { testUtils.Validate(JsonConvert.DeserializeObject <MonitoringAPICallAttempt>(value)); } } else { break; } } }
public async Task WebExceptionRetryableRequestsWithHttpStatusCodeTestAsync() { AmazonDynamoDBConfig config = new AmazonDynamoDBConfig { RegionEndpoint = Amazon.RegionEndpoint.USEast1, MaxErrorRetry = 2 }; CSMTestUtilities testUtils = new CSMTestUtilities { Service = "DynamoDB", ApiCall = "PutItem", Domain = "dynamodb.us-east-1.amazonaws.com", Region = "us-east-1", AttemptCount = config.MaxErrorRetry + 1, SdkException = "AmazonServiceException", SdkExceptionMessage = "WebException", HttpStatusCode = 400, MaxRetriesExceeded = 1, StashCount = config.MaxErrorRetry + 3 }; var task = Task.Run(() => testUtils.UDPListener()); var errorResponse = new Mock <HttpWebResponse>(); exceptionType = new WebException("Test exception", null, WebExceptionStatus.ConnectFailure, errorResponse.Object); errorResponse.SetupGet(foo => foo.StatusCode).Returns(HttpStatusCode.BadRequest); AmazonDynamoDBClient client = new MockDDBClient(config, exceptionType); Random generator = new Random(); Dictionary <string, AttributeValue> attributes = new Dictionary <string, AttributeValue>(); attributes["TestAttribute"] = new AttributeValue { S = generator.Next(0, 999999).ToString("D6") }; PutItemRequest request = new PutItemRequest { TableName = "TestTable", Item = attributes }; var exception = await Record.ExceptionAsync(async() => await client.PutItemAsync(request)); Assert.NotNull(exception); Assert.IsType <AmazonServiceException>(exception); Assert.IsType <WebException>(exception.InnerException); Thread.Sleep(10); testUtils.EndTest(); task.Wait(); testUtils.Validate(task.Result); }
public async Task IoExceptionRetryableRequestsTestAsync() { AmazonDynamoDBConfig config = new AmazonDynamoDBConfig { RegionEndpoint = Amazon.RegionEndpoint.USEast1, MaxErrorRetry = 0 }; CSMTestUtilities testUtils = new CSMTestUtilities { Service = "DynamoDB", ApiCall = "PutItem", Domain = "dynamodb.us-east-1.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()); exceptionType = new IOException(); AmazonDynamoDBClient client = new MockDDBClient(config, exceptionType); Random generator = new Random(); Dictionary <string, AttributeValue> attributes = new Dictionary <string, AttributeValue>(); attributes["TestAttribute"] = new AttributeValue { S = generator.Next(0, 999999).ToString("D6") }; PutItemRequest request = new PutItemRequest { TableName = "TestTable", Item = attributes }; var exception = await Record.ExceptionAsync(async() => await client.PutItemAsync(request)); Assert.NotNull(exception); Assert.IsType <IOException>(exception); Thread.Sleep(10); testUtils.EndTest(); task.Wait(); testUtils.Validate(task.Result); }
public void MultipleSuccessfulRequestsTest() { var task = Task.Run(() => UDPListener()); AmazonDynamoDBConfig config = new AmazonDynamoDBConfig { RegionEndpoint = Amazon.RegionEndpoint.USEast1 }; AmazonDynamoDBClient client = new MockDDBClient(config); Random generator = new Random(); TestTimer.Start(); while (TestTimer.ElapsedMilliseconds <= 5000) { // Define item attributes Dictionary <string, AttributeValue> attributes = new Dictionary <string, AttributeValue>(); attributes["TestAttribute"] = new AttributeValue { S = generator.Next(0, 999999).ToString("D6") }; PutItemRequest request = new PutItemRequest { TableName = "TestTable", Item = attributes }; client.PutItem(request); TestRequestExecution++; Thread.Sleep(10); } using (var udpClient = new UdpClient()) { udpClient.Send(Encoding.UTF8.GetBytes("Exit"), Encoding.UTF8.GetBytes("Exit").Length, "127.0.0.1", 31000); Thread.Sleep(10); } task.Wait(); TestTimer.Stop(); Assert.Equal(TestRequestExecution * 2 + 1, task.Result.Count); CSMTestUtilities testUtils = new CSMTestUtilities { Service = "DynamoDB", ApiCall = "PutItem", Domain = "dynamodb.us-east-1.amazonaws.com", Region = "us-east-1", HttpStatusCode = 200 }; 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; } } }
public void IoExceptionRetryableRequestsTest() { var task = Task.Run(() => UDPListener()); AmazonDynamoDBConfig config = new AmazonDynamoDBConfig { RegionEndpoint = Amazon.RegionEndpoint.USEast1, MaxErrorRetry = 2, }; exceptionType = new IOException(); AmazonDynamoDBClient client = new MockDDBClient(config, exceptionType); Random generator = new Random(); Dictionary <string, AttributeValue> attributes = new Dictionary <string, AttributeValue>(); attributes["TestAttribute"] = new AttributeValue { S = generator.Next(0, 999999).ToString("D6") }; PutItemRequest request = new PutItemRequest { TableName = "TestTable", Item = attributes }; try { client.PutItemAsync(request).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 = "DynamoDB", ApiCall = "PutItem", Domain = "dynamodb.us-east-1.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; } } }