Search in sources :

Example 21 with Job

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);
    });
}
Also used : ScheduledJob(org.kie.kogito.jobs.service.model.ScheduledJob) Job(org.kie.kogito.jobs.api.Job) ScheduledJob(org.kie.kogito.jobs.service.model.ScheduledJob) Test(org.junit.jupiter.api.Test)

Example 22 with Job

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);
}
Also used : ScheduledJob(org.kie.kogito.jobs.service.model.ScheduledJob) Job(org.kie.kogito.jobs.api.Job) ScheduledJob(org.kie.kogito.jobs.service.model.ScheduledJob) Test(org.junit.jupiter.api.Test)

Example 23 with Job

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);
}
Also used : CreateProcessInstanceJobRequestEvent(org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent) ZonedDateTime(java.time.ZonedDateTime) Job(org.kie.kogito.jobs.api.Job) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 24 with Job

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());
}
Also used : CreateProcessInstanceJobRequestEvent(org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent) Job(org.kie.kogito.jobs.api.Job) JobDetails(org.kie.kogito.jobs.service.model.job.JobDetails) JobServiceException(org.kie.kogito.jobs.service.exception.JobServiceException) Test(org.junit.jupiter.api.Test)

Example 25 with Job

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");
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Job(org.kie.kogito.jobs.api.Job) Test(org.junit.jupiter.api.Test)

Aggregations

Job (org.kie.kogito.jobs.api.Job)30 Test (org.junit.jupiter.api.Test)23 ScheduledJob (org.kie.kogito.jobs.service.model.ScheduledJob)13 CreateProcessInstanceJobRequestEvent (org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent)8 ZonedDateTime (java.time.ZonedDateTime)4 JobDetails (org.kie.kogito.jobs.service.model.job.JobDetails)3 Timeout (org.junit.jupiter.api.Timeout)2 ProcessInstanceJobDescription (org.kie.kogito.jobs.ProcessInstanceJobDescription)2 TimerJobId (org.kie.kogito.jobs.TimerJobId)2 JobServiceException (org.kie.kogito.jobs.service.exception.JobServiceException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CloudEvent (io.cloudevents.CloudEvent)1 CloudEventData (io.cloudevents.CloudEventData)1 AsyncResult (io.vertx.core.AsyncResult)1 Handler (io.vertx.core.Handler)1 Buffer (io.vertx.core.buffer.Buffer)1 HttpResponse (io.vertx.ext.web.client.HttpResponse)1 IOException (java.io.IOException)1 URI (java.net.URI)1 JobCallbackResourceDef.buildCallbackPatternJob (org.kie.kogito.jobs.api.JobCallbackResourceDef.buildCallbackPatternJob)1