Search in sources :

Example 11 with Job

use of org.kie.kogito.jobs.api.Job in project kogito-apps by kiegroup.

the class BaseKeycloakJobServiceIT method executeTest.

@Test
void executeTest() throws Exception {
    final String id = "4";
    final Job job = getJob(id);
    createJob(jobToJson(job), getAccessToken("jdoe"), OK_CODE);
    given().pathParam("id", id).when().get(JobResource.JOBS_PATH + "/{id}").then().statusCode(FORBIDDEN_CODE);
    given().auth().oauth2(getAccessToken("alice")).pathParam("id", id).when().get(JobResource.JOBS_PATH + "/{id}").then().statusCode(UNAUTHORIZED_CODE);
    final ScheduledJob scheduledJob = given().auth().oauth2(getAccessToken("jdoe")).pathParam("id", id).when().get(JobResource.JOBS_PATH + "/{id}").then().statusCode(OK_CODE).contentType(ContentType.JSON).assertThat().extract().as(ScheduledJob.class);
    assertEquals(scheduledJob.getId(), job.getId());
    assertEquals(0, scheduledJob.getRetries());
    assertEquals(JobStatus.SCHEDULED, scheduledJob.getStatus());
    assertNotNull(scheduledJob.getScheduledId());
}
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 12 with Job

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");
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ZonedDateTime(java.time.ZonedDateTime) HttpResponse(io.vertx.ext.web.client.HttpResponse) Job(org.kie.kogito.jobs.api.Job) AsyncResult(io.vertx.core.AsyncResult) Test(org.junit.jupiter.api.Test)

Example 13 with Job

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());
}
Also used : ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) Job(org.kie.kogito.jobs.api.Job) TimerJobId(org.kie.kogito.jobs.TimerJobId) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 14 with Job

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);
}
Also used : Job(org.kie.kogito.jobs.api.Job)

Example 15 with Job

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);
    }
}
Also used : CloudEventData(io.cloudevents.CloudEventData) IOException(java.io.IOException) Job(org.kie.kogito.jobs.api.Job) CloudEvent(io.cloudevents.CloudEvent) JobCloudEvent(org.kie.kogito.jobs.api.event.JobCloudEvent)

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