private void terminateCluster(String namespace, String clusterDefinitionName, String clusterName) { try { String fullClusterName = emrHelper.buildEmrClusterName(namespace, clusterDefinitionName, clusterName); AwsParamsDto awsParams = emrHelper.getAwsParamsDto(); emrDao.terminateEmrCluster(fullClusterName, true, awsParams); } catch (Exception e) { /* * Ignore the error. * Most of the cases the failures are because the cluster terminated by itself, in which case what this method was trying to achieve has been * accomplished. * If cluster termination legitimately fails, it is not part of this test suite. */ LOGGER.warn(String .format("Failed to terminate cluster namespace = %s, clusterDefinitionName = %s, clusterName = %s", namespace, clusterDefinitionName, clusterName)); } }
@Test public void terminateEmrCluster() throws Exception { String clusterName = "clusterName"; boolean overrideTerminationProtection = false; String clusterId = "clusterId"; ListClustersResult listClustersResult = new ListClustersResult(); listClustersResult.setClusters(new ArrayList<>()); ClusterSummary clusterSummary = new ClusterSummary(); clusterSummary.setId(clusterId); clusterSummary.setName(clusterName); listClustersResult.getClusters().add(clusterSummary); when(mockEmrOperations.listEmrClusters(any(), any())).thenReturn(listClustersResult); emrDao.terminateEmrCluster(clusterId, overrideTerminationProtection, getAwsParamsDto()); // Assert that terminateEmrCluster was called with these parameters ONCE verify(mockEmrOperations).terminateEmrCluster(any(), eq(clusterId), eq(overrideTerminationProtection)); }
.buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName()); verify(mockEmrHelper).getActiveEmrClusterId(emrClusterId, buildEmrClusterNameResult, null); verify(mockEmrDao).terminateEmrCluster(buildEmrClusterNameResult, overrideTerminationProtection, awsParamsDto); verify(mockEmrDao).getEmrClusterStatusById(buildEmrClusterNameResult, awsParamsDto);
emrDao.terminateEmrCluster(clusterId, overrideTerminationProtection, awsParamsDto);
emrDao.terminateEmrCluster(clusterId, overrideTerminationProtection, awsParamsDto);