com.amazonaws.services.rds.model.DescribeDBInstancesRequest Java Examples
The following examples show how to use
com.amazonaws.services.rds.model.DescribeDBInstancesRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RdsTableProviderTest.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
@Override protected void setUpRead() { final AtomicLong requestCount = new AtomicLong(0); when(mockRds.describeDBInstances(any(DescribeDBInstancesRequest.class))) .thenAnswer((InvocationOnMock invocation) -> { DescribeDBInstancesResult mockResult = mock(DescribeDBInstancesResult.class); List<DBInstance> values = new ArrayList<>(); values.add(makeValue(getIdValue())); values.add(makeValue(getIdValue())); values.add(makeValue("fake-id")); when(mockResult.getDBInstances()).thenReturn(values); if (requestCount.incrementAndGet() < 3) { when(mockResult.getMarker()).thenReturn(String.valueOf(requestCount.get())); } return mockResult; }); }
Example #2
Source File: BeanstalkConnector.java From cloudml with GNU Lesser General Public License v3.0 | 6 votes |
public String getDBEndPoint(String dbInstanceId, int timeout){ DescribeDBInstancesRequest ddbir = new DescribeDBInstancesRequest() .withDBInstanceIdentifier(dbInstanceId); System.out.println("Waiting for DB endpoints"); while(timeout -- > 0){ System.out.print("-"); DescribeDBInstancesResult ddbi = rdsClient.describeDBInstances(ddbir); Endpoint endpoint = ddbi.getDBInstances().get(0).getEndpoint(); if(endpoint != null && endpoint.toString().length()!=0) return endpoint.getAddress()+":"+endpoint.getPort(); try { Thread.sleep(1000); } catch (InterruptedException ex) { Logger.getLogger(BeanstalkConnector.class.getName()).log(Level.SEVERE, null, ex); } } return ""; }
Example #3
Source File: AwsRdsStopService.java From cloudbreak with Apache License 2.0 | 6 votes |
public void stop(AuthenticatedContext ac, DatabaseStack dbStack) throws ExecutionException, TimeoutException, InterruptedException { AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonRDS rdsClient = awsClient.createRdsClient(credentialView, regionName); String dbInstanceIdentifier = dbStack.getDatabaseServer().getServerId(); StopDBInstanceRequest stopDBInstanceRequest = new StopDBInstanceRequest(); stopDBInstanceRequest.setDBInstanceIdentifier(dbInstanceIdentifier); LOGGER.debug("RDS stop request"); try { rdsClient.stopDBInstance(stopDBInstanceRequest); } catch (RuntimeException ex) { throw new CloudConnectorException(ex.getMessage(), ex); } Waiter<DescribeDBInstancesRequest> rdsWaiter = customAmazonWaiterProvider .getDbInstanceStopWaiter(rdsClient); DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceIdentifier); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); run(rdsWaiter, describeDBInstancesRequest, stackCancellationCheck); LOGGER.debug("RDS stop process finished. DB Instance ID: {}", dbInstanceIdentifier); }
Example #4
Source File: AwsRdsStartService.java From cloudbreak with Apache License 2.0 | 6 votes |
public void start(AuthenticatedContext ac, DatabaseStack dbStack) throws ExecutionException, TimeoutException, InterruptedException { AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonRDS rdsClient = awsClient.createRdsClient(credentialView, regionName); String dbInstanceIdentifier = dbStack.getDatabaseServer().getServerId(); StartDBInstanceRequest startDBInstanceRequest = new StartDBInstanceRequest(); startDBInstanceRequest.setDBInstanceIdentifier(dbInstanceIdentifier); try { rdsClient.startDBInstance(startDBInstanceRequest); } catch (RuntimeException ex) { throw new CloudConnectorException(ex.getMessage(), ex); } Waiter<DescribeDBInstancesRequest> rdsWaiter = rdsClient.waiters().dBInstanceAvailable(); DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceIdentifier); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); run(rdsWaiter, describeDBInstancesRequest, stackCancellationCheck); }
Example #5
Source File: AmazonRdsDatabaseAutoConfigurationTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Bean AmazonRDSClient amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.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)) .withReadReplicaDBInstanceIdentifiers( "read1"))); return client; }
Example #6
Source File: DatabaseInstanceStatusRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@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); }
Example #7
Source File: DatabaseInstanceStatusRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@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); }
Example #8
Source File: AmazonRdsInstanceConfigurationTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Bean AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.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)) .withReadReplicaDBInstanceIdentifiers( "read1"))); return client; }
Example #9
Source File: AmazonRdsInstanceConfigurationTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Bean AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.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)) .withReadReplicaDBInstanceIdentifiers( "read1"))); return client; }
Example #10
Source File: AmazonRdsInstanceConfigurationTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Bean AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.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)) .withReadReplicaDBInstanceIdentifiers( "read1"))); return client; }
Example #11
Source File: AmazonRdsInstanceConfigurationTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Bean AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.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)) .withReadReplicaDBInstanceIdentifiers( "read1"))); return client; }
Example #12
Source File: AmazonRdsInstanceConfigurationTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Bean AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.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)) .withReadReplicaDBInstanceIdentifiers( "read1"))); return client; }
Example #13
Source File: AmazonRdsDataSourceFactoryBeanTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void afterPropertiesSet_customUserNameSet_createsInstanceWithCustomUserNameAndIgnoresMetaDataUserName() throws Exception { 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)))); AmazonRdsDataSourceFactoryBean amazonRdsDataSourceFactoryBean = new AmazonRdsDataSourceFactoryBean( amazonRDS, "test", "secret"); amazonRdsDataSourceFactoryBean.setUsername("superAdmin"); amazonRdsDataSourceFactoryBean.setDataSourceFactory(dataSourceFactory); amazonRdsDataSourceFactoryBean.afterPropertiesSet(); amazonRdsDataSourceFactoryBean.getObject(); verify(dataSourceFactory, times(1)).createDataSource(new DataSourceInformation( DatabaseType.MYSQL, "localhost", 3306, "test", "superAdmin", "secret")); }
Example #14
Source File: RdsTableProvider.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
/** * Calls DescribeDBInstances on the AWS RDS Client returning all DB Instances that match the supplied predicate and attempting * to push down certain predicates (namely queries for specific DB Instance) to EC2. * * @See TableProvider */ @Override public void readWithConstraint(BlockSpiller spiller, ReadRecordsRequest recordsRequest, QueryStatusChecker queryStatusChecker) { boolean done = false; DescribeDBInstancesRequest request = new DescribeDBInstancesRequest(); ValueSet idConstraint = recordsRequest.getConstraints().getSummary().get("instance_id"); if (idConstraint != null && idConstraint.isSingleValue()) { request.setDBInstanceIdentifier(idConstraint.getSingleValue().toString()); } while (!done) { DescribeDBInstancesResult response = rds.describeDBInstances(request); for (DBInstance instance : response.getDBInstances()) { instanceToRow(instance, spiller); } request.setMarker(response.getMarker()); if (response.getMarker() == null || !queryStatusChecker.isQueryRunning()) { done = true; } } }
Example #15
Source File: AmazonRdsDataSourceFactoryBeanTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void afterPropertiesSet_noInstanceFound_reportsIllegalStateException() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); when(amazonRDS.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) .thenThrow(new DBInstanceNotFoundException("foo")); AmazonRdsDataSourceFactoryBean amazonRdsDataSourceFactoryBean = new AmazonRdsDataSourceFactoryBean( amazonRDS, "test", "foo"); // Assert assertThatThrownBy(amazonRdsDataSourceFactoryBean::afterPropertiesSet) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("No database instance with id:'test'"); }
Example #16
Source File: AmazonRdsDataSourceFactoryBean.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
/** * Retrieves the {@link com.amazonaws.services.rds.model.DBInstance} information. * @param identifier - the database identifier used * @return - the db instance * @throws IllegalStateException if the db instance is not found */ protected DBInstance getDbInstance(String identifier) throws IllegalStateException { DBInstance instance; try { DescribeDBInstancesResult describeDBInstancesResult = this.amazonRds .describeDBInstances(new DescribeDBInstancesRequest() .withDBInstanceIdentifier(identifier)); instance = describeDBInstancesResult.getDBInstances().get(0); } catch (DBInstanceNotFoundException e) { throw new IllegalStateException(MessageFormat.format( "No database instance with id:''{0}'' found. Please specify a valid db instance", identifier)); } return instance; }
Example #17
Source File: FetchRdsJobTest.java From fullstop with Apache License 2.0 | 6 votes |
@SuppressWarnings("ResultOfMethodCallIgnored") @Test public void testCheck() { final FetchRdsJob fetchRdsJob = new FetchRdsJob(accountIdSupplierMock, clientProviderMock, jobsPropertiesMock, violationSinkMock, exceptionHandlerMock); when(amazonRDSClientMock.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenReturn(describeDBInstancesResultMock); fetchRdsJob.run(); ArgumentCaptor<Violation> violations = ArgumentCaptor.forClass(Violation.class); verify(violationSinkMock, times(2)).put(violations.capture()); verify(accountIdSupplierMock, times(1)).get(); verify(amazonRDSClientMock, times(1)).describeDBInstances(any(DescribeDBInstancesRequest.class)); verify(jobsPropertiesMock, times(1)).getWhitelistedRegions(); verify(clientProviderMock, times(1)).getClient(any(), any(String.class), any(Region.class)); // Regression test for #479: Make sure that the metadata lists the correct endpoints. assertArrayEquals(new String[]{"aws.db.cn", "aws.db2.cn"}, violations.getAllValues().stream() .map(violation -> (Map) violation.getMetaInfo()) .map(metaInfo -> metaInfo.get("unsecuredDatabase")) .toArray()); }
Example #18
Source File: RedshiftInstanceUtil.java From obevo with Apache License 2.0 | 6 votes |
private void describe(String dbInstanceIdentifier) throws Exception { while (true) { DescribeDBInstancesRequest request = new DescribeDBInstancesRequest() .withDBInstanceIdentifier(dbInstanceIdentifier); DescribeClustersResult response = client.describeClusters(new DescribeClustersRequest() .withClusterIdentifier(INSTANCE_ID) ); Cluster dbInstance = response.getClusters().get(0); if (!dbInstance.getClusterStatus().equalsIgnoreCase("creating")) { System.out.println("Done! " + response); System.out.println(dbInstance.getEndpoint().getAddress()); System.out.println(dbInstance.getEndpoint().getPort()); break; } System.out.println("Not done - will wait 10s: " + response); Thread.sleep(10000L); } }
Example #19
Source File: CreateDbInstance.java From obevo with Apache License 2.0 | 6 votes |
private void describe(String dbInstanceIdentifier) throws Exception { while (true) { DescribeDBInstancesRequest request = new DescribeDBInstancesRequest() .withDBInstanceIdentifier(dbInstanceIdentifier); DescribeDBInstancesResult response = client.describeDBInstances(request); DBInstance dbInstance = response.getDBInstances().get(0); if (!dbInstance.getDBInstanceStatus().equalsIgnoreCase("creating")) { System.out.println("Done! " + response); System.out.println(dbInstance.getEndpoint().getAddress()); System.out.println(dbInstance.getEndpoint().getPort()); break; } System.out.println("Not done - will wait 10s: " + response); Thread.sleep(10000L); } }
Example #20
Source File: DatabaseInstanceStatusRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@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"); }
Example #21
Source File: BeanstalkConnector.java From cloudml with GNU Lesser General Public License v3.0 | 5 votes |
public String getDBStatus(String dbInstanceId){ DescribeDBInstancesRequest ddbir = new DescribeDBInstancesRequest() .withDBInstanceIdentifier(dbInstanceId); DescribeDBInstancesResult ddbi = rdsClient.describeDBInstances(ddbir); try{ return ddbi.getDBInstances().get(0).getStatusInfos().toString(); }catch(Exception e){ throw new RuntimeException("DBInstance not found"); } }
Example #22
Source File: AwsRdsStatusLookupServiceTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void shouldReturnDeletedInCaseOfDBInstanceNotFoundException() { when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenThrow(DBInstanceNotFoundException.class); ExternalDatabaseStatus result = victim.getStatus(authenticatedContext, dbStack); assertEquals(ExternalDatabaseStatus.DELETED, result); }
Example #23
Source File: AwsRdsStatusLookupServiceTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void shouldLookupUpdateInProgressExternalDatabaseStatus() { when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenReturn(describeDBInstancesResult); when(describeDBInstancesResult.getDBInstances()).thenReturn(Arrays.asList(dbInstance)); when(dbInstance.getDBInstanceStatus()).thenReturn(DB_INSTANCE_STATUS_ANY); ExternalDatabaseStatus result = victim.getStatus(authenticatedContext, dbStack); assertEquals(ExternalDatabaseStatus.UPDATE_IN_PROGRESS, result); }
Example #24
Source File: AwsRdsStatusLookupServiceTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void shouldLookupStoppedExternalDatabaseStatus() { when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenReturn(describeDBInstancesResult); when(describeDBInstancesResult.getDBInstances()).thenReturn(Arrays.asList(dbInstance)); when(dbInstance.getDBInstanceStatus()).thenReturn(DB_INSTANCE_STATUS_STOPPED); ExternalDatabaseStatus result = victim.getStatus(authenticatedContext, dbStack); assertEquals(ExternalDatabaseStatus.STOPPED, result); }
Example #25
Source File: AwsRdsStatusLookupServiceTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void shouldLookupStartedExternalDatabaseStatus() { when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenReturn(describeDBInstancesResult); when(describeDBInstancesResult.getDBInstances()).thenReturn(Arrays.asList(dbInstance)); when(dbInstance.getDBInstanceStatus()).thenReturn(DB_INSTANCE_STATUS_STARTED); ExternalDatabaseStatus result = victim.getStatus(authenticatedContext, dbStack); assertEquals(ExternalDatabaseStatus.STARTED, result); }
Example #26
Source File: PublicAccessAutoFix.java From pacbot with Apache License 2.0 | 5 votes |
/** * Gets the DB instance for rds db resource. * * @param clientMap the client map * @param resourceId the resource id * @return the DB instance for rds db resource * @throws Exception the exception */ public static List<DBInstance> getDBInstanceForRdsDbResource(Map<String,Object> clientMap,String resourceId) throws Exception { AmazonRDS amazonRDS = (AmazonRDS) clientMap.get("client"); DescribeDBInstancesRequest instancesRequest = new DescribeDBInstancesRequest(); instancesRequest.setDBInstanceIdentifier(resourceId); DescribeDBInstancesResult dbInstancesResult = amazonRDS.describeDBInstances(instancesRequest); return dbInstancesResult.getDBInstances(); }
Example #27
Source File: AmazonRdsDatabaseAutoConfigurationTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Bean AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.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)) .withReadReplicaDBInstanceIdentifiers( "read1"))); when(client.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("read1"))) .thenReturn(new DescribeDBInstancesResult().withDBInstances( new DBInstance().withDBInstanceStatus("available") .withDBName("read1") .withDBInstanceIdentifier("read1") .withEngine("mysql") .withMasterUsername("admin") .withEndpoint(new Endpoint() .withAddress("localhost") .withPort(3306)))); return client; }
Example #28
Source File: AmazonRdsDatabaseAutoConfigurationTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Bean AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.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)))); when(client.describeDBInstances(new DescribeDBInstancesRequest() .withDBInstanceIdentifier("anotherOne"))) .thenReturn(new DescribeDBInstancesResult().withDBInstances( new DBInstance().withDBInstanceStatus("available") .withDBName("test") .withDBInstanceIdentifier("anotherOne") .withEngine("mysql") .withMasterUsername("admin") .withEndpoint(new Endpoint() .withAddress("localhost") .withPort(3306)))); return client; }
Example #29
Source File: AmazonRdsDataSourceFactoryBeanTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void newInstance_withResourceIdResolver_createsInstanceWithResolvedName() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class); ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class); DataSource dataSource = mock(DataSource.class); when(resourceIdResolver.resolveToPhysicalResourceId("test")).thenReturn("bar"); when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest() .withDBInstanceIdentifier("bar"))).thenReturn( new DescribeDBInstancesResult().withDBInstances(new DBInstance() .withDBInstanceStatus("available").withDBName("test") .withDBInstanceIdentifier("bar").withEngine("mysql") .withMasterUsername("admin").withEndpoint(new Endpoint() .withAddress("localhost").withPort(3306)))); when(dataSourceFactory.createDataSource(new DataSourceInformation( DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret"))) .thenReturn(dataSource); AmazonRdsDataSourceFactoryBean amazonRdsDataSourceFactoryBean = new AmazonRdsDataSourceFactoryBean( amazonRDS, "test", "secret"); amazonRdsDataSourceFactoryBean.setDataSourceFactory(dataSourceFactory); amazonRdsDataSourceFactoryBean.setResourceIdResolver(resourceIdResolver); // Act amazonRdsDataSourceFactoryBean.afterPropertiesSet(); // Assert assertThat(amazonRdsDataSourceFactoryBean.getObject()).isNotNull(); verify(dataSourceFactory, times(1)).createDataSource(new DataSourceInformation( DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret")); }
Example #30
Source File: DatabaseInstanceStatusRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@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); }