use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class DatabaseInstanceStatusRetryPolicyTest method canRetry_withResourceIdResolver_returnsTrue.
@Test
void canRetry_withResourceIdResolver_returnsTrue() throws Exception {
// Arrange
AmazonRDS amazonRDS = mock(AmazonRDS.class);
ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy(amazonRDS, "foo");
when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceStatus("available")));
when(resourceIdResolver.resolveToPhysicalResourceId("foo")).thenReturn("test");
policy.setResourceIdResolver(resourceIdResolver);
RetryContext retryContext = policy.open(new RetryContextSupport(null));
// Act
policy.registerThrowable(retryContext, new TransientDataAccessResourceException("not available"));
// Assert
assertThat(policy.canRetry(retryContext)).isTrue();
policy.close(retryContext);
}
use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class DatabaseInstanceStatusRetryPolicyTest method canRetry_retryNotPossibleDueToNoDatabase_returnsFalse.
@Test
void canRetry_retryNotPossibleDueToNoDatabase_returnsFalse() throws Exception {
// Arrange
AmazonRDS amazonRDS = mock(AmazonRDS.class);
DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy(amazonRDS, "test");
when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenThrow(new DBInstanceNotFoundException("test"));
RetryContext retryContext = policy.open(new RetryContextSupport(null));
// Act
policy.registerThrowable(retryContext, new TransientDataAccessResourceException("not available"));
// Assert
assertThat(policy.canRetry(retryContext)).isFalse();
policy.close(retryContext);
}
use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class DatabaseInstanceStatusRetryPolicyTest method canRetry_multipleDatabasesFoundForInstanceIdentifier_reportsException.
@Test
void canRetry_multipleDatabasesFoundForInstanceIdentifier_reportsException() throws Exception {
// Arrange
AmazonRDS amazonRDS = mock(AmazonRDS.class);
DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy(amazonRDS, "test");
DescribeDBInstancesResult describeDBInstancesResult = new DescribeDBInstancesResult().withDBInstances(new DBInstance(), new DBInstance());
when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(describeDBInstancesResult);
RetryContext retryContext = policy.open(new RetryContextSupport(null));
// Act
policy.registerThrowable(retryContext, new TransientDataAccessResourceException("not available"));
// Assert
assertThatThrownBy(() -> policy.canRetry(retryContext)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Multiple databases found for same identifier");
}
use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class AmazonRdsDataSourceBeanDefinitionParserTest method parseInternal_fullConfiguration_createsBeanDefinitionWithoutReadReplicas.
@Test
void parseInternal_fullConfiguration_createsBeanDefinitionWithoutReadReplicas() throws Exception {
// Arrange
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(Mockito.class);
beanDefinitionBuilder.setFactoryMethod("mock");
beanDefinitionBuilder.addConstructorArgValue(AmazonRDS.class);
beanFactory.registerBeanDefinition(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonRDSClient.class.getName()), beanDefinitionBuilder.getBeanDefinition());
XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-fullConfiguration.xml", getClass()));
AmazonRDS client = beanFactory.getBean(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonRDSClient.class.getName()), AmazonRDS.class);
when(client.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceStatus("available").withDBName("test").withDBInstanceIdentifier("test").withEngine("mysql").withEndpoint(new Endpoint().withAddress("localhost").withPort(3306))));
BeanDefinition definition = beanFactory.getBeanDefinition("test");
assertThat(definition.getConstructorArgumentValues().getArgumentValue(1, String.class).getValue()).isEqualTo("test");
assertThat(definition.getConstructorArgumentValues().getArgumentValue(2, String.class).getValue()).isEqualTo("password");
assertThat(definition.getPropertyValues().getPropertyValue("username").getValue()).isEqualTo("myUser");
assertThat(definition.getPropertyValues().getPropertyValue("databaseName").getValue()).isEqualTo("fooDb");
DataSource dataSource = beanFactory.getBean(DataSource.class);
// Assert
assertThat(dataSource).isNotNull();
assertThat(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource).isTrue();
}
use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class AmazonRdsDataSourceBeanDefinitionParserTest method parseInternal_customRegionConfigured_amazonRdsClientWithCustomRegionConfigured.
@Test
void parseInternal_customRegionConfigured_amazonRdsClientWithCustomRegionConfigured() throws Exception {
// Arrange
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-customRegion.xml", getClass()));
// Act
AmazonRDS amazonRDS = beanFactory.getBean(AmazonRDS.class);
// Assert
// have to use reflection utils
assertThat(ReflectionTestUtils.getField(amazonRDS, "endpoint").toString()).isEqualTo("https://rds.eu-west-1.amazonaws.com");
}
Aggregations