Search in sources :

Example 1 with TransactionLockInterceptor

use of org.drools.persistence.jta.TransactionLockInterceptor in project jbpm by kiegroup.

the class SingletonRuntimeManagerTest method testInterceptorAfterRollback.

@Test
public void testInterceptorAfterRollback() throws Exception {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithRollback.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    ProcessInstance processInstance = ksession.startProcess("UserTaskWithRollback");
    ExecutableRunner commandService = ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
    assertEquals(PersistableRunner.class, commandService.getClass());
    ChainableRunner internalCommandService = ((PersistableRunner) commandService).getChainableRunner();
    assertEquals(ExecutionErrorHandlerInterceptor.class, internalCommandService.getClass());
    internalCommandService = (ChainableRunner) ((ExecutionErrorHandlerInterceptor) internalCommandService).getNext();
    assertEquals(TransactionLockInterceptor.class, internalCommandService.getClass());
    TaskService taskService = runtime.getTaskService();
    List<Long> taskIds = taskService.getTasksByProcessInstanceId(processInstance.getId());
    taskService.start(taskIds.get(0), "john");
    HashMap<String, Object> result = new HashMap<String, Object>();
    result.put("output1", "rollback");
    try {
        // rollback transaction
        taskService.complete(taskIds.get(0), "john", result);
    } catch (WorkflowRuntimeException e) {
    // ignore
    }
    result = new HashMap<String, Object>();
    result.put("output1", "ok");
    // this time, execute normally
    taskService.complete(taskIds.get(0), "john", result);
    internalCommandService = ((PersistableRunner) commandService).getChainableRunner();
    assertEquals(ExecutionErrorHandlerInterceptor.class, internalCommandService.getClass());
    internalCommandService = (ChainableRunner) ((ExecutionErrorHandlerInterceptor) internalCommandService).getNext();
    assertEquals(TransactionLockInterceptor.class, internalCommandService.getClass());
    internalCommandService = (ChainableRunner) ((TransactionLockInterceptor) internalCommandService).getNext();
    assertEquals(OptimisticLockRetryInterceptor.class, internalCommandService.getClass());
    internalCommandService = (ChainableRunner) ((OptimisticLockRetryInterceptor) internalCommandService).getNext();
    assertEquals("org.drools.persistence.PersistableRunner$TransactionInterceptor", internalCommandService.getClass().getName());
    // close manager which will close session maintained by the manager
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) ExecutableRunner(org.kie.api.runtime.ExecutableRunner) PersistableRunner(org.drools.persistence.PersistableRunner) ChainableRunner(org.drools.core.runtime.ChainableRunner) ExecutionErrorHandlerInterceptor(org.jbpm.runtime.manager.impl.error.ExecutionErrorHandlerInterceptor) OptimisticLockRetryInterceptor(org.drools.persistence.jpa.OptimisticLockRetryInterceptor) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) TransactionLockInterceptor(org.drools.persistence.jta.TransactionLockInterceptor) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 2 with TransactionLockInterceptor

use of org.drools.persistence.jta.TransactionLockInterceptor in project jbpm by kiegroup.

the class JPASessionFactory method addInterceptors.

protected void addInterceptors(KieSession ksession) {
    PersistableRunner runner = (PersistableRunner) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
    runner.addInterceptor(new OptimisticLockRetryInterceptor());
    // even though it's added always TransactionLockInterceptor is by default disabled so won't do anything
    runner.addInterceptor(new TransactionLockInterceptor(ksession.getEnvironment()));
    runner.addInterceptor(new ExecutionErrorHandlerInterceptor(ksession.getEnvironment()));
}
Also used : ExecutionErrorHandlerInterceptor(org.jbpm.runtime.manager.impl.error.ExecutionErrorHandlerInterceptor) OptimisticLockRetryInterceptor(org.drools.persistence.jpa.OptimisticLockRetryInterceptor) TransactionLockInterceptor(org.drools.persistence.jta.TransactionLockInterceptor) PersistableRunner(org.drools.persistence.PersistableRunner)

Aggregations

PersistableRunner (org.drools.persistence.PersistableRunner)2 OptimisticLockRetryInterceptor (org.drools.persistence.jpa.OptimisticLockRetryInterceptor)2 TransactionLockInterceptor (org.drools.persistence.jta.TransactionLockInterceptor)2 ExecutionErrorHandlerInterceptor (org.jbpm.runtime.manager.impl.error.ExecutionErrorHandlerInterceptor)2 HashMap (java.util.HashMap)1 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)1 ChainableRunner (org.drools.core.runtime.ChainableRunner)1 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)1 WorkflowRuntimeException (org.jbpm.workflow.instance.WorkflowRuntimeException)1 Test (org.junit.Test)1 ExecutableRunner (org.kie.api.runtime.ExecutableRunner)1 KieSession (org.kie.api.runtime.KieSession)1 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 TaskService (org.kie.api.task.TaskService)1