Search in sources :

Example 51 with RequestInfo

use of org.kie.api.executor.RequestInfo in project jbpm by kiegroup.

the class BasicExecutorIntegrationTest method addAnotherCallbackTest.

@Test
public void addAnotherCallbackTest() throws InterruptedException {
    CommandContext commandContext = new CommandContext();
    commandContext.setData("businessKey", UUID.randomUUID().toString());
    cachedEntities.put((String) commandContext.getData("businessKey"), new AtomicLong(1));
    commandContext.setData("callbacks", "org.jbpm.executor.ejb.impl.test.SimpleIncrementCallback");
    executorService.scheduleRequest("org.jbpm.executor.ejb.impl.test.AddAnotherCallbackCommand", commandContext);
    Thread.sleep(10000);
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(0, inErrorRequests.size());
    List<RequestInfo> queuedRequests = executorService.getQueuedRequests(new QueryContext());
    assertEquals(0, queuedRequests.size());
    List<RequestInfo> executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(1, executedRequests.size());
    assertEquals(2, ((AtomicLong) cachedEntities.get((String) commandContext.getData("businessKey"))).longValue());
    ExecutionResults results = null;
    byte[] responseData = executedRequests.get(0).getResponseData();
    ObjectInputStream in = null;
    try {
        in = new ObjectInputStream(new ByteArrayInputStream(responseData));
        results = (ExecutionResults) in.readObject();
    } catch (Exception e) {
        logger.warn("Exception while serializing context data", e);
        return;
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    String result = (String) results.getData("custom");
    assertNotNull(result);
    assertEquals("custom callback invoked", result);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CommandContext(org.kie.api.executor.CommandContext) ByteArrayInputStream(java.io.ByteArrayInputStream) ExecutionResults(org.kie.api.executor.ExecutionResults) QueryContext(org.kie.api.runtime.query.QueryContext) IOException(java.io.IOException) RequestInfo(org.kie.api.executor.RequestInfo) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 52 with RequestInfo

use of org.kie.api.executor.RequestInfo in project jbpm by kiegroup.

the class BasicExecutorIntegrationTest method executorExceptionTrimmingTest.

@Test
public void executorExceptionTrimmingTest() throws InterruptedException {
    System.setProperty("org.kie.executor.msg.length", "10");
    System.setProperty("org.kie.executor.stacktrace.length", "20");
    CommandContext commandContext = new CommandContext();
    commandContext.setData("businessKey", UUID.randomUUID().toString());
    cachedEntities.put((String) commandContext.getData("businessKey"), new AtomicLong(1));
    commandContext.setData("callbacks", "org.jbpm.executor.ejb.impl.test.SimpleIncrementCallback");
    commandContext.setData("retries", 0);
    executorService.scheduleRequest("org.jbpm.executor.ejb.impl.test.ThrowExceptionCommand", commandContext);
    logger.info("{} Sleeping for 10 secs", System.currentTimeMillis());
    Thread.sleep(10000);
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(1, inErrorRequests.size());
    logger.info("Error: {}", inErrorRequests.get(0));
    List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
    logger.info("Errors: {}", errors);
    assertEquals(1, errors.size());
    ErrorInfo error = errors.get(0);
    assertEquals(10, error.getMessage().length());
    assertEquals(20, error.getStacktrace().length());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CommandContext(org.kie.api.executor.CommandContext) ErrorInfo(org.kie.api.executor.ErrorInfo) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 53 with RequestInfo

use of org.kie.api.executor.RequestInfo in project jbpm by kiegroup.

the class BasicExecutorIntegrationTest method cancelRequestWithSearchByCommandTest.

@Test
public void cancelRequestWithSearchByCommandTest() throws InterruptedException {
    CommandContext ctxCMD = new CommandContext();
    String businessKey = UUID.randomUUID().toString();
    ctxCMD.setData("businessKey", businessKey);
    Date futureDate = new Date(System.currentTimeMillis() + 5000);
    Long requestId = executorService.scheduleRequest("org.jbpm.executor.test.CustomCommand", futureDate, ctxCMD);
    List<RequestInfo> requests = executorService.getRequestsByCommand("org.jbpm.executor.test.CustomCommand", new QueryContext());
    assertNotNull(requests);
    assertEquals(1, requests.size());
    assertEquals(requestId, requests.get(0).getId());
    // cancel the task immediately
    executorService.cancelRequest(requestId);
    List<RequestInfo> cancelledRequests = executorService.getCancelledRequests(new QueryContext());
    assertEquals(1, cancelledRequests.size());
}
Also used : CommandContext(org.kie.api.executor.CommandContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Date(java.util.Date) Test(org.junit.Test)

Example 54 with RequestInfo

use of org.kie.api.executor.RequestInfo in project jbpm by kiegroup.

the class BasicExecutorIntegrationTest method callbackTest.

@Test
public void callbackTest() throws InterruptedException {
    CommandContext commandContext = new CommandContext();
    commandContext.setData("businessKey", UUID.randomUUID().toString());
    cachedEntities.put((String) commandContext.getData("businessKey"), new AtomicLong(1));
    commandContext.setData("callbacks", "org.jbpm.executor.ejb.impl.test.SimpleIncrementCallback");
    executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", commandContext);
    Thread.sleep(10000);
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(0, inErrorRequests.size());
    List<RequestInfo> queuedRequests = executorService.getQueuedRequests(new QueryContext());
    assertEquals(0, queuedRequests.size());
    List<RequestInfo> executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(1, executedRequests.size());
    assertEquals(2, ((AtomicLong) cachedEntities.get((String) commandContext.getData("businessKey"))).longValue());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CommandContext(org.kie.api.executor.CommandContext) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Aggregations

RequestInfo (org.kie.api.executor.RequestInfo)54 QueryContext (org.kie.api.runtime.query.QueryContext)53 Test (org.junit.Test)51 CommandContext (org.kie.api.executor.CommandContext)39 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)25 AtomicLong (java.util.concurrent.atomic.AtomicLong)22 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)13 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)13 KieSession (org.kie.api.runtime.KieSession)13 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)13 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)13 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)13 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)11 Date (java.util.Date)9 ErrorInfo (org.kie.api.executor.ErrorInfo)9 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)8 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)8 HashMap (java.util.HashMap)7 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener)6 ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)5