Search in sources :

Example 6 with DBInstance

use of com.amazonaws.services.rds.model.DBInstance in project Synapse-Stack-Builder by Sage-Bionetworks.

the class MySqlDatabaseSetupTest method testWaitForDatabaseNotAvailable.

@Test
public void testWaitForDatabaseNotAvailable() throws Exception {
    when(mockDbInstance.getDBInstanceStatus()).thenReturn("busy");
    when(mockDbInstance.getDBInstanceIdentifier()).thenReturn("dbInstanceId");
    List<DBInstance> expectedDBInstances = Arrays.asList(mockDbInstance);
    when(mockDBInstancesResult.getDBInstances()).thenReturn(expectedDBInstances);
    ArgumentCaptor<DescribeDBInstancesRequest> captor = new ArgumentCaptor<>();
    when(mockClient.describeDBInstances(captor.capture())).thenReturn(mockDBInstancesResult);
    DBInstance instance = databaseSetup.waitForDatabase(mockDbInstance);
    List<DescribeDBInstancesRequest> actualRequests = captor.getAllValues();
    assertEquals(10, actualRequests.size());
    assertNull(instance);
}
Also used : ArgumentCaptor(org.mockito.ArgumentCaptor) DBInstance(com.amazonaws.services.rds.model.DBInstance) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.Test)

Example 7 with DBInstance

use of com.amazonaws.services.rds.model.DBInstance in project Synapse-Stack-Builder by Sage-Bionetworks.

the class MySqlDatabaseSetupTest method testCreateOrGetDatabaseInstanceDoesExist.

@Test
public void testCreateOrGetDatabaseInstanceDoesExist() {
    // For this case the database already exists so it should not be created again.
    String dbIdentifier = "id-123";
    CreateDBInstanceRequest request = MySqlDatabaseSetup.getDefaultCreateDBInstanceRequest();
    request.setDBInstanceIdentifier(dbIdentifier);
    DescribeDBInstancesRequest describeRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbIdentifier);
    DBInstance instance = new DBInstance();
    instance.setDBInstanceIdentifier(dbIdentifier);
    DescribeDBInstancesResult describeResult = new DescribeDBInstancesResult();
    describeResult.withDBInstances(instance);
    when(mockClient.describeDBInstances(describeRequest)).thenReturn(describeResult);
    DBInstance instanceResult = databaseSetup.createOrGetDatabaseInstance(request);
    assertEquals(instance, instanceResult);
    // Describe once
    verify(mockClient, times(1)).describeDBInstances(describeRequest);
    // Create should not be called this time.
    verify(mockClient, times(0)).createDBInstance(request);
}
Also used : CreateDBInstanceRequest(com.amazonaws.services.rds.model.CreateDBInstanceRequest) DBInstance(com.amazonaws.services.rds.model.DBInstance) DescribeDBInstancesResult(com.amazonaws.services.rds.model.DescribeDBInstancesResult) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.Test)

Example 8 with DBInstance

use of com.amazonaws.services.rds.model.DBInstance in project Synapse-Stack-Builder by Sage-Bionetworks.

the class MySqlDatabaseSetupTest method testDeleteDatabaseInstanceDoesNotExist.

@Test
public void testDeleteDatabaseInstanceDoesNotExist() {
    // Should just be a no-op
    DeleteDBInstanceRequest req = new DeleteDBInstanceRequest();
    when(mockClient.deleteDBInstance(req)).thenThrow(new DBInstanceNotFoundException("Database instance does not exist"));
    DBInstance inst = databaseSetup.deleteDatabaseInstance(req);
    assertNull(inst);
}
Also used : DeleteDBInstanceRequest(com.amazonaws.services.rds.model.DeleteDBInstanceRequest) DBInstanceNotFoundException(com.amazonaws.services.rds.model.DBInstanceNotFoundException) DBInstance(com.amazonaws.services.rds.model.DBInstance) Test(org.junit.Test)

Example 9 with DBInstance

use of com.amazonaws.services.rds.model.DBInstance in project Synapse-Stack-Builder by Sage-Bionetworks.

the class MySqlDatabaseSetupTest method testWaitForDatabaseBecomesAvailable.

@Test
public void testWaitForDatabaseBecomesAvailable() throws Exception {
    when(mockDbInstance.getDBInstanceStatus()).thenReturn("busy", "busy", "available");
    when(mockDbInstance.getDBInstanceIdentifier()).thenReturn("dbInstanceId");
    List<DBInstance> expectedDBInstances = Arrays.asList(mockDbInstance);
    when(mockDBInstancesResult.getDBInstances()).thenReturn(expectedDBInstances);
    ArgumentCaptor<DescribeDBInstancesRequest> captor = new ArgumentCaptor<>();
    when(mockClient.describeDBInstances(captor.capture())).thenReturn(mockDBInstancesResult);
    DBInstance instance = databaseSetup.waitForDatabase(mockDbInstance);
    List<DescribeDBInstancesRequest> actualRequests = captor.getAllValues();
    assertEquals(3, actualRequests.size());
    assertNotNull(instance);
}
Also used : ArgumentCaptor(org.mockito.ArgumentCaptor) DBInstance(com.amazonaws.services.rds.model.DBInstance) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.Test)

