Search in sources :

Example 1 with RequestInfoInstance

use of org.kie.server.api.model.instance.RequestInfoInstance in project droolsjbpm-integration by kiegroup.

the class ProcessServiceIntegrationTest method testStartProcessInstanceWithAsyncNodes.

@Test(timeout = 60 * 1000)
public void testStartProcessInstanceWithAsyncNodes() throws Exception {
    List<String> status = new ArrayList<String>();
    status.add(STATUS.QUEUED.toString());
    status.add(STATUS.RUNNING.toString());
    status.add(STATUS.DONE.toString());
    int originalJobCount = jobServicesClient.getRequestsByStatus(status, 0, 1000).size();
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_ASYNC_SCRIPT);
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId.longValue() > 0);
    try {
        // async node is executed as a job
        List<RequestInfoInstance> jobs = jobServicesClient.getRequestsByStatus(status, 0, 1000);
        assertNotNull(jobs);
        assertEquals(originalJobCount + 1, jobs.size());
        // wait for process instance to be completed
        KieServerSynchronization.waitForProcessInstanceToFinish(processClient, CONTAINER_ID, processInstanceId);
        ProcessInstance pi = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(pi);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, pi.getState().intValue());
    } catch (Exception e) {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        fail(e.getMessage());
    }
}
Also used : RequestInfoInstance(org.kie.server.api.model.instance.RequestInfoInstance) ArrayList(java.util.ArrayList) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test)

Example 2 with RequestInfoInstance

use of org.kie.server.api.model.instance.RequestInfoInstance in project droolsjbpm-integration by kiegroup.

the class JobServiceIntegrationTest method testScheduleSearchByStatusAndCancelJob.

@Test
public void testScheduleSearchByStatusAndCancelJob() {
    int currentNumberOfCancelled = jobServicesClient.getRequestsByStatus(Collections.singletonList(STATUS.CANCELLED.toString()), 0, 100).size();
    Calendar tomorrow = Calendar.getInstance();
    tomorrow.add(Calendar.DATE, 1);
    JobRequestInstance jobRequestInstance = createJobRequestInstance();
    jobRequestInstance.setScheduledDate(tomorrow.getTime());
    Long jobId = jobServicesClient.scheduleRequest(jobRequestInstance);
    assertNotNull(jobId);
    assertTrue(jobId.longValue() > 0);
    List<String> status = new ArrayList<String>();
    status.add(STATUS.QUEUED.toString());
    List<RequestInfoInstance> result = jobServicesClient.getRequestsByStatus(status, 0, 100);
    assertNotNull(result);
    assertEquals(1, result.size());
    RequestInfoInstance jobRequest = result.get(0);
    RequestInfoInstance expected = createExpectedRequestInfoInstance(jobId, STATUS.QUEUED);
    assertRequestInfoInstance(expected, jobRequest);
    assertNotNull(jobRequest.getScheduledDate());
    jobServicesClient.cancelRequest(jobId);
    result = jobServicesClient.getRequestsByStatus(status, 0, 100);
    assertNotNull(result);
    assertEquals(0, result.size());
    // clear status to search only for canceled
    status.clear();
    status.add(STATUS.CANCELLED.toString());
    result = jobServicesClient.getRequestsByStatus(status, 0, 100);
    assertNotNull(result);
    assertEquals(1 + currentNumberOfCancelled, result.size());
}
Also used : JobRequestInstance(org.kie.server.api.model.instance.JobRequestInstance) Calendar(java.util.Calendar) RequestInfoInstance(org.kie.server.api.model.instance.RequestInfoInstance) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with RequestInfoInstance

use of org.kie.server.api.model.instance.RequestInfoInstance in project droolsjbpm-integration by kiegroup.

the class JobServiceIntegrationTest method runProcessAutoAckErrorCommand.

private void runProcessAutoAckErrorCommand() throws Exception {
    Map<String, Object> data = new HashMap<>();
    data.put("SingleRun", "true");
    data.put("EmfName", "org.jbpm.domain");
    JobRequestInstance jobRequestInstance = new JobRequestInstance();
    jobRequestInstance.setCommand(PROCESS_AUTO_ACK_ERROR_COMMAND);
    jobRequestInstance.setData(data);
    Long jobId = jobServicesClient.scheduleRequest(jobRequestInstance);
    assertNotNull(jobId);
    RequestInfoInstance jobRequest = jobServicesClient.getRequestById(jobId, false, false);
    assertNotNull(jobRequest);
    KieServerSynchronization.waitForJobToFinish(jobServicesClient, jobId);
}
Also used : JobRequestInstance(org.kie.server.api.model.instance.JobRequestInstance) HashMap(java.util.HashMap) RequestInfoInstance(org.kie.server.api.model.instance.RequestInfoInstance)

