Search in sources :

Example 26 with ExecutorServiceImpl

use of org.jbpm.executor.impl.ExecutorServiceImpl in project jbpm by kiegroup.

the class SLATrackingCommandTest method configureListener.

protected CountDownAsyncJobListener configureListener(int threads) {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(threads);
    ((ExecutorServiceImpl) executorService).addAsyncJobListener(countDownListener);
    return countDownListener;
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl)

Example 27 with ExecutorServiceImpl

use of org.jbpm.executor.impl.ExecutorServiceImpl in project jbpm by kiegroup.

the class JmsAvaiableJobExecutorTest method testAsyncAuditProducerPrioritizedJobs.

@Test
public void testAsyncAuditProducerPrioritizedJobs() throws Exception {
    CountDownAsyncJobListener countDownListener = configureListener(2);
    final List<String> executedJobs = new ArrayList<String>();
    ((ExecutorServiceImpl) executorService).addAsyncJobListener(new AsynchronousJobListener() {

        @Override
        public void beforeJobScheduled(AsynchronousJobEvent event) {
        }

        @Override
        public void beforeJobExecuted(AsynchronousJobEvent event) {
        }

        @Override
        public void beforeJobCancelled(AsynchronousJobEvent event) {
        }

        @Override
        public void afterJobScheduled(AsynchronousJobEvent event) {
        }

        @Override
        public void afterJobExecuted(AsynchronousJobEvent event) {
            executedJobs.add(event.getJob().getKey());
        }

        @Override
        public void afterJobCancelled(AsynchronousJobEvent event) {
        }
    });
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", "low priority");
    ctxCMD.setData("priority", 2);
    CommandContext ctxCMD2 = new CommandContext();
    ctxCMD2.setData("businessKey", "high priority");
    ctxCMD2.setData("priority", 8);
    UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
    ut.begin();
    executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", ctxCMD);
    executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", ctxCMD2);
    ut.commit();
    MessageReceiver receiver = new MessageReceiver();
    receiver.receiveAndProcess(queue, countDownListener);
    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(2, executedRequests.size());
    assertEquals(2, executedJobs.size());
    assertEquals("high priority", executedJobs.get(0));
    assertEquals("low priority", executedJobs.get(1));
}
Also used : UserTransaction(javax.transaction.UserTransaction) AsynchronousJobListener(org.jbpm.executor.AsynchronousJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) CommandContext(org.kie.api.executor.CommandContext) ArrayList(java.util.ArrayList) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) AsynchronousJobEvent(org.jbpm.executor.AsynchronousJobEvent) CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) Test(org.junit.Test)

Example 28 with ExecutorServiceImpl

use of org.jbpm.executor.impl.ExecutorServiceImpl in project jbpm by kiegroup.

the class ExecutorServiceFactory method configure.

private static ExecutorService configure(EntityManagerFactory emf, TransactionalCommandService commandService, ExecutorEventSupportImpl eventSupport) {
    // create instances of executor services
    ExecutorQueryService queryService = new ExecutorQueryServiceImpl(true);
    Executor executor = new ExecutorImpl();
    ExecutorAdminService adminService = new ExecutorRequestAdminServiceImpl();
    ExecutorStoreService storeService = new JPAExecutorStoreService(true);
    ((JPAExecutorStoreService) storeService).setCommandService(commandService);
    ((JPAExecutorStoreService) storeService).setEmf(emf);
    ((JPAExecutorStoreService) storeService).setEventSupport(eventSupport);
    AvailableJobsExecutor jobExecutor = new AvailableJobsExecutor();
    ClassCacheManager classCacheManager = new ClassCacheManager();
    jobExecutor.setClassCacheManager(classCacheManager);
    jobExecutor.setQueryService(queryService);
    jobExecutor.setExecutorStoreService(storeService);
    jobExecutor.setEventSupport(eventSupport);
    jobExecutor.setExecutor(executor);
    ((ExecutorImpl) executor).setExecutorStoreService(storeService);
    ((ExecutorImpl) executor).setEventSupport(eventSupport);
    ((ExecutorImpl) executor).setJobProcessor(jobExecutor);
    ((ExecutorImpl) executor).setTransactionManager(commandService.getTransactionManager());
    // set executor on all instances that requires it
    ((ExecutorQueryServiceImpl) queryService).setCommandService(commandService);
    ((ExecutorRequestAdminServiceImpl) adminService).setCommandService(commandService);
    ((ExecutorRequestAdminServiceImpl) adminService).setExecutor(executor);
    // configure services
    ExecutorService service = new ExecutorServiceImpl(executor);
    ((ExecutorServiceImpl) service).setQueryService(queryService);
    ((ExecutorServiceImpl) service).setExecutor(executor);
    ((ExecutorServiceImpl) service).setAdminService(adminService);
    ((ExecutorServiceImpl) service).setEventSupport(eventSupport);
    return service;
}
Also used : AvailableJobsExecutor(org.jbpm.executor.impl.AvailableJobsExecutor) ClassCacheManager(org.jbpm.executor.impl.ClassCacheManager) AvailableJobsExecutor(org.jbpm.executor.impl.AvailableJobsExecutor) Executor(org.kie.api.executor.Executor) ExecutorAdminService(org.kie.api.executor.ExecutorAdminService) ExecutorRequestAdminServiceImpl(org.jbpm.executor.impl.jpa.ExecutorRequestAdminServiceImpl) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) ExecutorStoreService(org.kie.api.executor.ExecutorStoreService) JPAExecutorStoreService(org.jbpm.executor.impl.jpa.JPAExecutorStoreService) ExecutorImpl(org.jbpm.executor.impl.ExecutorImpl) JPAExecutorStoreService(org.jbpm.executor.impl.jpa.JPAExecutorStoreService) ExecutorService(org.kie.api.executor.ExecutorService) ExecutorQueryServiceImpl(org.jbpm.executor.impl.jpa.ExecutorQueryServiceImpl) ExecutorQueryService(org.kie.api.executor.ExecutorQueryService)

