use of software.amazon.awssdk.iot.iotjobs.model.JobExecutionData in project aws-greengrass-nucleus by aws-greengrass.
the class IotJobsHelperTest method GIVEN_ongoing_job_deployment_with_queued_job_in_cloud_WHEN_cancel_notification_THEN_cancel_current_deployment.
@Test
void GIVEN_ongoing_job_deployment_with_queued_job_in_cloud_WHEN_cancel_notification_THEN_cancel_current_deployment() throws Exception {
iotJobsHelper.postInject();
String TEST_JOB_ID = "jobToBeCancelled";
iotJobsHelper.setDeploymentQueue(mockDeploymentQueue);
when(mockDeploymentQueue.isEmpty()).thenReturn(true);
CompletableFuture<Integer> integerCompletableFuture = CompletableFuture.completedFuture(1);
when(mockIotJobsClientWrapper.SubscribeToJobExecutionsChangedEvents(any(), eq(QualityOfService.AT_LEAST_ONCE), any())).thenReturn(integerCompletableFuture);
when(mockIotJobsClientWrapper.SubscribeToDescribeJobExecutionAccepted(any(), eq(QualityOfService.AT_LEAST_ONCE), any())).thenReturn(integerCompletableFuture);
when(mockIotJobsClientWrapper.SubscribeToDescribeJobExecutionRejected(any(), eq(QualityOfService.AT_LEAST_ONCE), any())).thenReturn(integerCompletableFuture);
DeploymentTaskMetadata mockCurrentDeploymentTaskMetadata = mock(DeploymentTaskMetadata.class);
when(mockCurrentDeploymentTaskMetadata.getDeploymentType()).thenReturn(IOT_JOBS);
when(mockCurrentDeploymentTaskMetadata.isCancellable()).thenReturn(true);
when(mockDeploymentService.getCurrentDeploymentTaskMetadata()).thenReturn(mockCurrentDeploymentTaskMetadata);
iotJobsHelper.subscribeToJobsTopics();
verify(mockIotJobsClientWrapper, times(2)).SubscribeToDescribeJobExecutionAccepted(any(), eq(QualityOfService.AT_LEAST_ONCE), describeJobResponseCaptor.capture());
JobExecutionData jobExecutionData = new JobExecutionData();
jobExecutionData.jobId = TEST_JOB_ID;
jobExecutionData.status = JobStatus.QUEUED;
jobExecutionData.queuedAt = new Timestamp(new Date());
HashMap<String, Object> sampleJobDocument = new HashMap<>();
sampleJobDocument.put("DeploymentId", TEST_JOB_ID);
jobExecutionData.jobDocument = sampleJobDocument;
DescribeJobExecutionResponse describeJobExecutionResponse = new DescribeJobExecutionResponse();
describeJobExecutionResponse.execution = jobExecutionData;
describeJobResponseCaptor.getValue().accept(describeJobExecutionResponse);
ArgumentCaptor<Deployment> deploymentArgumentCaptor = ArgumentCaptor.forClass(Deployment.class);
verify(mockDeploymentQueue, times(2)).offer(deploymentArgumentCaptor.capture());
// First queued deployment should be for cancellation and then next one for next queued job
List<Deployment> actualDeployments = deploymentArgumentCaptor.getAllValues();
assertTrue(actualDeployments.get(0).isCancelled());
assertEquals(IOT_JOBS, actualDeployments.get(0).getDeploymentType());
assertFalse(actualDeployments.get(1).isCancelled());
assertEquals(IOT_JOBS, actualDeployments.get(1).getDeploymentType());
assertEquals(TEST_JOB_ID, actualDeployments.get(1).getId());
}
use of software.amazon.awssdk.iot.iotjobs.model.JobExecutionData in project aws-greengrass-nucleus by aws-greengrass.
the class IotJobsHelperTest method GIVEN_connected_to_iot_WHEN_subscribe_to_jobs_topics_THEN_get_job_description.
@Test
void GIVEN_connected_to_iot_WHEN_subscribe_to_jobs_topics_THEN_get_job_description() throws Exception {
iotJobsHelper.postInject();
String TEST_JOB_ID = "jobToReceive";
iotJobsHelper.setDeploymentQueue(mockDeploymentQueue);
CompletableFuture<Integer> integerCompletableFuture = CompletableFuture.completedFuture(1);
when(mockIotJobsClientWrapper.SubscribeToJobExecutionsChangedEvents(any(), eq(QualityOfService.AT_LEAST_ONCE), any())).thenReturn(integerCompletableFuture);
when(mockIotJobsClientWrapper.SubscribeToDescribeJobExecutionAccepted(any(), eq(QualityOfService.AT_LEAST_ONCE), any())).thenReturn(integerCompletableFuture);
when(mockIotJobsClientWrapper.SubscribeToDescribeJobExecutionRejected(any(), eq(QualityOfService.AT_LEAST_ONCE), any())).thenReturn(integerCompletableFuture);
when(mockDeploymentService.getCurrentDeploymentTaskMetadata()).thenReturn(null);
iotJobsHelper.subscribeToJobsTopics();
verify(mockIotJobsClientWrapper, times(2)).SubscribeToDescribeJobExecutionAccepted(any(), eq(QualityOfService.AT_LEAST_ONCE), describeJobResponseCaptor.capture());
verify(mockIotJobsClientWrapper, times(2)).SubscribeToDescribeJobExecutionRejected(any(), eq(QualityOfService.AT_LEAST_ONCE), rejectedErrorCaptor.capture());
JobExecutionData jobExecutionData = new JobExecutionData();
jobExecutionData.jobId = TEST_JOB_ID;
jobExecutionData.status = JobStatus.QUEUED;
jobExecutionData.queuedAt = new Timestamp(new Date());
HashMap<String, Object> sampleJobDocument = new HashMap<>();
sampleJobDocument.put("DeploymentId", TEST_JOB_ID);
jobExecutionData.jobDocument = sampleJobDocument;
DescribeJobExecutionResponse describeJobExecutionResponse = new DescribeJobExecutionResponse();
describeJobExecutionResponse.execution = jobExecutionData;
describeJobResponseCaptor.getValue().accept(describeJobExecutionResponse);
ArgumentCaptor<Deployment> deploymentArgumentCaptor = ArgumentCaptor.forClass(Deployment.class);
verify(mockDeploymentQueue).offer(deploymentArgumentCaptor.capture());
Deployment actualDeployment = deploymentArgumentCaptor.getValue();
assertEquals(TEST_JOB_ID, actualDeployment.getId());
assertEquals(IOT_JOBS, actualDeployment.getDeploymentType());
assertEquals("{\"DeploymentId\":\"jobToReceive\"}", actualDeployment.getDeploymentDocument());
}
use of software.amazon.awssdk.iot.iotjobs.model.JobExecutionData in project aws-greengrass-nucleus by aws-greengrass.
the class IotJobsHelperTest method getMockJobExecutionData.
private JobExecutionData getMockJobExecutionData(String jobId, Timestamp ts) {
JobExecutionData jobExecutionData = new JobExecutionData();
jobExecutionData.jobId = jobId;
jobExecutionData.status = JobStatus.QUEUED;
jobExecutionData.queuedAt = ts;
HashMap<String, Object> sampleJobDocument = new HashMap<>();
sampleJobDocument.put("DeploymentId", jobId);
jobExecutionData.jobDocument = sampleJobDocument;
return jobExecutionData;
}
Aggregations