### Question:
KubernetesOperationExecutor extends BaseOperationExecutor { @Override public OperationProgress retrieveOperationProgress() { try { logger.debug("[{}] Getting Pod annotations", executionConfig.getName()); Map<String,String> podAnnotations = follower.getPodAnnotations(); String progressJson = podAnnotations.getOrDefault(KubernetesReporter.REPORT_PROGRESS_ANNOTATION, null); String resultPayload = podAnnotations.get(KubernetesReporter.REPORT_PAYLOAD_ANNOTATION); logger.debug("progressJson [" + progressJson + "], resultPayload [" + resultPayload + ']'); if(progressJson == null) { return defaultFailedOperationProgress; } logger.debug("[{}] Getting operationProgress", executionConfig.getName()); OperationProgress operationProgress = jsonHelper.getObjectFromString(progressJson, OperationProgress.class); logger.debug("[{}] OperationProgress processingState={} processingStateMessage={} percentComplete={}", executionConfig.getName(), operationProgress.getProcessingState(), operationProgress.getProcessingStateMessage(), operationProgress.getPercentComplete()); operationProgress.setOperation(operation.getName()); operationProgress.setResultPayload(resultPayload); if(operationProgress.getProcessingState() == ProcessingState.COMPLETE) isCompleteOperationProgressRetrieved.set(true); return operationProgress; } catch(JsonHelperException je) { logger.error("[{}] {} - Unable to convert progress string to OperationProgress", executionConfig.getName(), operation.getName()); } catch(Exception e) { logger.error("[{}] {} - Unable to pull pod annotation: {}", executionConfig.getName(), operation.getName(), KubernetesReporter.REPORT_PROGRESS_ANNOTATION); } return null; } KubernetesOperationExecutor(PodFollower<PodPushClient> follower, Operation operation, KubeConfig kubeConfig, PodConfig podConfig, ExecutionConfig executionConfig, ExecutorContext executorContext); void setFollower(PodFollower<PodPushClient> follower); void setKubeConfig(KubeConfig kubeConfig); void setPodConfig(PodConfig podConfig); void setExecutionConfig(ExecutionConfig executionConfig); @Override OperationProgress retrieveOperationProgress(); @Override String execute(String payload); KubeConfig getKubeConfig(); PodConfig getPodConfig(); ExecutionConfig getExecutionConfig(); static final int MAX_POD_LOG_LINES; static final int DEFAULT_FAIL_DIAGNOSTIC_LINE_LIMIT; }### Answer:
@Test public void testRetrieveOperationProgressPayloadIssue() { configurePodAnnotations("{>", null); Assert.assertNull(executor.retrieveOperationProgress()); }
@Test public void testRetrieveOperationProgressError() { doThrow(new RuntimeException()).when(mockPodFollower).getPodAnnotations(); Assert.assertNull(executor.retrieveOperationProgress()); }
@Test public void testRetrieveOperationProgressSuccess() { final ProcessingState EXPECTED_PROCESSING_STATE = ProcessingState.EXECUTING; final String EXPECTED_MESSAGE = "Working"; final Double EXPECTED_PERCENT = 50d; configurePodAnnotations(jsonHelper.getJSONString(createOperationProgress(EXPECTED_PROCESSING_STATE, EXPECTED_MESSAGE, EXPECTED_PERCENT)), null); OperationProgress operationProgress = executor.retrieveOperationProgress(); Assert.assertNotNull(operationProgress); Assert.assertEquals(operationProgress.getProcessingState(), EXPECTED_PROCESSING_STATE); Assert.assertEquals(operationProgress.getProcessingStateMessage(), EXPECTED_MESSAGE); Assert.assertEquals(operationProgress.getPercentComplete(), EXPECTED_PERCENT); }