Search in sources :

Example 26 with ProcessInstanceLog

use of org.kie.api.runtime.manager.audit.ProcessInstanceLog in project jbpm by kiegroup.

the class MigrationManagerTest method testMigrateUserTaskProcessInstanceDifferentRuntimeManagers.

@Test
public void testMigrateUserTaskProcessInstanceDifferentRuntimeManagers() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("migration/v1/BPMN2-UserTask-v1.bpmn2"), ResourceType.BPMN2).get();
    managerV1 = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment, DEPLOYMENT_ID_V1);
    RuntimeEnvironment environment2 = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("migration/v2/BPMN2-UserTask-v2.bpmn2"), ResourceType.BPMN2).get();
    managerV2 = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment2, DEPLOYMENT_ID_V2);
    assertNotNull(managerV1);
    assertNotNull(managerV2);
    RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance pi1 = ksession.startProcess(PROCESS_ID_V1);
    assertNotNull(pi1);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    JPAAuditLogService auditService = new JPAAuditLogService(emf);
    ProcessInstanceLog log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(PROCESS_ID_V1, log.getProcessId());
    assertEquals(PROCESS_NAME_V1, log.getProcessName());
    assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
    TaskService taskService = runtime.getTaskService();
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner(USER_JOHN, "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    assertNotNull(task);
    assertEquals(PROCESS_ID_V1, task.getProcessId());
    assertEquals(DEPLOYMENT_ID_V1, task.getDeploymentId());
    assertEquals(TASK_NAME_V1, task.getName());
    managerV1.disposeRuntimeEngine(runtime);
    MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, PROCESS_ID_V2);
    MigrationManager migrationManager = new MigrationManager(migrationSpec);
    try {
        migrationManager.migrate();
    } catch (MigrationException e) {
        assertEquals("Source (org.jbpm.runtime.manager.impl.SingletonRuntimeManager) and target (org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager) deployments are of different type (they represent different runtime strategies)", e.getMessage());
    }
    runtime = managerV1.getRuntimeEngine(EmptyContext.get());
    ksession = runtime.getKieSession();
    assertNotNull(ksession);
    auditService = new JPAAuditLogService(emf);
    log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(PROCESS_ID_V1, log.getProcessId());
    assertEquals(PROCESS_NAME_V1, log.getProcessName());
    assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
    taskService = runtime.getTaskService();
    tasks = taskService.getTasksAssignedAsPotentialOwner(USER_JOHN, "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    task = tasks.get(0);
    assertNotNull(task);
    assertEquals(PROCESS_ID_V1, task.getProcessId());
    assertEquals(DEPLOYMENT_ID_V1, task.getDeploymentId());
    assertEquals(TASK_NAME_V1, task.getName());
    managerV1.disposeRuntimeEngine(runtime);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 27 with ProcessInstanceLog

use of org.kie.api.runtime.manager.audit.ProcessInstanceLog in project jbpm by kiegroup.

the class MigrationManagerTest method testMigrateUserTaskProcessInstanceWithRollback.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testMigrateUserTaskProcessInstanceWithRollback() {
    createRuntimeManagers("migration/v1/BPMN2-UserTask-v1.bpmn2", "migration/v2/BPMN2-UserTask-v2.bpmn2");
    assertNotNull(managerV1);
    assertNotNull(managerV2);
    RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance pi1 = ksession.startProcess(PROCESS_ID_V1);
    assertNotNull(pi1);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    managerV1.disposeRuntimeEngine(runtime);
    MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, PROCESS_ID_V2);
    MigrationManager migrationManager = new MigrationManager(migrationSpec);
    MigrationReport report = null;
    try {
        // explicitly without generic to cause error (class cast) in migration process to test rollback
        Map erronousMapping = Collections.singletonMap("_2", 2);
        migrationManager.migrate(erronousMapping);
    } catch (MigrationException e) {
        report = e.getReport();
    }
    assertNotNull(report);
    assertFalse(report.isSuccessful());
    JPAAuditLogService auditService = new JPAAuditLogService(emf);
    ProcessInstanceLog log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(PROCESS_ID_V1, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
    auditService.dispose();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Map(java.util.Map) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 28 with ProcessInstanceLog

use of org.kie.api.runtime.manager.audit.ProcessInstanceLog in project jbpm by kiegroup.

the class TimerMigrationManagerTest method testMigrateEventSubprocessTimerProcessInstance.

@Test(timeout = 10000)
public void testMigrateEventSubprocessTimerProcessInstance() throws Exception {
    NodeLeftCountDownProcessEventListener countdownListener = new NodeLeftCountDownProcessEventListener("Script Task 1 V2", 1);
    createRuntimeManagers("migration/v1/BPMN2-EventSubprocessTimer-v1.bpmn2", "migration/v2/BPMN2-EventSubprocessTimer-v2.bpmn2", countdownListener);
    assertNotNull(managerV1);
    assertNotNull(managerV2);
    RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance pi1 = ksession.startProcess(EVENT_SUBPROCESS_TIMER_ID_V1);
    assertNotNull(pi1);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    JPAAuditLogService auditService = new JPAAuditLogService(emf);
    ProcessInstanceLog log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(EVENT_SUBPROCESS_TIMER_ID_V1, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
    managerV1.disposeRuntimeEngine(runtime);
    MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, EVENT_SUBPROCESS_TIMER_ID_V2);
    MigrationManager migrationManager = new MigrationManager(migrationSpec);
    MigrationReport report = migrationManager.migrate();
    assertNotNull(report);
    assertTrue(report.isSuccessful());
    log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(EVENT_SUBPROCESS_TIMER_ID_V2, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
    assertEquals(ProcessInstance.STATE_ACTIVE, log.getStatus().intValue());
    // wait till timer fires
    countdownListener.waitTillCompleted();
    log = auditService.findProcessInstance(pi1.getId());
    auditService.dispose();
    assertNotNull(log);
    assertEquals(EVENT_SUBPROCESS_TIMER_ID_V2, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
    assertEquals(ProcessInstance.STATE_ABORTED, log.getStatus().intValue());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 29 with ProcessInstanceLog

use of org.kie.api.runtime.manager.audit.ProcessInstanceLog in project jbpm by kiegroup.

the class TimerMigrationManagerTest method testMigrateTimerProcessInstanceRollback.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test(timeout = 10000)
public void testMigrateTimerProcessInstanceRollback() throws Exception {
    NodeLeftCountDownProcessEventListener countdownListener = new NodeLeftCountDownProcessEventListener("Event", 1);
    createRuntimeManagers("migration/v1/BPMN2-Timer-v1.bpmn2", "migration/v2/BPMN2-Timer-v2.bpmn2", countdownListener);
    assertNotNull(managerV1);
    assertNotNull(managerV2);
    RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance pi1 = ksession.startProcess(TIMER_ID_V1);
    assertNotNull(pi1);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    JPAAuditLogService auditService = new JPAAuditLogService(emf);
    ProcessInstanceLog log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(TIMER_ID_V1, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
    managerV1.disposeRuntimeEngine(runtime);
    MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, TIMER_ID_V2);
    MigrationManager migrationManager = new MigrationManager(migrationSpec);
    MigrationReport report = null;
    try {
        // explicitly without generic to cause error (class cast) in migration process to test rollback
        Map erronousMapping = Collections.singletonMap("_3", 3);
        migrationManager.migrate(erronousMapping);
    } catch (MigrationException e) {
        report = e.getReport();
    }
    assertNotNull(report);
    assertFalse(report.isSuccessful());
    log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(TIMER_ID_V1, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
    assertEquals(ProcessInstance.STATE_ACTIVE, log.getStatus().intValue());
    // wait till timer fires
    countdownListener.waitTillCompleted();
    log = auditService.findProcessInstance(pi1.getId());
    auditService.dispose();
    assertNotNull(log);
    assertEquals(TIMER_ID_V1, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
    assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Map(java.util.Map) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 30 with ProcessInstanceLog

use of org.kie.api.runtime.manager.audit.ProcessInstanceLog in project jbpm by kiegroup.

the class TimerMigrationManagerTest method testMigrateTimerProcessInstance.

@Test(timeout = 10000)
public void testMigrateTimerProcessInstance() throws Exception {
    NodeLeftCountDownProcessEventListener countdownListener = new NodeLeftCountDownProcessEventListener("EventV2", 1);
    createRuntimeManagers("migration/v1/BPMN2-Timer-v1.bpmn2", "migration/v2/BPMN2-Timer-v2.bpmn2", countdownListener);
    assertNotNull(managerV1);
    assertNotNull(managerV2);
    RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance pi1 = ksession.startProcess(TIMER_ID_V1);
    assertNotNull(pi1);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    JPAAuditLogService auditService = new JPAAuditLogService(emf);
    ProcessInstanceLog log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(TIMER_ID_V1, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
    managerV1.disposeRuntimeEngine(runtime);
    MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, TIMER_ID_V2);
    MigrationManager migrationManager = new MigrationManager(migrationSpec);
    MigrationReport report = migrationManager.migrate();
    assertNotNull(report);
    assertTrue(report.isSuccessful());
    log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(TIMER_ID_V2, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
    assertEquals(ProcessInstance.STATE_ACTIVE, log.getStatus().intValue());
    // wait till timer fires
    countdownListener.waitTillCompleted();
    log = auditService.findProcessInstance(pi1.getId());
    auditService.dispose();
    assertNotNull(log);
    assertEquals(TIMER_ID_V2, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
    assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

ProcessInstanceLog (org.kie.api.runtime.manager.audit.ProcessInstanceLog)30 Test (org.junit.Test)24 KieSession (org.kie.api.runtime.KieSession)23 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)19 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)16 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)12 JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)11 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)7 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)6 AuditService (org.kie.api.runtime.manager.audit.AuditService)5 TaskSummary (org.kie.api.task.model.TaskSummary)5 TaskService (org.kie.api.task.TaskService)4 BZ (qa.tools.ikeeper.annotation.BZ)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Task (org.kie.api.task.model.Task)2 ProcessInstanceLogDeleteBuilder (org.kie.internal.runtime.manager.audit.query.ProcessInstanceLogDeleteBuilder)2 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1