Example 29 with ExecutorServiceImpl

use of org.jbpm.executor.impl.ExecutorServiceImpl in project jbpm by kiegroup.

the class LogCleanupCommandTest method skipTaskLog.

@Ignore
@Test(timeout = 10000)
public void skipTaskLog() throws Exception {
    KieSession kieSession = null;
    List<ProcessInstance> processInstanceList = null;
    try {
        CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
        ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownListener);
        // Generate data
        kieSession = createKSession(LOG_CLEANUP);
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("assigneeName", "krisv");
        processInstanceList = startProcess(kieSession, LOG_CLEANUP_ID, paramMap, 1);
        TaskService taskService = getRuntimeEngine().getTaskService();
        List<Long> taskIdList = taskService.getTasksByProcessInstanceId(processInstanceList.get(0).getId());
        taskService.start(taskIdList.get(0), "krisv");
        taskService.complete(taskIdList.get(0), "krisv", null);
        // Verify presence of data
        Assertions.assertThat(getProcessLogSize(LOG_CLEANUP_ID)).isEqualTo(1);
        Assertions.assertThat(getTaskLogSize(LOG_CLEANUP_ID)).isEqualTo(1);
        Assertions.assertThat(getNodeInstanceLogSize(LOG_CLEANUP_ID)).isPositive();
        Assertions.assertThat(getVariableLogSize(LOG_CLEANUP_ID)).isEqualTo(3);
        // Schedule cleanup job
        scheduleLogCleanup(false, true, false, getTomorrow(), null, LOG_CLEANUP_ID);
        countDownListener.waitTillCompleted();
        // Verify absence of data
        Assertions.assertThat(getProcessLogSize(LOG_CLEANUP_ID)).isZero();
        Assertions.assertThat(getTaskLogSize(LOG_CLEANUP_ID)).isEqualTo(1);
        Assertions.assertThat(getNodeInstanceLogSize(LOG_CLEANUP_ID)).isZero();
        Assertions.assertThat(getVariableLogSize(LOG_CLEANUP_ID)).isZero();
    } finally {
        if (processInstanceList != null) {
            abortProcess(kieSession, processInstanceList);
        }
    }
}
Also used : CountDownAsyncJobListener(org.jbpm.test.listener.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) TaskService(org.kie.api.task.TaskService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with ExecutorServiceImpl

use of org.jbpm.executor.impl.ExecutorServiceImpl in project jbpm by kiegroup.

the class LogCleanupCommandTest method deleteAllLogsOlderThanTomorrowDifferentProcess.

@Test(timeout = 10000)
public void deleteAllLogsOlderThanTomorrowDifferentProcess() throws Exception {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
    ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownListener);
    deleteAllLogsOlderThan(getTomorrow(), HELLO_WORLD_ID, ANOTHER_PROCESS, countDownListener);
    Assertions.assertThat(getProcessLogSize(HELLO_WORLD_ID)).isPositive();
    Assertions.assertThat(getNodeInstanceLogSize(HELLO_WORLD_ID)).isPositive();
}
Also used : CountDownAsyncJobListener(org.jbpm.test.listener.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) Test(org.junit.Test)

Aggregations

ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)32 Test (org.junit.Test)24 KieSession (org.kie.api.runtime.KieSession)18 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)17 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)16 HashMap (java.util.HashMap)13 CountDownAsyncJobListener (org.jbpm.test.listener.CountDownAsyncJobListener)13 QueryContext (org.kie.api.runtime.query.QueryContext)12 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)8 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)8 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)8 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)6 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)6 AsyncWorkItemHandler (org.jbpm.executor.impl.wih.AsyncWorkItemHandler)5 AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)5 RequestInfo (org.kie.api.executor.RequestInfo)5 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)4 CommandContext (org.kie.api.executor.CommandContext)4 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)4 TaskSummary (org.kie.api.task.model.TaskSummary)4