EmrDaoImpl implements EmrDao { protected List<InstanceGroupConfig> getInstanceGroupConfigs(InstanceDefinitions instanceDefinitions) { List<InstanceGroupConfig> instanceGroupConfigs = null; if (!emrHelper.isInstanceDefinitionsEmpty(instanceDefinitions)) { instanceGroupConfigs = new ArrayList<>(); instanceGroupConfigs.add(getInstanceGroupConfig(InstanceRoleType.MASTER, instanceDefinitions.getMasterInstances().getInstanceType(), instanceDefinitions.getMasterInstances().getInstanceCount(), instanceDefinitions.getMasterInstances().getInstanceSpotPrice(), instanceDefinitions.getMasterInstances().getEbsConfiguration())); if (instanceDefinitions.getCoreInstances() != null) { instanceGroupConfigs.add(getInstanceGroupConfig(InstanceRoleType.CORE, instanceDefinitions.getCoreInstances().getInstanceType(), instanceDefinitions.getCoreInstances().getInstanceCount(), instanceDefinitions.getCoreInstances().getInstanceSpotPrice(), instanceDefinitions.getCoreInstances().getEbsConfiguration())); } if (instanceDefinitions.getTaskInstances() != null) { instanceGroupConfigs.add(getInstanceGroupConfig(InstanceRoleType.TASK, instanceDefinitions.getTaskInstances().getInstanceType(), instanceDefinitions.getTaskInstances().getInstanceCount(), instanceDefinitions.getTaskInstances().getInstanceSpotPrice(), instanceDefinitions.getTaskInstances().getEbsConfiguration())); } } return instanceGroupConfigs; }  @Override String addEmrStep(String clusterId, StepConfig emrStepConfig, AwsParamsDto awsParamsDto); @Override String createEmrCluster(String clusterName, EmrClusterDefinition emrClusterDefinition, EmrParamsDto emrParamsDto); @Override synchronized ClusterSummary getActiveEmrClusterByNameAndAccountId(String clusterName, String accountId, AwsParamsDto awsParams); List<Application> getApplications(List<EmrClusterDefinitionApplication> emrClusterDefinitionApplications); @Override StepSummary getClusterActiveStep(String clusterId, AwsParamsDto awsParamsDto); @Override Step getClusterStep(String clusterId, String stepId, AwsParamsDto awsParamsDto); @Override AmazonElasticMapReduceClient getEmrClient(AwsParamsDto awsParamsDto); @Override Cluster getEmrClusterById(String clusterId, AwsParamsDto awsParams); @Override String getEmrClusterStatusById(String clusterId, AwsParamsDto awsParams); @Override Instance getEmrMasterInstance(String clusterId, AwsParamsDto awsParams); @Override ListInstanceFleetsResult getListInstanceFleetsResult(String clusterId, AwsParamsDto awsParams); @Override void terminateEmrCluster(String clusterId, boolean overrideTerminationProtection, AwsParamsDto awsParams);  }
@Test public void testGetInstanceGroupConfigs() { final Integer instanceCount = 0; final InstanceDefinitions instanceDefinitions = new InstanceDefinitions(new MasterInstanceDefinition(), new InstanceDefinition(), new InstanceDefinition()); when(emrHelper.isInstanceDefinitionsEmpty(instanceDefinitions)).thenReturn(false); List<InstanceGroupConfig> result = emrDaoImpl.getInstanceGroupConfigs(instanceDefinitions); verify(emrHelper).isInstanceDefinitionsEmpty(instanceDefinitions); verifyNoMoreInteractionsHelper(); assertEquals(3, CollectionUtils.size(result)); assertTrue(result.contains(new InstanceGroupConfig(InstanceRoleType.MASTER, null, instanceCount))); assertTrue(result.contains(new InstanceGroupConfig(InstanceRoleType.CORE, null, instanceCount))); assertTrue(result.contains(new InstanceGroupConfig(InstanceRoleType.TASK, null, instanceCount))); }
@Test public void testGetInstanceGroupConfigsMissingOptionalInstanceDefinitions() { final Integer instanceCount = 0; final InstanceDefinitions instanceDefinitions = new InstanceDefinitions(new MasterInstanceDefinition(), null, null); when(emrHelper.isInstanceDefinitionsEmpty(instanceDefinitions)).thenReturn(false); List<InstanceGroupConfig> result = emrDaoImpl.getInstanceGroupConfigs(instanceDefinitions); verify(emrHelper).isInstanceDefinitionsEmpty(instanceDefinitions); verifyNoMoreInteractionsHelper(); assertEquals(Lists.newArrayList(new InstanceGroupConfig(InstanceRoleType.MASTER, null, instanceCount)), result); }
@Test public void testGetInstanceGroupConfigsWhenInstanceDefinitionsObjectIsEmpty() { final InstanceDefinitions instanceDefinitions = new InstanceDefinitions(); when(emrHelper.isInstanceDefinitionsEmpty(instanceDefinitions)).thenReturn(true); List<InstanceGroupConfig> result = emrDaoImpl.getInstanceGroupConfigs(instanceDefinitions); verify(emrHelper).isInstanceDefinitionsEmpty(instanceDefinitions); verifyNoMoreInteractionsHelper(); assertNull(result); }