com.amazonaws.services.rds.model.Endpoint Java Examples

The following examples show how to use com.amazonaws.services.rds.model.Endpoint. 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: AmazonRdsInstanceConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: BeanstalkConnector.java    From cloudml with GNU Lesser General Public License v3.0 6 votes vote down vote up
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: AmazonRdsDatabaseAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: AmazonRdsInstanceConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: AmazonRdsInstanceConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: AmazonRdsInstanceConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: AmazonRdsInstanceConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: AmazonRdsDataSourceFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: AmazonRdsDataSourceFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void destroyInstance_shutdownInitiated_destroysDynamicDataSource() throws Exception {
	AmazonRDS amazonRDS = mock(AmazonRDS.class);
	DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
	DataSource dataSource = mock(DataSource.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))));

	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.afterPropertiesSet();

	amazonRdsDataSourceFactoryBean.getObject();

	amazonRdsDataSourceFactoryBean.destroy();

	verify(dataSourceFactory, times(1)).closeDataSource(dataSource);
}
 
Example #10
Source File: AmazonRdsDataSourceFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void afterPropertiesSet_noUserNameSet_createsInstanceWithUserNameFromMetaData()
		throws Exception {
	// Arrange
	AmazonRDS amazonRDS = mock(AmazonRDS.class);
	DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
	DataSource dataSource = mock(DataSource.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))));

	when(dataSourceFactory.createDataSource(new DataSourceInformation(
			DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret")))
					.thenReturn(dataSource);

	AmazonRdsDataSourceFactoryBean amazonRdsDataSourceFactoryBean = new AmazonRdsDataSourceFactoryBean(
			amazonRDS, "test", "secret");
	amazonRdsDataSourceFactoryBean.setDataSourceFactory(dataSourceFactory);

	// Act
	amazonRdsDataSourceFactoryBean.afterPropertiesSet();

	// Assert
	DataSource datasource = amazonRdsDataSourceFactoryBean.getObject();
	assertThat(datasource).isNotNull();

	verify(dataSourceFactory, times(1)).createDataSource(new DataSourceInformation(
			DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret"));
}
 
Example #11
Source File: AmazonRdsDataSourceFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: AmazonRdsReadReplicaAwareDataSourceFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example #13
Source File: AmazonRdsInstanceConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@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 #14
Source File: FetchRdsJobTest.java    From fullstop with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    this.clientProviderMock = mock(ClientProvider.class);
    this.jobsPropertiesMock = mock(JobsProperties.class);
    this.violationSinkMock = mock(ViolationSink.class);
    this.amazonRDSClientMock = mock(AmazonRDSClient.class);
    this.accountIdSupplierMock = mock(AccountIdSupplier.class);
    this.exceptionHandlerMock = mock(JobExceptionHandler.class);

    when(accountIdSupplierMock.get()).thenReturn(newHashSet("54321"));

    // Jobsproperties
    when(jobsPropertiesMock.getWhitelistedRegions()).thenReturn(newArrayList("eu-west-1"));

    // Dbinstances
    final Endpoint endpoint = new Endpoint();
    endpoint.setAddress("aws.db.cn");
    final Endpoint endpoint2 = new Endpoint();
    endpoint2.setAddress("aws.db2.cn");
    final DBInstance dbInstance1 = new DBInstance();
    dbInstance1.setPubliclyAccessible(true);
    dbInstance1.setEndpoint(endpoint);
    final DBInstance dbInstance2 = new DBInstance();
    dbInstance2.setPubliclyAccessible(false);
    dbInstance2.setEndpoint(endpoint);
    final DBInstance dbInstance3 = new DBInstance();
    dbInstance3.setPubliclyAccessible(true);
    dbInstance3.setEndpoint(endpoint2);
    describeDBInstancesResultMock = new DescribeDBInstancesResult();
    describeDBInstancesResultMock.setDBInstances(newArrayList(dbInstance1, dbInstance2, dbInstance3));

    // clientprovider
    when(clientProviderMock.getClient(any(), any(String.class), any(Region.class))).thenReturn(amazonRDSClientMock);

}
 
Example #15
Source File: AmazonRdsDatabaseAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: AmazonRdsDatabaseAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@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 #17
Source File: RdsTableProviderTest.java    From aws-athena-query-federation with Apache License 2.0 4 votes vote down vote up
private DBInstance makeValue(String id)
{
    return new DBInstance()
            .withDBInstanceIdentifier(id)
            .withAvailabilityZone("primary_az")
            .withAllocatedStorage(100)
            .withStorageEncrypted(true)
            .withBackupRetentionPeriod(100)
            .withAutoMinorVersionUpgrade(true)
            .withDBInstanceClass("instance_class")
            .withDbInstancePort(100)
            .withDBInstanceStatus("status")
            .withStorageType("storage_type")
            .withDbiResourceId("dbi_resource_id")
            .withDBName("name")
            .withDomainMemberships(new DomainMembership()
                    .withDomain("domain")
                    .withFQDN("fqdn")
                    .withIAMRoleName("iam_role")
                    .withStatus("status"))
            .withEngine("engine")
            .withEngineVersion("engine_version")
            .withLicenseModel("license_model")
            .withSecondaryAvailabilityZone("secondary_az")
            .withPreferredBackupWindow("backup_window")
            .withPreferredMaintenanceWindow("maint_window")
            .withReadReplicaSourceDBInstanceIdentifier("read_replica_source_id")
            .withDBParameterGroups(new DBParameterGroupStatus()
                    .withDBParameterGroupName("name")
                    .withParameterApplyStatus("status"))
            .withDBSecurityGroups(new DBSecurityGroupMembership()
                    .withDBSecurityGroupName("name")
                    .withStatus("status"))
            .withDBSubnetGroup(new DBSubnetGroup()
                    .withDBSubnetGroupName("name")
                    .withSubnetGroupStatus("status")
                    .withVpcId("vpc")
                    .withSubnets(new Subnet()
                            .withSubnetIdentifier("subnet")))
            .withStatusInfos(new DBInstanceStatusInfo()
                    .withStatus("status")
                    .withMessage("message")
                    .withNormal(true)
                    .withStatusType("type"))
            .withEndpoint(new Endpoint()
                    .withAddress("address")
                    .withPort(100)
                    .withHostedZoneId("zone"))
            .withInstanceCreateTime(new Date(100000))
            .withIops(100)
            .withMultiAZ(true)
            .withPubliclyAccessible(true);
}
 
Example #18
Source File: AmazonRdsReadReplicaAwareDataSourceFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@Test
void afterPropertiesSet_instanceWithReadReplica_createsDataSourceRouter()
		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))
									.withReadReplicaDBInstanceIdentifiers("read1",
											"read2")));

	when(amazonRDS.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))));

	when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest()
			.withDBInstanceIdentifier("read2"))).thenReturn(
					new DescribeDBInstancesResult().withDBInstances(new DBInstance()
							.withDBInstanceStatus("available").withDBName("read2")
							.withDBInstanceIdentifier("read2").withEngine("mysql")
							.withMasterUsername("admin").withEndpoint(new Endpoint()
									.withAddress("localhost").withPort(3306))));

	DataSource createdDataSource = mock(DataSource.class);
	Connection connection = mock(Connection.class);

	when(dataSourceFactory.createDataSource(new DataSourceInformation(
			DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret")))
					.thenReturn(createdDataSource);
	when(dataSourceFactory.createDataSource(new DataSourceInformation(
			DatabaseType.MYSQL, "localhost", 3306, "read1", "admin", "secret")))
					.thenReturn(createdDataSource);
	when(dataSourceFactory.createDataSource(new DataSourceInformation(
			DatabaseType.MYSQL, "localhost", 3306, "read2", "admin", "secret")))
					.thenReturn(createdDataSource);
	when(createdDataSource.getConnection()).thenReturn(connection);

	AmazonRdsReadReplicaAwareDataSourceFactoryBean factoryBean = new AmazonRdsReadReplicaAwareDataSourceFactoryBean(
			amazonRDS, "test", "secret");
	factoryBean.setDataSourceFactory(dataSourceFactory);

	// Act
	factoryBean.afterPropertiesSet();

	// Assert
	DataSource datasource = factoryBean.getObject();
	assertThat(datasource).isNotNull();
	assertThat(datasource instanceof LazyConnectionDataSourceProxy).isTrue();

	ReadOnlyRoutingDataSource source = (ReadOnlyRoutingDataSource) ((LazyConnectionDataSourceProxy) datasource)
			.getTargetDataSource();
	assertThat(source.getDataSources().size()).isEqualTo(3);
}
 
Example #19
Source File: DatabaseConnectionService.java    From Gatekeeper with Apache License 2.0 4 votes vote down vote up
private String getAddress(Endpoint endpoint, String dbName){
    return getAddress(endpoint.getAddress(), endpoint.getPort(), dbName);
}