public void run() { try { // wait for amount of time timer expires and plus 1s initially Thread.sleep(wait * 1000 + 1000); long processInstanceId = counter + 1; for (int y = 0; y < wait; y++) { RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)); try { testCompleteTaskByProcessInstance(manager, runtime, processInstanceId); } catch (Throwable e) { if (checkOptimiticLockException(e)) { logger.debug("{} retrying for process instance {}", counter, processInstanceId); manager.disposeRuntimeEngine(runtime); runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)); testRetryCompleteTaskByProcessInstance(manager, runtime, processInstanceId); } else { throw e; } } manager.disposeRuntimeEngine(runtime); } completedTask++; } catch (Throwable t) { t.printStackTrace(); } }
@Test public void testDeploymentOfProcessesKieConteinerInjection() { assertNotNull(deploymentService); KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION, "KBase-test", "ksession-test-2"); deploymentService.deploy(deploymentUnit); units.add(deploymentUnit); assertNotNull(deploymentUnit.getDeploymentDescriptor()); DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier()); assertNotNull(deployed); assertNotNull(deployed.getDeploymentUnit()); assertNotNull(deployed.getRuntimeManager()); assertNull(deployed.getDeployedAssetLocation("customtask")); assertEquals( GROUP_ID + ":" + ARTIFACT_ID + ":" + VERSION + ":" + "KBase-test" + ":" + "ksession-test-2", deployed.getDeploymentUnit().getIdentifier()); RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier()); assertNotNull(manager); RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get()); assertNotNull(engine); Map<String, Object> params = new HashMap<String, Object>(); params.put("id", "test"); ProcessInstance processInstance = engine.getKieSession().startProcess("customtask", params); assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState()); manager.disposeRuntimeEngine(engine); }
public void afterCompletion(int status) { try { manager.disposeRuntimeEngine(runtime); } catch (Throwable e) { // catch exception as it's only clean up and should not affect runtime } }
@Test public void testUserTaskFromKjar() { KieServices ks = KieServices.Factory.get(); RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get() .newDefaultBuilder(ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION)) .userGroupCallback(userGroupCallback) .get(); manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment); assertNotNull(manager); RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get()); assertNotNull(engine); Map<String, Object> params = new HashMap<String, Object>(); ProcessInstance processInstance = engine.getKieSession().startProcess("UserTask", params); List<TaskSummary> tasks = engine.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK"); assertNotNull(tasks); assertEquals(1, tasks.size()); long taskId = tasks.get(0).getId(); engine.getTaskService().start(taskId, "john"); engine.getTaskService().complete(taskId, "john", null); processInstance = engine.getKieSession().getProcessInstance(processInstance.getId()); assertNull(processInstance); manager.disposeRuntimeEngine(engine); }
@Test public void testSinglePerRequestManager() { assertNotNull(perRequestManager); RuntimeEngine runtime = perRequestManager.getRuntimeEngine(EmptyContext.get()); assertNotNull(runtime); testProcessStartOnManager(runtime); perRequestManager.disposeRuntimeEngine(runtime); }
public void run() { try { RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get()); testStartProcess(runtime); manager.disposeRuntimeEngine(runtime); completedStart++; } catch (Throwable t) { t.printStackTrace(); } }
@Test public void testSinglePerProcessInstanceManager() { assertNotNull(perProcessInstanceManager); RuntimeEngine runtime = perProcessInstanceManager.getRuntimeEngine(ProcessInstanceIdContext.get()); assertNotNull(runtime); testProcessStartOnManager(runtime); perProcessInstanceManager.disposeRuntimeEngine(runtime); }
@Test public void testProcess() { RuntimeManager manager = createRuntimeManager("hello.bpmn"); RuntimeEngine runtimeEngine = getRuntimeEngine(); KieSession ksession = runtimeEngine.getKieSession(); ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello"); // check whether the process instance has completed successfully assertProcessInstanceCompleted(processInstance.getId(), ksession); assertNodeTriggered(processInstance.getId(), "StartProcess", "Hello", "EndProcess"); manager.disposeRuntimeEngine(runtimeEngine); manager.close(); }
/** * Disposes currently active (in scope of a test) <code>RuntimeManager</code> together with all * active <code>RuntimeEngine</code>'s that were created (in scope of a test). Usual use case is * to simulate system shutdown. */ protected void disposeRuntimeManager() { if (!activeEngines.isEmpty()) { for (RuntimeEngine engine : activeEngines) { manager.disposeRuntimeEngine(engine); } activeEngines.clear(); } if (manager != null) { manager.close(); manager = null; } }
/** * Disposes currently active (in scope of a test) <code>RuntimeManager</code> together with all * active <code>RuntimeEngine</code>'s that were created (in scope of a test). Usual use case is * to simulate system shutdown. */ protected void disposeRuntimeManager() { if (!activeEngines.isEmpty()) { for (RuntimeEngine engine : activeEngines) { try { manager.disposeRuntimeEngine(engine); } catch (Exception e) { logger.debug( "Exception during dipose of runtime engine, might be already disposed - {}", e.getMessage()); } } activeEngines.clear(); } if (manager != null) { manager.close(); manager = null; } }
@After public void tearDown() throws Exception { clearHistory(); if (setupDataSource) { if (emf != null) { emf.close(); emf = null; } if (ds != null) { ds.close(); ds = null; } } if (!activeEngines.isEmpty()) { for (RuntimeEngine engine : activeEngines) { manager.disposeRuntimeEngine(engine); } } if (manager != null) { manager.close(); manager = null; } }
@Test public void testDeploymentOfProcessWithDescriptorKieConteinerInjection() { assertNotNull(deploymentService); KieServices ks = KieServices.Factory.get(); ReleaseId releaseId = ks.newReleaseId(GROUP_ID, "kjar-with-dd", VERSION); List<String> processes = new ArrayList<String>(); processes.add("repo/processes/general/customtask.bpmn"); processes.add("repo/processes/general/humanTask.bpmn"); processes.add("repo/processes/general/import.bpmn"); DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain"); customDescriptor .getBuilder() .runtimeStrategy(RuntimeStrategy.PER_REQUEST) .addWorkItemHandler( new NamedObjectModel( "mvel", "Log", "new org.jbpm.kie.services.test.objects.KieConteinerSystemOutWorkItemHandler(kieContainer)")); Map<String, String> resources = new HashMap<String, String>(); resources.put( "src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml()); InternalKieModule kJar1 = createKieJar(ks, releaseId, processes, resources); File pom = new File("target/kmodule", "pom.xml"); pom.getParentFile().mkdir(); try { FileOutputStream fs = new FileOutputStream(pom); fs.write(getPom(releaseId).getBytes()); fs.close(); } catch (Exception e) { } MavenRepository repository = getMavenRepository(); repository.deployArtifact(releaseId, kJar1, pom); DeploymentUnit deploymentUnit = new KModuleDeploymentUnit( GROUP_ID, "kjar-with-dd", VERSION, "KBase-test", "ksession-test2"); deploymentService.deploy(deploymentUnit); units.add(deploymentUnit); DeployedUnit deployedGeneral = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier()); assertNotNull(deployedGeneral); assertNotNull(deployedGeneral.getDeploymentUnit()); assertNotNull(deployedGeneral.getRuntimeManager()); DeploymentDescriptor descriptor = ((InternalRuntimeManager) deployedGeneral.getRuntimeManager()).getDeploymentDescriptor(); assertNotNull(descriptor); assertEquals("org.jbpm.domain", descriptor.getPersistenceUnit()); assertEquals("org.jbpm.domain", descriptor.getAuditPersistenceUnit()); assertEquals(AuditMode.JPA, descriptor.getAuditMode()); assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode()); assertEquals(RuntimeStrategy.PER_REQUEST, descriptor.getRuntimeStrategy()); assertEquals(0, descriptor.getMarshallingStrategies().size()); assertEquals(0, descriptor.getConfiguration().size()); assertEquals(0, descriptor.getEnvironmentEntries().size()); assertEquals(0, descriptor.getEventListeners().size()); assertEquals(0, descriptor.getGlobals().size()); assertEquals(0, descriptor.getTaskEventListeners().size()); assertEquals(1, descriptor.getWorkItemHandlers().size()); assertEquals(0, descriptor.getRequiredRoles().size()); RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier()); assertNotNull(manager); RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get()); assertNotNull(engine); Map<String, Object> params = new HashMap<String, Object>(); ProcessInstance processInstance = engine.getKieSession().startProcess("customtask", params); assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState()); manager.disposeRuntimeEngine(engine); }
@Test public void testSessionPerProcessInstance() throws Exception { RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get() .newDefaultBuilder() .entityManagerFactory(emf) .userGroupCallback(userGroupCallback) .addAsset( ResourceFactory.newClassPathResource( "org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT.bpmn2"), ResourceType.BPMN2) .schedulerService(globalScheduler) .get(); long startTimeStamp = System.currentTimeMillis(); long maxEndTime = startTimeStamp + maxWaitTime; manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment); // prepare task service with users and groups RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get()); TaskService taskService = engine.getTaskService(); Group grouphr = TaskModelProvider.getFactory().newGroup(); ((InternalOrganizationalEntity) grouphr).setId("HR"); User mary = TaskModelProvider.getFactory().newUser(); ((InternalOrganizationalEntity) mary).setId("mary"); User john = TaskModelProvider.getFactory().newUser(); ((InternalOrganizationalEntity) john).setId("john"); ((InternalTaskService) taskService).addGroup(grouphr); ((InternalTaskService) taskService).addUser(mary); ((InternalTaskService) taskService).addUser(john); manager.disposeRuntimeEngine(engine); completedStart = 0; for (int i = 0; i < nbThreadsProcess; i++) { new StartProcessPerProcessInstanceRunnable(manager, i).run(); } completedTask = 0; for (int i = 0; i < nbThreadsTask; i++) { new Thread(new CompleteTaskPerProcessInstanceRunnable(manager, i)).start(); } while (completedStart < nbThreadsProcess || completedTask < nbThreadsTask) { Thread.sleep(100); if (System.currentTimeMillis() > maxEndTime) { fail("Failure, did not finish in time most likely hanging"); } } // make sure all process instance were completed engine = manager.getRuntimeEngine(EmptyContext.get()); AuditService logService = engine.getAuditService(); // active List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("IntermediateCatchEvent"); assertNotNull(logs); for (ProcessInstanceLog log : logs) { logger.debug("Left over {}", log.getProcessInstanceId()); } assertEquals(0, logs.size()); // completed logs = logService.findProcessInstances("IntermediateCatchEvent"); assertNotNull(logs); assertEquals(nbThreadsProcess, logs.size()); manager.disposeRuntimeEngine(engine); logger.debug("Done"); }