EmrHelperServiceImpl implements EmrHelperService { @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) public EmrClusterCreateDto emrCreateClusterAwsSpecificSteps(EmrClusterCreateRequest emrClusterCreateRequest, EmrClusterDefinition emrClusterDefinition, EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrParamsDto emrParamsDto) { return emrCreateClusterAwsSpecificStepsImpl(emrClusterCreateRequest, emrClusterDefinition, emrClusterAlternateKeyDto, emrParamsDto); }  @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) EmrClusterCreateDto emrCreateClusterAwsSpecificSteps(EmrClusterCreateRequest emrClusterCreateRequest, EmrClusterDefinition emrClusterDefinition,
        EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrParamsDto emrParamsDto); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) EmrClusterPreCreateDto emrPreCreateClusterSteps(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrClusterCreateRequest emrClusterCreateRequest); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void logEmrClusterCreation(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrClusterDefinition emrClusterDefinition, String clusterId);  }
@Test public void testEmrCreateClusterAwsSpecificStepsImplNullClusterSummary() { EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition(); emrClusterDefinition.setAccountId(AWS_ACCOUNT_ID); emrClusterDefinition.setInstanceDefinitions(new InstanceDefinitions()); EmrClusterCreateRequest emrClusterCreateRequest = new EmrClusterCreateRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, NO_DRY_RUN, emrClusterDefinition); emrClusterCreateRequest.setEmrClusterDefinitionOverride(emrClusterDefinition); EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = new EmrClusterAlternateKeyDto(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME); EmrParamsDto emrParamsDto = new EmrParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1, NO_S3_TRUSTING_ACCOUNT_STAGING_BUCKET_NAME); when(emrHelper.isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions())).thenReturn(false); when(emrHelper.buildEmrClusterName(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName(), emrClusterAlternateKeyDto.getEmrClusterName())).thenReturn(EMR_CLUSTER_NAME); when(emrDao.getActiveEmrClusterByNameAndAccountId(EMR_CLUSTER_NAME, emrClusterDefinition.getAccountId(), emrParamsDto)).thenReturn(null); when(emrDao.createEmrCluster(EMR_CLUSTER_NAME, emrClusterDefinition, emrParamsDto)).thenReturn(EMR_CLUSTER_ID); when(emrDao.getEmrClusterStatusById(EMR_CLUSTER_ID, emrParamsDto)).thenReturn(EMR_CLUSTER_STATUS); emrHelperServiceImpl.emrCreateClusterAwsSpecificSteps(emrClusterCreateRequest, emrClusterDefinition, emrClusterAlternateKeyDto, emrParamsDto); verify(emrHelper).isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions()); verify(emrPricingHelper).updateEmrClusterDefinitionWithBestPrice(emrClusterAlternateKeyDto, emrClusterDefinition, emrParamsDto); verify(emrHelper).buildEmrClusterName(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName(), emrClusterAlternateKeyDto.getEmrClusterName()); verify(emrDao).getActiveEmrClusterByNameAndAccountId(EMR_CLUSTER_NAME, emrClusterDefinition.getAccountId(), emrParamsDto); verify(emrDao).createEmrCluster(EMR_CLUSTER_NAME, emrClusterDefinition, emrParamsDto); verify(emrDao).getEmrClusterStatusById(EMR_CLUSTER_ID, emrParamsDto); verifyNoMoreInteractionsHelper(); }
@Test public void testEmrCreateClusterAwsSpecificStepsImplDryRun() { EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition(); emrClusterDefinition.setAccountId(AWS_ACCOUNT_ID); emrClusterDefinition.setInstanceDefinitions(new InstanceDefinitions()); EmrClusterCreateRequest emrClusterCreateRequest = new EmrClusterCreateRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, DRY_RUN, emrClusterDefinition); emrClusterCreateRequest.setEmrClusterDefinitionOverride(emrClusterDefinition); EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = new EmrClusterAlternateKeyDto(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME); EmrParamsDto emrParamsDto = new EmrParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1, NO_S3_TRUSTING_ACCOUNT_STAGING_BUCKET_NAME); ClusterSummary clusterSummary = new ClusterSummary(); clusterSummary.setId(EMR_CLUSTER_ID); when(emrHelper.isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions())).thenReturn(false); emrHelperServiceImpl.emrCreateClusterAwsSpecificSteps(emrClusterCreateRequest, emrClusterDefinition, emrClusterAlternateKeyDto, emrParamsDto); verify(emrHelper).isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions()); verify(emrPricingHelper).updateEmrClusterDefinitionWithBestPrice(emrClusterAlternateKeyDto, emrClusterDefinition, emrParamsDto); verifyNoMoreInteractionsHelper(); }
@Test public void testEmrCreateClusterAwsSpecificStepsImplWithAmazonServiceException() { EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition(); emrClusterDefinition.setAccountId(AWS_ACCOUNT_ID); emrClusterDefinition.setInstanceDefinitions(new InstanceDefinitions()); EmrClusterCreateRequest emrClusterCreateRequest = new EmrClusterCreateRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, NO_DRY_RUN, emrClusterDefinition); emrClusterCreateRequest.setEmrClusterDefinitionOverride(emrClusterDefinition); EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = new EmrClusterAlternateKeyDto(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME); EmrParamsDto emrParamsDto = new EmrParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1, NO_S3_TRUSTING_ACCOUNT_STAGING_BUCKET_NAME); AmazonServiceException amazonServiceException = new AmazonServiceException(ERROR_MESSAGE); when(emrHelper.isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions())).thenReturn(false); when(emrHelper.buildEmrClusterName(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName(), emrClusterAlternateKeyDto.getEmrClusterName())).thenReturn(EMR_CLUSTER_NAME); when(emrDao.getActiveEmrClusterByNameAndAccountId(EMR_CLUSTER_NAME, emrClusterDefinition.getAccountId(), emrParamsDto)).thenReturn(null); when(emrDao.createEmrCluster(EMR_CLUSTER_NAME, emrClusterDefinition, emrParamsDto)).thenThrow(amazonServiceException); emrHelperServiceImpl.emrCreateClusterAwsSpecificSteps(emrClusterCreateRequest, emrClusterDefinition, emrClusterAlternateKeyDto, emrParamsDto); verify(emrHelper).isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions()); verify(emrPricingHelper).updateEmrClusterDefinitionWithBestPrice(emrClusterAlternateKeyDto, emrClusterDefinition, emrParamsDto); verify(emrHelper).buildEmrClusterName(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName(), emrClusterAlternateKeyDto.getEmrClusterName()); verify(emrDao).getActiveEmrClusterByNameAndAccountId(EMR_CLUSTER_NAME, emrClusterDefinition.getAccountId(), emrParamsDto); verify(emrDao).createEmrCluster(EMR_CLUSTER_NAME, emrClusterDefinition, emrParamsDto); verify(awsServiceHelper) .handleAmazonException(amazonServiceException, "An Amazon exception occurred while creating EMR cluster with name \"" + EMR_CLUSTER_NAME + "\"."); verifyNoMoreInteractionsHelper(); }