EmrHelperServiceImpl implements EmrHelperService { EmrClusterCreateDto emrCreateClusterAwsSpecificStepsImpl(EmrClusterCreateRequest request, EmrClusterDefinition emrClusterDefinition, EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrParamsDto emrParamsDto) { if (!emrHelper.isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions())) { emrPricingHelper.updateEmrClusterDefinitionWithBestPrice(emrClusterAlternateKeyDto, emrClusterDefinition, emrParamsDto); } else { updateEmrClusterDefinitionWithValidInstanceFleetSubnets(emrClusterAlternateKeyDto, emrClusterDefinition, emrParamsDto); } String clusterId = null; Boolean emrClusterAlreadyExists = null; Boolean emrClusterCreated = null; String emrClusterStatus = null; if (!Boolean.TRUE.equals(request.isDryRun())) { String clusterName = emrHelper .buildEmrClusterName(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName(), emrClusterAlternateKeyDto.getEmrClusterName()); try { synchronized (this) { LOGGER.info("Entering synchronized block."); ClusterSummary clusterSummary = emrDao.getActiveEmrClusterByNameAndAccountId(clusterName, emrClusterDefinition.getAccountId(), emrParamsDto); if (clusterSummary == null) { clusterId = emrDao.createEmrCluster(clusterName, emrClusterDefinition, emrParamsDto); emrClusterCreated = true; emrClusterStatus = emrDao.getEmrClusterStatusById(clusterId, emrParamsDto); } else { clusterId = clusterSummary.getId(); emrClusterCreated = false; emrClusterAlreadyExists = true; emrClusterStatus = clusterSummary.getStatus().getState(); } LOGGER.info("Exiting synchronized block."); } } catch (AmazonServiceException ex) { awsServiceHelper.handleAmazonException(ex, "An Amazon exception occurred while creating EMR cluster with name \"" + clusterName + "\"."); } } else { emrClusterCreated = false; } return new EmrClusterCreateDto(clusterId, emrClusterAlreadyExists, emrClusterCreated, emrClusterStatus); }  @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 testEmrCreateClusterAwsSpecificStepsImpl() { 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); ClusterSummary clusterSummary = new ClusterSummary(); clusterSummary.setId(EMR_CLUSTER_ID); clusterSummary.setStatus(new ClusterStatus().withState(EMR_CLUSTER_STATUS)); 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(clusterSummary); 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); verifyNoMoreInteractionsHelper(); }