Example 4 with RequestInfoInstance

use of org.kie.server.api.model.instance.RequestInfoInstance in project droolsjbpm-integration by kiegroup.

the class JobServiceIntegrationTest method testScheduleViewAndCancelJob.

@Test
public void testScheduleViewAndCancelJob() {
    Calendar tomorrow = Calendar.getInstance();
    tomorrow.add(Calendar.DATE, 1);
    JobRequestInstance jobRequestInstance = createJobRequestInstance();
    jobRequestInstance.setScheduledDate(tomorrow.getTime());
    Long jobId = jobServicesClient.scheduleRequest(jobRequestInstance);
    assertNotNull(jobId);
    assertTrue(jobId.longValue() > 0);
    RequestInfoInstance jobRequest = jobServicesClient.getRequestById(jobId, false, false);
    RequestInfoInstance expected = createExpectedRequestInfoInstance(jobId, STATUS.QUEUED);
    assertRequestInfoInstance(expected, jobRequest);
    assertNotNull(jobRequest.getScheduledDate());
    jobServicesClient.cancelRequest(jobId);
    jobRequest = jobServicesClient.getRequestById(jobId, false, false);
    expected.setStatus(STATUS.CANCELLED.toString());
    assertRequestInfoInstance(expected, jobRequest);
}
Also used : JobRequestInstance(org.kie.server.api.model.instance.JobRequestInstance) Calendar(java.util.Calendar) RequestInfoInstance(org.kie.server.api.model.instance.RequestInfoInstance) Test(org.junit.Test)

Example 5 with RequestInfoInstance

use of org.kie.server.api.model.instance.RequestInfoInstance in project droolsjbpm-integration by kiegroup.

the class JobServiceIntegrationTest method testScheduleAndRunJobWithoutData.

@Test
public void testScheduleAndRunJobWithoutData() throws Exception {
    JobRequestInstance jobRequestInstance = new JobRequestInstance();
    jobRequestInstance.setCommand(PRINT_OUT_COMMAND);
    Long jobId = jobServicesClient.scheduleRequest(jobRequestInstance);
    assertNotNull(jobId);
    assertTrue(jobId.longValue() > 0);
    RequestInfoInstance jobRequest = jobServicesClient.getRequestById(jobId, false, false);
    assertNotNull(jobRequest);
    assertEquals(jobId, jobRequest.getId());
    assertThat(jobRequest.getStatus(), anyOf(equalTo(STATUS.QUEUED.toString()), equalTo(STATUS.RUNNING.toString()), equalTo(STATUS.DONE.toString())));
    assertEquals(PRINT_OUT_COMMAND, jobRequest.getCommandName());
    KieServerSynchronization.waitForJobToFinish(jobServicesClient, jobId);
    jobRequest = jobServicesClient.getRequestById(jobId, false, false);
    assertNotNull(jobRequest);
    assertEquals(jobId, jobRequest.getId());
    assertEquals(STATUS.DONE.toString(), jobRequest.getStatus());
    assertEquals(PRINT_OUT_COMMAND, jobRequest.getCommandName());
}
Also used : JobRequestInstance(org.kie.server.api.model.instance.JobRequestInstance) RequestInfoInstance(org.kie.server.api.model.instance.RequestInfoInstance) Test(org.junit.Test)

Aggregations

RequestInfoInstance (org.kie.server.api.model.instance.RequestInfoInstance)20 Test (org.junit.Test)14 JobRequestInstance (org.kie.server.api.model.instance.JobRequestInstance)13 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)5 Calendar (java.util.Calendar)5 RequestInfo (org.kie.api.executor.RequestInfo)3 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)2 Before (org.junit.Before)2 Category (org.junit.experimental.categories.Category)2 KieServicesException (org.kie.server.api.exception.KieServicesException)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 AnyOf.anyOf (org.hamcrest.core.AnyOf.anyOf)1 IsEqual.equalTo (org.hamcrest.core.IsEqual.equalTo)1 Assert.assertEquals (org.junit.Assert.assertEquals)1