use of org.kie.kogito.jobs.api.Job in project kogito-apps by kiegroup.
the class BaseJobResourceIT method cancelRunningNonPeriodicJobTest.
@Test
void cancelRunningNonPeriodicJobTest() throws Exception {
final String id = UUID.randomUUID().toString();
final Job job = getJob(id, DateUtil.now().plus(10, ChronoUnit.SECONDS));
create(jobToJson(job));
assertGetScheduledJob(id);
// guarantee the job is scheduled on vertx
await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> {
// canceled the running job
ScheduledJob scheduledJob = assertCancelScheduledJob(id);
// assert the job was deleted from the api perspective
assertJobNotFound(id);
// ensure the job was indeed canceled on vertx
assertJobNotScheduledOnVertx(scheduledJob);
});
}
use of org.kie.kogito.jobs.api.Job in project kogito-apps by kiegroup.
the class BaseKeycloakJobServiceIT method deleteAfterCreate.
@Test
void deleteAfterCreate() throws Exception {
final String id = "2";
final Job job = getJob(id);
createJob(jobToJson(job), getAccessToken("alice"), UNAUTHORIZED_CODE);
createJob(jobToJson(job), "", FORBIDDEN_CODE);
createJob(jobToJson(job), getAccessToken("jdoe"), OK_CODE);
given().pathParam("id", id).when().delete(JobResource.JOBS_PATH + "/{id}").then().statusCode(FORBIDDEN_CODE);
given().auth().oauth2(getAccessToken("alice")).pathParam("id", id).when().delete(JobResource.JOBS_PATH + "/{id}").then().statusCode(UNAUTHORIZED_CODE);
final ScheduledJob response = given().auth().oauth2(getAccessToken("jdoe")).pathParam("id", id).when().delete(JobResource.JOBS_PATH + "/{id}").then().statusCode(OK_CODE).contentType(ContentType.JSON).extract().as(ScheduledJob.class);
assertEquals(job, response);
}
use of org.kie.kogito.jobs.api.Job in project kogito-apps by kiegroup.
the class BaseMessagingApiIT method createJob.
@Test
@Timeout(value = 10, unit = TimeUnit.MINUTES)
protected void createJob() {
assertCallbackResource();
// create a job service request event and send it to the jobs service.
ZonedDateTime expiration = ZonedDateTime.now().plusSeconds(10);
String callback = buildCallbackEndpoint(getCallbackResourceURL(), PROCESS_ID, PROCESS_INSTANCE_ID, NODE_INSTANCE_ID_1);
CreateProcessInstanceJobRequestEvent event = CreateProcessInstanceJobRequestEvent.builder().source(URI.create(TEST_SOURCE)).job(new Job(JOB_ID_1, expiration, PRIORITY, callback, PROCESS_INSTANCE_ID, ROOT_PROCESS_INSTANCE_ID, PROCESS_ID, ROOT_PROCESS_ID, REPEAT_INTERVAL, REPEAT_LIMIT, NODE_INSTANCE_ID_1)).processInstanceId(PROCESS_INSTANCE_ID).processId(PROCESS_ID).rootProcessInstanceId(ROOT_PROCESS_INSTANCE_ID).rootProcessId(ROOT_PROCESS_ID).kogitoAddons(KOGITO_ADDONS).build();
String jsonEvent = serializer.serialize(event);
jobEventsEmitter.send(jsonEvent);
// wait until we can verify that the job was executed or fail if the CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS
// elapsed.
waitUntilResult(() -> getJobCallbackExecutions(NODE_INSTANCE_ID_1), executions -> Objects.equals(executions, "2"), CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS, CALLBACK_EXECUTIONS_QUERY_POLL_INTERVAL_IN_MILLISECONDS);
}
use of org.kie.kogito.jobs.api.Job in project kogito-apps by kiegroup.
the class ReactiveMessagingEventConsumerTest method onCreateProcessInstanceJobWithJobScheduleError.
@Test
void onCreateProcessInstanceJobWithJobScheduleError() {
Job job = new Job();
job.setId(JOB_ID);
CreateProcessInstanceJobRequestEvent event = CreateProcessInstanceJobRequestEvent.builder().job(job).build();
doReturn(event).when(message).getPayload();
JobDetails existingJob = JobDetails.builder().id(JOB_ID).status(JobStatus.SCHEDULED).build();
CompletionStage<JobDetails> queryJobStage = CompletableFuture.completedStage(existingJob);
doReturn(queryJobStage).when(jobRepository).get(JOB_ID);
CompletionStage<JobDetails> createJobFailingStage = CompletableFuture.failedStage(new Exception(INTERNAL_ERROR));
Publisher<JobDetails> schedulePublisher = ReactiveStreams.fromCompletionStage(createJobFailingStage).buildRs();
doReturn(schedulePublisher).when(scheduler).schedule(any());
executeFailedExecution(INTERNAL_ERROR);
verify(scheduler).schedule(any());
}
use of org.kie.kogito.jobs.api.Job in project kogito-runtimes by kiegroup.
the class SpringRestJobsServiceTest method testGetScheduleTime.
@Test
void testGetScheduleTime() {
Job job = new Job();
job.setId("123");
job.setExpirationTime(ZonedDateTime.now());
when(restTemplate.getForObject(any(), any(), anyString())).thenReturn(job);
ZonedDateTime scheduledTime = tested.getScheduledTime("123");
assertThat(scheduledTime).isEqualTo(job.getExpirationTime());
verify(restTemplate).getForObject(tested.getJobsServiceUri() + "/{id}", Job.class, "123");
}
Aggregations