@Override public StepSummary getClusterActiveStep(String clusterId, AwsParamsDto awsParamsDto) { ListStepsRequest listStepsRequest = new ListStepsRequest().withClusterId(clusterId).withStepStates(StepState.RUNNING); List<StepSummary> stepSummaryList = emrOperations.listStepsRequest(getEmrClient(awsParamsDto), listStepsRequest).getSteps(); return !stepSummaryList.isEmpty() ? stepSummaryList.get(0) : null; }
@Override public StepSummary getClusterActiveStep(String clusterId, AwsParamsDto awsParamsDto) { ListStepsRequest listStepsRequest = new ListStepsRequest().withClusterId(clusterId).withStepStates(StepState.RUNNING); List<StepSummary> stepSummaryList = emrOperations.listStepsRequest(getEmrClient(awsParamsDto), listStepsRequest).getSteps(); return !stepSummaryList.isEmpty() ? stepSummaryList.get(0) : null; }
@Test public void getClusterActiveStepAssertReturnNullWhenStepListIsEmpty() throws Exception { String clusterId = "clusterId"; when(mockEmrOperations.listStepsRequest(any(), any())).thenReturn(new ListStepsResult()); assertNull(emrDao.getClusterActiveStep(clusterId, getAwsParamsDto())); }
@Test public void getClusterActiveStepAssertCallListStepsAndReturnStepSummary() throws Exception { String clusterId = "clusterId"; StepSummary expectedStepSummary = new StepSummary(); when(mockEmrOperations.listStepsRequest(any(), any())).then(new Answer<ListStepsResult>() { @Override public ListStepsResult answer(InvocationOnMock invocation) throws Throwable { ListStepsRequest listStepsRequest = invocation.getArgument(1); assertEquals(clusterId, listStepsRequest.getClusterId()); assertEquals(1, listStepsRequest.getStepStates().size()); assertEquals(StepState.RUNNING.toString(), listStepsRequest.getStepStates().get(0)); ListStepsResult listStepsResult = new ListStepsResult(); listStepsResult.setSteps(new ArrayList<>()); listStepsResult.getSteps().add(expectedStepSummary); return listStepsResult; } }); assertEquals(expectedStepSummary, emrDao.getClusterActiveStep(clusterId, getAwsParamsDto())); }
@Test public void getClusterActiveStepAssertReturnFirstWhenStepListSizeGt1() throws Exception { String clusterId = "clusterId"; StepSummary expectedStepSummary = new StepSummary(); expectedStepSummary.setId("expected"); ListStepsResult listStepsResult = new ListStepsResult(); listStepsResult.setSteps(Arrays.asList(expectedStepSummary, new StepSummary())); when(mockEmrOperations.listStepsRequest(any(), any())).thenReturn(listStepsResult); assertEquals(expectedStepSummary, emrDao.getClusterActiveStep(clusterId, getAwsParamsDto())); }
ListStepsResult listStepsResult = emrOperations.listStepsRequest(null, listStepsRequest); List<StepSummary> addedSteps = listStepsResult.getSteps();