use of org.kie.kogito.jobs.api.Job in project kogito-runtimes by kiegroup.
the class VertxJobsServiceTest method testGetScheduleTime.
@Test
void testGetScheduleTime(@Mock HttpRequest<Buffer> request, @Mock HttpResponse<Buffer> response) {
when(webClient.get(anyString())).thenReturn(request);
Job job = new Job();
job.setId("123");
job.setExpirationTime(ZonedDateTime.now());
AsyncResult<HttpResponse<Buffer>> asyncResult = mock(AsyncResult.class);
when(asyncResult.succeeded()).thenReturn(true);
when(asyncResult.result()).thenReturn(response);
when(response.statusCode()).thenReturn(200);
when(response.bodyAsJson(any())).thenReturn(job);
doAnswer(invocationOnMock -> {
Handler<AsyncResult<HttpResponse<Buffer>>> handler = invocationOnMock.getArgument(0);
executor.submit(() -> handler.handle(asyncResult));
return null;
}).when(request).send(any());
ZonedDateTime scheduledTime = tested.getScheduledTime("123");
assertThat(scheduledTime).isEqualTo(job.getExpirationTime());
verify(webClient).get("/jobs/123");
}
use of org.kie.kogito.jobs.api.Job in project kogito-runtimes by kiegroup.
the class SpringRestJobsServiceTest method testScheduleProcessInstanceJob.
@Test
void testScheduleProcessInstanceJob() {
when(restTemplate.postForEntity(any(URI.class), any(Job.class), eq(String.class))).thenReturn(ResponseEntity.ok().build());
ProcessInstanceJobDescription processInstanceJobDescription = ProcessInstanceJobDescription.of(new TimerJobId(123l), ExactExpirationTime.now(), "processInstanceId", "processId");
tested.scheduleProcessInstanceJob(processInstanceJobDescription);
ArgumentCaptor<Job> jobArgumentCaptor = forClass(Job.class);
verify(restTemplate).postForEntity(eq(tested.getJobsServiceUri()), jobArgumentCaptor.capture(), eq(String.class));
Job job = jobArgumentCaptor.getValue();
assertThat(job.getId()).isEqualTo(processInstanceJobDescription.id());
}
use of org.kie.kogito.jobs.api.Job in project kogito-runtimes by kiegroup.
the class CreateProcessInstanceJobRequestEventTest method assertFields.
@Override
void assertFields(CreateProcessInstanceJobRequestEvent event) {
super.assertFields(event);
Job job = event.getData();
assertThat(job).isNotNull();
assertThat(job.getId()).isEqualTo(JOB_ID);
assertThat(job.getProcessInstanceId()).isEqualTo(PROCESS_INSTANCE_ID);
assertThat(job.getRootProcessInstanceId()).isEqualTo(ROOT_PROCESS_INSTANCE_ID);
assertThat(job.getProcessId()).isEqualTo(PROCESS_ID);
assertThat(job.getRootProcessId()).isEqualTo(ROOT_PROCESS_ID);
assertThat(job.getNodeInstanceId()).isEqualTo(NODE_INSTANCE_ID);
assertThat(job.getExpirationTime()).isEqualTo(EXPIRATION_TIME);
assertThat(job.getCallbackEndpoint()).isEqualTo(CALLBACK_ENDPOINT);
assertThat(job.getRepeatInterval()).isEqualTo(REPEAT_INTERVAL);
assertThat(job.getRepeatLimit()).isEqualTo(REPEAT_LIMIT);
assertThat(job.getPriority()).isEqualTo(PRIORITY);
}
use of org.kie.kogito.jobs.api.Job in project kogito-runtimes by kiegroup.
the class JobCloudEventDeserializer method deserialize.
public JobCloudEvent<?> deserialize(byte[] data) {
try {
CloudEvent cloudEvent = objectMapper.readValue(data, CloudEvent.class);
CloudEventData cloudEventData = Objects.requireNonNull(cloudEvent.getData(), "JobCloudEvent data field must not be null");
if (cloudEvent.getType().equals(CreateProcessInstanceJobRequestEvent.CREATE_PROCESS_INSTANCE_JOB_REQUEST)) {
Job job = objectMapper.readValue(cloudEventData.toBytes(), Job.class);
return CreateProcessInstanceJobRequestEvent.builder().withValuesFrom(cloudEvent).withContextFrom(cloudEvent).job(job).build();
} else if (cloudEvent.getType().equals(CancelJobRequestEvent.CANCEL_JOB_REQUEST)) {
CancelJobRequestEvent.JobId jobId = objectMapper.readValue(cloudEventData.toBytes(), CancelJobRequestEvent.JobId.class);
return CancelJobRequestEvent.builder().withValuesFrom(cloudEvent).withContextFrom(cloudEvent).jobId(jobId.getId()).build();
}
throw new DeserializationException("Unknown JobCloudEvent event type: " + cloudEvent.getType());
} catch (IOException e) {
throw new DeserializationException("An error was produced during a JobCloudEvent deserialization: " + e.getMessage(), e);
}
}
use of org.kie.kogito.jobs.api.Job in project kogito-apps by kiegroup.
the class BaseMessagingApiIT method cancelJob.
@Test
@Timeout(value = 10, unit = TimeUnit.MINUTES)
protected void cancelJob() {
assertCallbackResource();
// create a job service request event and send it to the jobs service.
ZonedDateTime expiration = ZonedDateTime.now().plusDays(1);
String callback = buildCallbackEndpoint(getCallbackResourceURL(), PROCESS_ID, PROCESS_INSTANCE_ID, NODE_INSTANCE_ID_2);
CreateProcessInstanceJobRequestEvent createJobEvent = CreateProcessInstanceJobRequestEvent.builder().source(URI.create(TEST_SOURCE)).job(new Job(JOB_ID_2, expiration, PRIORITY, callback, PROCESS_INSTANCE_ID, ROOT_PROCESS_INSTANCE_ID, PROCESS_ID, ROOT_PROCESS_ID, REPEAT_INTERVAL, REPEAT_LIMIT, NODE_INSTANCE_ID_2)).processInstanceId(PROCESS_INSTANCE_ID).processId(PROCESS_ID).rootProcessInstanceId(ROOT_PROCESS_INSTANCE_ID).rootProcessId(ROOT_PROCESS_ID).kogitoAddons(KOGITO_ADDONS).build();
String createJobEventJson = serializer.serialize(createJobEvent);
jobEventsEmitter.send(createJobEventJson);
// wait until the job is created or fail if the CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS elapsed.
String jobUrl = "/jobs/" + JOB_ID_2;
waitUntilResult(() -> getJob(jobUrl), response -> expectedJobExists(JOB_ID_2, response), CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS, CALLBACK_EXECUTIONS_QUERY_POLL_INTERVAL_IN_MILLISECONDS);
// create a job service cancel event and send it to the jobs service.
CancelJobRequestEvent cancelJobEvent = CancelJobRequestEvent.builder().source(URI.create(TEST_SOURCE)).jobId(JOB_ID_2).build();
String cancelJobEventJson = serializer.serialize(cancelJobEvent);
jobEventsEmitter.send(cancelJobEventJson);
// wait until the job was canceled or fail if CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS elapsed.
waitUntilResult(() -> getJob(jobUrl), response -> expectedJobDontExists(JOB_ID_2, response), CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS, CALLBACK_EXECUTIONS_QUERY_POLL_INTERVAL_IN_MILLISECONDS);
}
Aggregations