public void testNewSessionFailBefore() throws Exception { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("sampleFailBefore.bpmn"), ResourceType.BPMN2); KnowledgeBase kbase = kbuilder.newKnowledgeBase(); SessionManagerFactory factory = new NewSessionSessionManagerFactory(kbase); SessionManager sessionManager = factory.getSessionManager(); try { ProcessInstance processInstance = sessionManager.getKnowledgeSession().startProcess("com.sample.bpmn.hello", null); fail("Started process instance " + processInstance.getId()); } catch (RuntimeException e) { // do nothing } // TODO: whenever transaction fails, do we need to dispose? can we? // sessionManager.dispose(); List<Status> statusses = new ArrayList<Status>(); statusses.add(Status.Reserved); sessionManager = factory.getSessionManager(); List<TaskSummary> tasks = sessionManager.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK"); assertEquals(0, tasks.size()); sessionManager.dispose(); factory.dispose(); }
public void testNewSessionDispose() throws Exception { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("sample.bpmn"), ResourceType.BPMN2); KnowledgeBase kbase = kbuilder.newKnowledgeBase(); SessionManagerFactory factory = new NewSessionSessionManagerFactory(kbase); final SessionManager sessionManager = factory.getSessionManager(); UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction"); ut.begin(); sessionManager.getKnowledgeSession().startProcess("com.sample.bpmn.hello", null); TransactionManagerServices.getTransactionManager() .getTransaction() .registerSynchronization( new Synchronization() { public void beforeCompletion() {} public void afterCompletion(int status) { try { sessionManager.dispose(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); ut.commit(); factory.dispose(); }
public void testProcessFactory() { RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process"); factory // header .name("My process") .packageName("org.jbpm") // nodes .startNode(1) .name("Start") .done() .actionNode(2) .name("Action") .action("java", "System.out.println(\"Action\");") .done() .endNode(3) .name("End") .done() // connections .connection(1, 2) .connection(2, 3); RuleFlowProcess process = factory.validate().getProcess(); KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newByteArrayResource( XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes()), ResourceType.BPMN2); KnowledgeBase kbase = kbuilder.newKnowledgeBase(); StatefulKnowledgeSession ksession = createKnowledgeSession(kbase); ksession.startProcess("org.jbpm.process"); }
public void testSingletonSessionMemory() throws Exception { for (int i = 0; i < 1000; i++) { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("sample.bpmn"), ResourceType.BPMN2); KnowledgeBase kbase = kbuilder.newKnowledgeBase(); SessionManagerFactory factory = new SingletonSessionManagerFactory(kbase); SessionManager sessionManager = factory.getSessionManager(); sessionManager.dispose(); factory.dispose(); System.gc(); Thread.sleep(100); System.gc(); System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); } }
public void testSingleActionNode() throws Exception { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( new ClassPathResource("ActionNodeTest.xml", ActionNodeTest.class), ResourceType.DRF); KnowledgeBase kbase = kbuilder.newKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); List<String> list = new ArrayList<String>(); ksession.setGlobal("list", list); ksession.startProcess("process name"); assertEquals(1, list.size()); assertEquals("action node was here", list.get(0)); }
public void testNewSessionFailAfter() throws Exception { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("sampleFailAfter.bpmn"), ResourceType.BPMN2); KnowledgeBase kbase = kbuilder.newKnowledgeBase(); SessionManagerFactory factory = new NewSessionSessionManagerFactory(kbase); SessionManager sessionManager = factory.getSessionManager(); ProcessInstance processInstance = sessionManager.getKnowledgeSession().startProcess("com.sample.bpmn.hello", null); long workItemId = ((HumanTaskNodeInstance) ((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next()) .getWorkItemId(); long taskId = sessionManager.getTaskService().getTaskByWorkItemId(workItemId).getId(); sessionManager.getTaskService().claim(taskId, "mary"); List<Status> statusses = new ArrayList<Status>(); statusses.add(Status.Reserved); List<TaskSummary> tasks = sessionManager.getTaskService().getTasksOwned("mary", statusses, "en-UK"); assertEquals(1, tasks.size()); taskId = tasks.get(0).getId(); UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction"); try { ut.begin(); sessionManager.getTaskService().start(taskId, "mary"); sessionManager.getTaskService().complete(taskId, "mary", null); fail("Task completed"); } catch (RuntimeException e) { // do nothing } ut.rollback(); // TODO: whenever transaction fails, do we need to dispose? can we? // sessionManager.dispose(); sessionManager = factory.getSessionManager(); tasks = sessionManager.getTaskService().getTasksOwned("mary", statusses, "en-UK"); assertEquals(1, tasks.size()); sessionManager.dispose(); factory.dispose(); }
public void testNewSession() throws Exception { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("sample.bpmn"), ResourceType.BPMN2); KnowledgeBase kbase = kbuilder.newKnowledgeBase(); SessionManagerFactory factory = new NewSessionSessionManagerFactory(kbase); completedStart = 0; for (int i = 0; i < nbThreadsProcess; i++) { new StartProcessRunnable(factory, i).run(); } completedTask = 0; for (int i = 0; i < nbThreadsTask; i++) { new Thread(new CompleteTaskRunnable(factory, i)).start(); } while (completedStart < nbThreadsProcess || completedTask < nbThreadsTask) { Thread.sleep(100); } factory.dispose(); System.out.println("Done"); }