use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationStackUtil in project cloudbreak by hortonworks.
the class ASGroupStatusCheckerTaskTest method successTest.
@Test
public void successTest() throws Exception {
int requiredInstances = 160;
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudContext cloudContext = mock(CloudContext.class);
String regionName = "eu-west-1";
when(cloudContext.getLocation()).thenReturn(Location.location(Region.region(regionName)));
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
CloudCredential cloudCredential = mock(CloudCredential.class);
when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
String asGroupName = "as-group";
AwsClient awsClient = mock(AwsClient.class);
AmazonEC2Client amazonEC2Client = mock(AmazonEC2Client.class);
when(awsClient.createAccess(any(AwsCredentialView.class), eq(regionName))).thenReturn(amazonEC2Client);
DescribeInstanceStatusResult firstDescribeInstanceStatusResult = new DescribeInstanceStatusResult();
List<InstanceStatus> firstInstanceStatuses = returnInstanceStatus(0, 100);
firstDescribeInstanceStatusResult.setInstanceStatuses(firstInstanceStatuses);
DescribeInstanceStatusResult secondDescribeInstanceStatusResult = new DescribeInstanceStatusResult();
List<InstanceStatus> secondInstanceStatuses = returnInstanceStatus(100, 160);
secondDescribeInstanceStatusResult.setInstanceStatuses(secondInstanceStatuses);
when(amazonEC2Client.describeInstanceStatus(any(DescribeInstanceStatusRequest.class))).thenReturn(firstDescribeInstanceStatusResult).thenReturn(secondDescribeInstanceStatusResult);
CloudFormationStackUtil cloudFormationStackUtil = mock(CloudFormationStackUtil.class);
List<String> instancIds = new ArrayList<>();
for (int i = 0; i < requiredInstances; i++) {
instancIds.add(Integer.toString(i));
}
AmazonAutoScalingClient autoScalingClient = mock(AmazonAutoScalingClient.class);
when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), anyString())).thenReturn(autoScalingClient);
when(autoScalingClient.describeScalingActivities(any(DescribeScalingActivitiesRequest.class))).thenReturn(new DescribeScalingActivitiesResult());
when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq(asGroupName))).thenReturn(instancIds);
ASGroupStatusCheckerTask asGroupStatusCheckerTask = new ASGroupStatusCheckerTask(authenticatedContext, asGroupName, requiredInstances, awsClient, cloudFormationStackUtil);
Boolean taskResult = asGroupStatusCheckerTask.call();
ArgumentCaptor<DescribeInstanceStatusRequest> instanceStatusRequestArgumentCaptor = ArgumentCaptor.forClass(DescribeInstanceStatusRequest.class);
verify(amazonEC2Client, times(2)).describeInstanceStatus(instanceStatusRequestArgumentCaptor.capture());
List<DescribeInstanceStatusRequest> allValues = instanceStatusRequestArgumentCaptor.getAllValues();
assertEquals(100, allValues.get(0).getInstanceIds().size());
assertEquals(60, allValues.get(1).getInstanceIds().size());
assertTrue(taskResult);
}
use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationStackUtil in project cloudbreak by hortonworks.
the class ASGroupStatusCheckerTaskTest method failTest.
@Test
public void failTest() throws Exception {
int requiredInstances = 160;
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudContext cloudContext = mock(CloudContext.class);
String regionName = "eu-west-1";
when(cloudContext.getLocation()).thenReturn(Location.location(Region.region(regionName)));
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
CloudCredential cloudCredential = mock(CloudCredential.class);
when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
String asGroupName = "as-group";
AwsClient awsClient = mock(AwsClient.class);
AmazonEC2Client amazonEC2Client = mock(AmazonEC2Client.class);
when(awsClient.createAccess(any(AwsCredentialView.class), eq(regionName))).thenReturn(amazonEC2Client);
DescribeInstanceStatusResult firstDescribeInstanceStatusResult = new DescribeInstanceStatusResult();
List<InstanceStatus> firstInstanceStatuses = returnInstanceStatus(0, 99);
firstDescribeInstanceStatusResult.setInstanceStatuses(firstInstanceStatuses);
DescribeInstanceStatusResult secondDescribeInstanceStatusResult = new DescribeInstanceStatusResult();
List<InstanceStatus> secondInstanceStatuses = returnInstanceStatus(100, 160);
secondDescribeInstanceStatusResult.setInstanceStatuses(secondInstanceStatuses);
when(amazonEC2Client.describeInstanceStatus(any(DescribeInstanceStatusRequest.class))).thenReturn(firstDescribeInstanceStatusResult).thenReturn(secondDescribeInstanceStatusResult);
CloudFormationStackUtil cloudFormationStackUtil = mock(CloudFormationStackUtil.class);
List<String> instancIds = new ArrayList<>();
for (int i = 0; i < requiredInstances; i++) {
instancIds.add(Integer.toString(i));
}
AmazonAutoScalingClient autoScalingClient = mock(AmazonAutoScalingClient.class);
when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), anyString())).thenReturn(autoScalingClient);
when(autoScalingClient.describeScalingActivities(any(DescribeScalingActivitiesRequest.class))).thenReturn(new DescribeScalingActivitiesResult());
when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq(asGroupName))).thenReturn(instancIds);
ASGroupStatusCheckerTask asGroupStatusCheckerTask = new ASGroupStatusCheckerTask(authenticatedContext, asGroupName, requiredInstances, awsClient, cloudFormationStackUtil);
Boolean taskResult = asGroupStatusCheckerTask.call();
ArgumentCaptor<DescribeInstanceStatusRequest> instanceStatusRequestArgumentCaptor = ArgumentCaptor.forClass(DescribeInstanceStatusRequest.class);
verify(amazonEC2Client, times(2)).describeInstanceStatus(instanceStatusRequestArgumentCaptor.capture());
List<DescribeInstanceStatusRequest> allValues = instanceStatusRequestArgumentCaptor.getAllValues();
assertEquals(100, allValues.get(0).getInstanceIds().size());
assertEquals(60, allValues.get(1).getInstanceIds().size());
assertFalse(taskResult);
}
Aggregations