Search in sources :

Example 21 with AmazonRDS

use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.

the class AmazonRdsDataSourceUserTagsFactoryBeanTest method getObject_instanceWithOutTags_emptyMapReturned.

@Test
void getObject_instanceWithOutTags_emptyMapReturned() throws Exception {
    // Arrange
    AmazonRDS amazonRds = mock(AmazonRDS.class);
    ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
    AmazonIdentityManagement amazonIdentityManagement = mock(AmazonIdentityManagement.class);
    AmazonRdsDataSourceUserTagsFactoryBean factoryBean = new AmazonRdsDataSourceUserTagsFactoryBean(amazonRds, "test", amazonIdentityManagement);
    factoryBean.setResourceIdResolver(resourceIdResolver);
    factoryBean.setResourceIdResolver(resourceIdResolver);
    factoryBean.setRegion(Region.getRegion(Regions.EU_WEST_1));
    when(resourceIdResolver.resolveToPhysicalResourceId("test")).thenReturn("stack-test");
    when(amazonIdentityManagement.getUser()).thenReturn(new GetUserResult().withUser(new User("/", "aemruli", "123456789012", "arn:aws:iam::1234567890:user/aemruli", new Date())));
    when(amazonRds.listTagsForResource(new ListTagsForResourceRequest().withResourceName("arn:aws:rds:eu-west-1:1234567890:db:stack-test"))).thenReturn(new ListTagsForResourceResult());
    // Act
    factoryBean.afterPropertiesSet();
    Map<String, String> userTagMap = factoryBean.getObject();
    // Assert
    assertThat(userTagMap.isEmpty()).isTrue();
}
Also used : GetUserResult(com.amazonaws.services.identitymanagement.model.GetUserResult) User(com.amazonaws.services.identitymanagement.model.User) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) AmazonRDS(com.amazonaws.services.rds.AmazonRDS) ListTagsForResourceRequest(com.amazonaws.services.rds.model.ListTagsForResourceRequest) ListTagsForResourceResult(com.amazonaws.services.rds.model.ListTagsForResourceResult) AmazonIdentityManagement(com.amazonaws.services.identitymanagement.AmazonIdentityManagement) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 22 with AmazonRDS

use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.

the class AmazonRdsReadReplicaAwareDataSourceFactoryBeanTest method afterPropertiesSet_instanceWithoutReadReplica_createsNoDataSourceRouter.