Example 10 with DBInstance

use of com.amazonaws.services.rds.model.DBInstance in project Synapse-Stack-Builder by Sage-Bionetworks.

the class TestHelper method createTestResources.

/**
 * Create GeneratedResources that can be used for a test.
 *
 * @param config
 * @return
 */
public static GeneratedResources createTestResources(InputConfiguration config) {
    GeneratedResources resources = new GeneratedResources();
    resources.setIdGeneratorDatabase(new DBInstance().withDBInstanceIdentifier(config.getIdGeneratorDatabaseIdentifier()).withEndpoint(new Endpoint().withAddress("id-gen-db.someplace.com")));
    resources.setStackInstancesDatabase(new DBInstance().withDBInstanceIdentifier(config.getStackInstanceDatabaseIdentifier()).withEndpoint(new Endpoint().withAddress("stack-instance-db.someplace.com")));
    resources.setSearchDomain(new DomainStatus().withSearchService(new ServiceEndpoint().withEndpoint("search-service.someplace.com")));
    resources.getSearchDomain().setDocService(new ServiceEndpoint().withEndpoint("doc-service.someplace.com"));
    resources.setSslCertificate(StackEnvironmentType.REPO, new ServerCertificateMetadata().withArn("ssl:arn:123"));
    resources.setSslCertificate(StackEnvironmentType.WORKERS, new ServerCertificateMetadata().withArn("ssl:arn:123"));
    resources.setSslCertificate(StackEnvironmentType.PORTAL, new ServerCertificateMetadata().withArn("ssl:arn:456"));
    resources.setACMCertificateArn(StackEnvironmentType.PORTAL, "arn:aws:acm:us-east1:123456789012:certificate/12345678-1234-1234-1234-123456789012");
    resources.setACMCertificateArn(StackEnvironmentType.REPO, "arn:aws:acm:us-east1:123456789012:certificate/12345678-1234-1234-1234-223456789012");
    resources.setACMCertificateArn(StackEnvironmentType.WORKERS, "arn:aws:acm:us-east1:123456789012:certificate/12345678-1234-1234-1234-323456789012");
    resources.setPortalApplicationVersion(new ApplicationVersionDescription().withVersionLabel(config.getVersionLabel(PREFIX_PORTAL)));
    resources.setRepoApplicationVersion(new ApplicationVersionDescription().withVersionLabel(config.getVersionLabel(PREFIX_REPO)));
    resources.setWorkersApplicationVersion(new ApplicationVersionDescription().withVersionLabel(config.getVersionLabel(PREFIX_WORKERS)));
    resources.setStackKeyPair(new KeyPairInfo().withKeyName(config.getStackKeyPairName()));
    // Add tables database instances
    List<DBInstance> tablesInstances = new LinkedList<DBInstance>();
    tablesInstances.add(new DBInstance().withEndpoint(new Endpoint().withAddress("tables.endpoint.one")));
    tablesInstances.add(new DBInstance().withEndpoint(new Endpoint().withAddress("tables.endpoint.two")));
    resources.setStackInstanceTablesDatabases(tablesInstances);
    return resources;
}
Also used : ServerCertificateMetadata(com.amazonaws.services.identitymanagement.model.ServerCertificateMetadata) ApplicationVersionDescription(com.amazonaws.services.elasticbeanstalk.model.ApplicationVersionDescription) DBInstance(com.amazonaws.services.rds.model.DBInstance) ServiceEndpoint(com.amazonaws.services.cloudsearchv2.model.ServiceEndpoint) Endpoint(com.amazonaws.services.rds.model.Endpoint) KeyPairInfo(com.amazonaws.services.ec2.model.KeyPairInfo) DomainStatus(com.amazonaws.services.cloudsearchv2.model.DomainStatus) ServiceEndpoint(com.amazonaws.services.cloudsearchv2.model.ServiceEndpoint) LinkedList(java.util.LinkedList)

Aggregations

DBInstance (com.amazonaws.services.rds.model.DBInstance)16 DescribeDBInstancesRequest (com.amazonaws.services.rds.model.DescribeDBInstancesRequest)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 DeleteDBInstanceRequest (com.amazonaws.services.rds.model.DeleteDBInstanceRequest)3 DescribeDBInstancesResult (com.amazonaws.services.rds.model.DescribeDBInstancesResult)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3 CreateDBInstanceRequest (com.amazonaws.services.rds.model.CreateDBInstanceRequest)2 DomainStatus (com.amazonaws.services.cloudsearchv2.model.DomainStatus)1 ServiceEndpoint (com.amazonaws.services.cloudsearchv2.model.ServiceEndpoint)1 DescribeAlarmsResult (com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult)1 PutMetricAlarmRequest (com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest)1 KeyPairInfo (com.amazonaws.services.ec2.model.KeyPairInfo)1 ApplicationVersionDescription (com.amazonaws.services.elasticbeanstalk.model.ApplicationVersionDescription)1 ServerCertificateMetadata (com.amazonaws.services.identitymanagement.model.ServerCertificateMetadata)1 DBInstanceNotFoundException (com.amazonaws.services.rds.model.DBInstanceNotFoundException)1 Endpoint (com.amazonaws.services.rds.model.Endpoint)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 Before (org.junit.Before)1