AwsAutoScalingDeployUtils { public boolean shouldAddExtraInstance(AutoScalingGroup autoScalingGroup) { return autoScalingGroup.getInstances().size() < autoScalingGroup.getMaxSize() && !(activeConfiguration.getMaxCapacity() != -1 && autoScalingGroup.getInstances().size() > activeConfiguration.getMaxCapacity()); } AwsAutoScalingDeployUtils(String region, DeployConfiguration activeConfiguration, Log log); AutoScalingGroup getAutoScalingGroup(); void suspendScheduledActions(); void setMinimalCapacity(int cap); void resumeScheduledActions(); boolean checkInstanceInService(String instanceId); List<Ec2Instance> getInstancesForAutoScalingGroup(Log log, AutoScalingGroup autoScalingGroup); void enableStickiness(String loadbalancerName, List<Integer> ports); void disableStickiness(String loadbalancerName, List<Integer> ports); boolean shouldAddExtraInstance(AutoScalingGroup autoScalingGroup); void setDesiredCapacity(AutoScalingGroup autoScalingGroup, Integer capacity); void updateInstanceState(Ec2Instance instance, List<String> loadBalancerNames); boolean checkInstanceInServiceOnAllElb(Instance newInstance, List<String> loadBalancerNames); boolean checkEc2Instance(String instanceId); void setDeployMetadataTags(final String version, Properties properties);  }
@Test public void testShouldAddExtraInstance() throws Exception { when(deployConfiguration.getMaxCapacity()).thenReturn(4); when(autoScalingGroup.getMaxSize()).thenReturn(4); when(instances.size()).thenReturn(1); when(autoScalingGroup.getInstances()).thenReturn(instances); AwsAutoScalingDeployUtils utils = new AwsAutoScalingDeployUtils("eu-west-1", deployConfiguration, null); Assert.assertTrue(utils.shouldAddExtraInstance(autoScalingGroup)); }
@Test public void testShouldNotAddExtraInstance() throws Exception { when(deployConfiguration.getMaxCapacity()).thenReturn(4); when(autoScalingGroup.getMaxSize()).thenReturn(4); when(instances.size()).thenReturn(4); when(autoScalingGroup.getInstances()).thenReturn(instances); AwsAutoScalingDeployUtils utils = new AwsAutoScalingDeployUtils("eu-west-1", deployConfiguration, null); Assert.assertFalse(utils.shouldAddExtraInstance(autoScalingGroup)); }
@Test public void testShouldNotAddExtraInstance_NoConfiguredMax() throws Exception { when(deployConfiguration.getMaxCapacity()).thenReturn(-1); when(autoScalingGroup.getMaxSize()).thenReturn(4); when(instances.size()).thenReturn(4); when(autoScalingGroup.getInstances()).thenReturn(instances); AwsAutoScalingDeployUtils utils = new AwsAutoScalingDeployUtils("eu-west-1", deployConfiguration, null); Assert.assertFalse(utils.shouldAddExtraInstance(autoScalingGroup)); }