@Test
void afterPropertiesSet_instanceWithoutReadReplica_createsNoDataSourceRouter() throws Exception {
    // Arrange
    AmazonRDS amazonRDS = mock(AmazonRDS.class);
    DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
    when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceStatus("available").withDBName("test").withDBInstanceIdentifier("test").withEngine("mysql").withMasterUsername("admin").withEndpoint(new Endpoint().withAddress("localhost").withPort(3306))));
    AmazonRdsReadReplicaAwareDataSourceFactoryBean factoryBean = new AmazonRdsReadReplicaAwareDataSourceFactoryBean(amazonRDS, "test", "secret");
    factoryBean.setDataSourceFactory(dataSourceFactory);
    when(dataSourceFactory.createDataSource(new DataSourceInformation(DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret"))).thenReturn(mock(DataSource.class));
    // Act
    factoryBean.afterPropertiesSet();
    // Assert
    DataSource datasource = factoryBean.getObject();
    assertThat(datasource).isNotNull();
    verify(dataSourceFactory, times(1)).createDataSource(new DataSourceInformation(DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret"));
}
Also used : DataSourceFactory(io.awspring.cloud.jdbc.datasource.DataSourceFactory) DBInstance(com.amazonaws.services.rds.model.DBInstance) Endpoint(com.amazonaws.services.rds.model.Endpoint) AmazonRDS(com.amazonaws.services.rds.AmazonRDS) DataSourceInformation(io.awspring.cloud.jdbc.datasource.DataSourceInformation) DescribeDBInstancesResult(com.amazonaws.services.rds.model.DescribeDBInstancesResult) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) DataSource(javax.sql.DataSource) ReadOnlyRoutingDataSource(io.awspring.cloud.jdbc.datasource.ReadOnlyRoutingDataSource) Test(org.junit.jupiter.api.Test)

Example 23 with AmazonRDS

use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.

the class DatabaseInstanceStatusRetryPolicyTest method canRetry_noExceptionRegistered_returnsTrue.

@Test
void canRetry_noExceptionRegistered_returnsTrue() throws Exception {
    // Arrange
    AmazonRDS amazonRDS = mock(AmazonRDS.class);
    DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy(amazonRDS, "test");
    RetryContext retryContext = new RetryContextSupport(null);
    // Act
    policy.open(retryContext);
    // Assert
    assertThat(policy.canRetry(retryContext)).isTrue();
}
Also used : AmazonRDS(com.amazonaws.services.rds.AmazonRDS) RetryContext(org.springframework.retry.RetryContext) RetryContextSupport(org.springframework.retry.context.RetryContextSupport) Test(org.junit.jupiter.api.Test)

Example 24 with AmazonRDS

use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.

the class DatabaseInstanceStatusRetryPolicyTest method canRetry_retryPossibleDueToAvailableDatabase_returnsTrue.

@Test
void canRetry_retryPossibleDueToAvailableDatabase_returnsTrue() throws Exception {
    // Arrange
    AmazonRDS amazonRDS = mock(AmazonRDS.class);
    DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy(amazonRDS, "test");
    when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceStatus("available")));
    RetryContext retryContext = policy.open(new RetryContextSupport(null));
    // Act
    policy.registerThrowable(retryContext, new TransientDataAccessResourceException("not available"));
    // Assert
    assertThat(policy.canRetry(retryContext)).isTrue();
    policy.close(retryContext);
}
Also used : TransientDataAccessResourceException(org.springframework.dao.TransientDataAccessResourceException) DBInstance(com.amazonaws.services.rds.model.DBInstance) AmazonRDS(com.amazonaws.services.rds.AmazonRDS) RetryContext(org.springframework.retry.RetryContext) DescribeDBInstancesResult(com.amazonaws.services.rds.model.DescribeDBInstancesResult) RetryContextSupport(org.springframework.retry.context.RetryContextSupport) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.jupiter.api.Test)

Example 25 with AmazonRDS

use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.

the class AmazonRdsRetryInterceptorBeanDefinitionParserTest method parseInternal_customRegionConfigured_createsAmazonRdsClientWithCustomRegionConfigured.

@Test
void parseInternal_customRegionConfigured_createsAmazonRdsClientWithCustomRegionConfigured() throws Exception {
    // Arrange
    ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-customRegion.xml", getClass());
    // Act
    AmazonRDS amazonRDS = classPathXmlApplicationContext.getBean(AmazonRDS.class);
    // Assert
    assertThat(ReflectionTestUtils.getField(amazonRDS, "endpoint").toString()).isEqualTo("https://rds.eu-west-1.amazonaws.com");
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) AmazonRDS(com.amazonaws.services.rds.AmazonRDS) Test(org.junit.jupiter.api.Test)

Aggregations

AmazonRDS (com.amazonaws.services.rds.AmazonRDS)27 Test (org.junit.jupiter.api.Test)24 DBInstance (com.amazonaws.services.rds.model.DBInstance)15 DescribeDBInstancesRequest (com.amazonaws.services.rds.model.DescribeDBInstancesRequest)15 DescribeDBInstancesResult (com.amazonaws.services.rds.model.DescribeDBInstancesResult)14 Endpoint (com.amazonaws.services.rds.model.Endpoint)10 DataSource (javax.sql.DataSource)9 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)7 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)7 ClassPathResource (org.springframework.core.io.ClassPathResource)7 DataSourceFactory (io.awspring.cloud.jdbc.datasource.DataSourceFactory)6 DataSourceInformation (io.awspring.cloud.jdbc.datasource.DataSourceInformation)6 AmazonIdentityManagement (com.amazonaws.services.identitymanagement.AmazonIdentityManagement)5 GetUserResult (com.amazonaws.services.identitymanagement.model.GetUserResult)5 User (com.amazonaws.services.identitymanagement.model.User)5 ListTagsForResourceRequest (com.amazonaws.services.rds.model.ListTagsForResourceRequest)5 ListTagsForResourceResult (com.amazonaws.services.rds.model.ListTagsForResourceResult)5 Date (java.util.Date)5 RetryContext (org.springframework.retry.RetryContext)5 RetryContextSupport (org.springframework.retry.context.RetryContextSupport)5