Java Code Examples for org.flowable.engine.TaskService#complete()
The following examples show how to use
org.flowable.engine.TaskService#complete() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleSimulationRunTest.java From flowable-engine with Apache License 2.0 | 6 votes |
private void recordEvents() { Clock clock = new DefaultClockImpl(); clock.setCurrentTime(new Date(0)); ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault(); config.setClock(clock); ProcessEngine processEngine = (new RecordableProcessEngineFactory(config, listener)) .getObject(); processEngine.getRepositoryService().createDeployment().addClasspathResource(USERTASK_PROCESS).deploy(); EventRecorderTestUtils.increaseTime(clock); TaskService taskService = processEngine.getTaskService(); Map<String, Object> variables = new HashMap<>(); variables.put(TEST_VARIABLE, TEST_VALUE); processEngine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess", "oneTaskProcessBusinessKey", variables); EventRecorderTestUtils.increaseTime(clock); Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult(); taskService.complete(task.getId()); checkStatus(processEngine.getHistoryService()); EventRecorderTestUtils.closeProcessEngine(processEngine, listener); ProcessEngines.destroy(); }
Example 2
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" }) public void logAddParticipantUser(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); try { assertThat(processInstance).isNotNull(); assertThat(task).isNotNull(); taskService.addUserIdentityLink(task.getId(), "newCandidateUser", IdentityLinkType.PARTICIPANT); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); assertThat(logEntries).hasSize(2); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_IDENTITY_LINK_ADDED") .list(); assertThat(logEntries).hasSize(1); assertThat(logEntries.get(0).getData()).contains( "\"type\":\"participant\"", "\"userId\":\"newCandidateUser\"" ); } } finally { taskService.complete(task.getId()); deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId()); } }
Example 3
Source File: FlowableRuleJunit4Test.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment public void ruleUsageExample() { RuntimeService runtimeService = activitiRule.getRuntimeService(); runtimeService.startProcessInstanceByKey("ruleUsage"); TaskService taskService = activitiRule.getTaskService(); org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult(); assertThat(task.getName()).isEqualTo("My Task"); taskService.complete(task.getId()); assertThat(runtimeService.createProcessInstanceQuery().count()).isZero(); }
Example 4
Source File: FlowableJupiterTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment void extensionUsageExample(ProcessEngine processEngine) { RuntimeService runtimeService = processEngine.getRuntimeService(); runtimeService.startProcessInstanceByKey("extensionUsage"); TaskService taskService = processEngine.getTaskService(); org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult(); assertThat(task.getName()).isEqualTo("My Task"); taskService.complete(task.getId()); assertThat(runtimeService.createProcessInstanceQuery().count()).isZero(); assertThat(processEngine.getName()).as("process engine name").isEqualTo(ProcessEngines.NAME_DEFAULT); }
Example 5
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" }) public void logDeleteCandidateUser(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); assertThat(processInstance).isNotNull(); assertThat(task).isNotNull(); taskService.addCandidateUser(task.getId(), "newCandidateUser"); try { taskService.deleteCandidateUser(task.getId(), "newCandidateUser"); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); assertThat(logEntries).hasSize(3); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_IDENTITY_LINK_REMOVED") .list(); assertThat(logEntries).hasSize(1); assertThat(logEntries.get(0).getData()).contains( "\"type\":\"candidate\"", "\"userId\":\"newCandidateUser\"" ); } } finally { taskService.complete(task.getId()); deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId()); } }
Example 6
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" }) public void logDeleteCandidateGroup(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); assertThat(processInstance).isNotNull(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); assertThat(task).isNotNull(); taskService.addCandidateGroup(task.getId(), "newCandidateGroup"); try { taskService.deleteCandidateGroup(task.getId(), "newCandidateGroup"); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); assertThat(logEntries).hasSize(3); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_IDENTITY_LINK_REMOVED") .list(); assertThat(logEntries).hasSize(1); assertThat(logEntries.get(0).getData()).contains( "\"type\":\"candidate\"", "\"groupId\":\"newCandidateGroup\"" ); } } finally { taskService.complete(task.getId()); deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId()); } }
Example 7
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" }) public void logAddGroup(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); assertThat(processInstance).isNotNull(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); assertThat(task).isNotNull(); try { taskService.addGroupIdentityLink(task.getId(), "newCandidateGroup", IdentityLinkType.PARTICIPANT); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); assertThat(logEntries).hasSize(2); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_IDENTITY_LINK_ADDED") .list(); assertThat(logEntries).hasSize(1); assertThat(logEntries.get(0).getData()).contains( "\"type\":\"participant\"", "\"groupId\":\"newCandidateGroup\"" ); } } finally { taskService.complete(task.getId()); deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId()); } }
Example 8
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" }) public void logAddCandidateGroup(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); assertThat(processInstance).isNotNull(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); assertThat(task).isNotNull(); try { taskService.addCandidateGroup(task.getId(), "newCandidateGroup"); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); assertThat(logEntries).hasSize(2); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_IDENTITY_LINK_ADDED") .list(); assertThat(logEntries).hasSize(1); assertThat(logEntries.get(0).getData()).contains( "\"type\":\"candidate\"", "\"groupId\":\"newCandidateGroup\"" ); } } finally { taskService.complete(task.getId()); deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId()); } }
Example 9
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" }) public void logAddCandidateUser(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); try { assertThat(processInstance).isNotNull(); assertThat(task).isNotNull(); taskService.addCandidateUser(task.getId(), "newCandidateUser"); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); assertThat(logEntries).hasSize(2); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_IDENTITY_LINK_ADDED") .list(); assertThat(logEntries).hasSize(1); assertThat(logEntries.get(0).getData()).contains( "\"type\":\"candidate\"", "\"userId\":\"newCandidateUser\"" ); } } finally { taskService.complete(task.getId()); deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId()); } }
Example 10
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" }) public void logProcessTaskEvents(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); assertThat(processInstance).isNotNull(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); assertThat(task).isNotNull(); try { taskService.setAssignee(task.getId(), "newAssignee"); taskService.setOwner(task.getId(), "newOwner"); taskService.complete(task.getId()); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); assertThat(logEntries).hasSize(4); HistoricTaskLogEntry logEntry = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_CREATED").singleResult(); assertThat(logEntry).isNotNull(); assertThat(logEntry.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId()); assertThat(logEntry.getExecutionId()).isEqualTo(task.getExecutionId()); assertThat(logEntry.getProcessInstanceId()).isEqualTo(processInstance.getId()); assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_ASSIGNEE_CHANGED").count()).isEqualTo(1); assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_OWNER_CHANGED").count()).isEqualTo(1); assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_COMPLETED").count()).isEqualTo(1); } } finally { deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId()); } }
Example 11
Source File: Application.java From flowable-engine with Apache License 2.0 | 5 votes |
@Bean CommandLineRunner startProcess(final RuntimeService runtimeService, final TaskService taskService) { return new CommandLineRunner() { @Override public void run(String... strings) throws Exception { for (int i = 0; i < 10; i++) runtimeService.startProcessInstanceByKey("waiter", Collections.singletonMap("customerId", (Object) i)); for (int i = 0; i < 7; i++) taskService.complete(taskService.createTaskQuery().list().get(0).getId()); } }; }
Example 12
Source File: ActivitiRuleJunit4Test.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment public void ruleUsageExample() { RuntimeService runtimeService = activitiRule.getRuntimeService(); runtimeService.startProcessInstanceByKey("ruleUsage"); TaskService taskService = activitiRule.getTaskService(); org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult(); assertEquals("My Task", task.getName()); taskService.complete(task.getId()); assertEquals(0, runtimeService.createProcessInstanceQuery().count()); }
Example 13
Source File: ReplayRunTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test public void testProcessInstanceStartEvents() throws Exception { ProcessEngineImpl processEngine = initProcessEngine(); TaskService taskService = processEngine.getTaskService(); RuntimeService runtimeService = processEngine.getRuntimeService(); Map<String, Object> variables = new HashMap<>(); variables.put(TEST_VARIABLE, TEST_VALUE); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(USERTASK_PROCESS, BUSINESS_KEY, variables); Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult(); TimeUnit.MILLISECONDS.sleep(50); taskService.complete(task.getId()); final SimulationDebugger simRun = new ReplaySimulationRun(processEngine, getReplayHandlers(processInstance.getId())); simRun.init(new NoExecutionVariableScope()); // original process is finished - there should not be any running process instance/task assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count()); assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); simRun.step(); // replay process was started assertEquals(1, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count()); // there should be one task assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); simRun.step(); // userTask was completed - replay process was finished assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count()); assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); simRun.close(); processEngine.close(); ProcessEngines.destroy(); }
Example 14
Source File: ProcessDefinitionCacheTest.java From flowable-engine with Apache License 2.0 | 4 votes |
public void testStartProcessInstanceByIdAfterReboot() { // In case this test is run in a test suite, previous engines might // have been initialized and cached. First we close the // existing process engines to make sure that the db is clean // and that there are no existing process engines involved. ProcessEngines.destroy(); // Creating the DB schema (without building a process engine) ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration(); processEngineConfiguration.setEngineName("reboot-test-schema"); processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000"); processEngineConfiguration.setFlowable5CompatibilityEnabled(true); ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine(); // Create process engine and deploy test process StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration(); standaloneProcessEngineConfiguration.setEngineName("reboot-test"); standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE); standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000"); standaloneProcessEngineConfiguration.setAsyncExecutorActivate(false); standaloneProcessEngineConfiguration.setFlowable5CompatibilityEnabled(true); ProcessEngine processEngine = standaloneProcessEngineConfiguration.buildProcessEngine(); processEngine.getRepositoryService() .createDeployment() .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE) .addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml") .deploy(); // verify existence of process definition List<ProcessDefinition> processDefinitions = processEngine .getRepositoryService() .createProcessDefinitionQuery() .list(); assertEquals(1, processDefinitions.size()); // Start a new Process instance ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId()); String processInstanceId = processInstance.getId(); assertNotNull(processInstance); // Close the process engine processEngine.close(); assertNotNull(processEngine.getRuntimeService()); // Reboot the process engine standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration(); standaloneProcessEngineConfiguration.setEngineName("reboot-test"); standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE); standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000"); standaloneProcessEngineConfiguration.setAsyncExecutorActivate(false); standaloneProcessEngineConfiguration.setFlowable5CompatibilityEnabled(true); processEngine = standaloneProcessEngineConfiguration.buildProcessEngine(); // Check if the existing process instance is still alive processInstance = processEngine .getRuntimeService() .createProcessInstanceQuery() .processInstanceId(processInstanceId) .singleResult(); assertNotNull(processInstance); // Complete the task. That will end the process instance TaskService taskService = processEngine.getTaskService(); org.flowable.task.api.Task task = taskService .createTaskQuery() .list() .get(0); taskService.complete(task.getId()); // Check if the process instance has really ended. This means that the process definition has // re-loaded into the process definition cache processInstance = processEngine .getRuntimeService() .createProcessInstanceQuery() .processInstanceId(processInstanceId) .singleResult(); assertNull(processInstance); // Extra check to see if a new process instance can be started as well processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId()); assertNotNull(processInstance); // close the process engine processEngine.close(); // Cleanup schema schemaProcessEngine.close(); }
Example 15
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test @Deployment(resources = "org/flowable/engine/test/api/task/TaskIdentityLinksTest.testCustomIdentityLink.bpmn20.xml") public void logIdentityLinkEventsForProcessIdentityLinks(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { runtimeService.startProcessInstanceByKey("customIdentityLink"); List<org.flowable.task.api.Task> tasks = taskService.createTaskQuery().taskInvolvedUser("kermit").list(); assertThat(tasks).hasSize(1); task = tasks.get(0); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); // create, identityLinkAdded, identityLinkAdded assertThat(logEntries).hasSize(3); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_IDENTITY_LINK_ADDED") .list(); assertThat(logEntries).hasSize(2); boolean hasKermit = false; boolean hasManagement = false; String data = logEntries.get(0).getData(); String data1 = logEntries.get(1).getData(); if ((data.contains("\"type\":\"businessAdministrator\"") && data.contains("\"userId\":\"kermit\"")) || (data1.contains("\"type\":\"businessAdministrator\"") && data1.contains("\"userId\":\"kermit\""))) { hasKermit = true; } if ((data.contains("\"type\":\"businessAdministrator\"") && data.contains("\"groupId\":\"management\"")) || (data1.contains("\"type\":\"businessAdministrator\"") && data1.contains("\"groupId\":\"management\""))) { hasManagement = true; } assertThat(hasKermit).isTrue(); assertThat(hasManagement).isTrue(); taskService.complete(tasks.get(0).getId()); HistoryTestHelper.waitForJobExecutorToProcessAllHistoryJobs(processEngineConfiguration, managementService, 10000, 200); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); // + completed event. Do not expect identity link removed events assertThat(logEntries).hasSize(4); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_COMPLETED") .list(); assertThat(logEntries).hasSize(1); } }
Example 16
Source File: ProcessDefinitionCacheTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test public void testStartProcessInstanceByIdAfterReboot() { // In case this test is run in a test suite, previous engines might have been initialized and cached. First we close the // existing process engines to make sure that the db is clean and that there are no existing process engines involved. ProcessEngines.destroy(); // Creating the DB schema (without building a process engine) ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration(); processEngineConfiguration.setEngineName("reboot-test-schema"); processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000"); ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine(); // Create process engine and deploy test process ProcessEngine processEngine = new StandaloneProcessEngineConfiguration().setEngineName("reboot-test").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE) .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine(); processEngine.getRepositoryService().createDeployment().addClasspathResource("org/flowable/engine/test/cache/originalProcess.bpmn20.xml").deploy(); // verify existence of process definition List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list(); assertEquals(1, processDefinitions.size()); // Start a new Process instance ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId()); String processInstanceId = processInstance.getId(); assertNotNull(processInstance); // Close the process engine processEngine.close(); assertNotNull(processEngine.getRuntimeService()); // Reboot the process engine processEngine = new StandaloneProcessEngineConfiguration().setEngineName("reboot-test").setDatabaseSchemaUpdate(org.flowable.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE) .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine(); // Check if the existing process instance is still alive processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); assertNotNull(processInstance); // Complete the task. That will end the process instance TaskService taskService = processEngine.getTaskService(); org.flowable.task.api.Task task = taskService.createTaskQuery().list().get(0); taskService.complete(task.getId()); // Check if the process instance has really ended. This means that the // process definition has re-loaded into the process definition cache processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); assertNull(processInstance); // Extra check to see if a new process instance can be started as well processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId()); assertNotNull(processInstance); // close the process engine processEngine.close(); // Cleanup schema schemaProcessEngine.close(); }
Example 17
Source File: ReplayEventLogTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test public void testProcessInstanceStartEvents() throws Exception { ProcessEngineImpl processEngine = initProcessEngine(); TaskService taskService = processEngine.getTaskService(); RuntimeService runtimeService = processEngine.getRuntimeService(); ManagementService managementService = processEngine.getManagementService(); HistoryService historyService = processEngine.getHistoryService(); // record events Map<String, Object> variables = new HashMap<>(); variables.put(TEST_VARIABLE, TEST_VALUE); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(USERTASK_PROCESS, BUSINESS_KEY, variables); Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult(); TimeUnit.MILLISECONDS.sleep(50); variables = new HashMap<>(); variables.put(TASK_TEST_VARIABLE, TASK_TEST_VALUE); taskService.complete(task.getId(), variables); // transform log events List<EventLogEntry> eventLogEntries = managementService.getEventLogEntries(null, null); EventLogTransformer transformer = new EventLogTransformer(getTransformers()); List<SimulationEvent> simulationEvents = transformer.transform(eventLogEntries); SimpleEventCalendar eventCalendar = new SimpleEventCalendar(processEngine.getProcessEngineConfiguration().getClock(), new SimulationEventComparator()); eventCalendar.addEvents(simulationEvents); // replay process instance run final SimulationDebugger simRun = new ReplaySimulationRun(processEngine, eventCalendar, getReplayHandlers(processInstance.getId())); simRun.init(new NoExecutionVariableScope()); // original process is finished - there should not be any running process instance/task assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count()); assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); simRun.step(); // replay process was started ProcessInstance replayProcessInstance = runtimeService.createProcessInstanceQuery() .processDefinitionKey(USERTASK_PROCESS) .singleResult(); assertNotNull(replayProcessInstance); assertNotEquals(replayProcessInstance.getId(), processInstance.getId()); assertEquals(TEST_VALUE, runtimeService.getVariable(replayProcessInstance.getId(), TEST_VARIABLE)); // there should be one task assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); simRun.step(); // userTask was completed - replay process was finished assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count()); assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(replayProcessInstance.getId()) .variableName(TASK_TEST_VARIABLE) .singleResult(); assertNotNull(variableInstance); assertEquals(TASK_TEST_VALUE, variableInstance.getValue()); // close simulation simRun.close(); processEngine.close(); ProcessEngines.destroy(); }