@After public void dispose() { if (ksession != null) { ksession.dispose(); ksession = null; } }
@After public void dispose() { if (ksession != null) { ksession.dispose(); } }
@After public void dispose() { if (ksession != null) { ksession.dispose(); ksession = null; } }
@After public void dispose() { if (ksession != null) { ksession.dispose(); ksession = null; } }
private StatefulKnowledgeSession reloadKnowledgeSession(StatefulKnowledgeSession ksession) { ksession.dispose(); return reloadKnowledgeSession(); } }
@After public void after() { if( ksession != null ) { ksession.dispose(); } cleanUp(context); }
@Override protected StatefulKnowledgeSession disposeAndReloadSession(StatefulKnowledgeSession ksession, long ksessionId, KieBase kbase) { ksession.dispose(); return JPAKnowledgeService.loadStatefulKnowledgeSession( ksessionId, kbase, null, createEnvironment(context) ); }
@After public void after() { if (ksession != null) { ksession.dispose(); } cleanUp(context); }
@Test public void getEmptyProcessInstances() throws Exception { StatefulKnowledgeSession ksession = reloadKnowledgeSession(); assertEquals(0, ksession.getProcessInstances().size()); ksession.dispose(); }
@Test public void testSignalBoundaryEventOnMultiInstanceSubprocess() throws Exception { KieBase kbase = createKnowledgeBase( "subprocess/BPMN2-MultiInstanceSubprocessWithBoundarySignal.bpmn2"); StatefulKnowledgeSession ksession = createKnowledgeSession(kbase); TestWorkItemHandler handler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler); Map<String, Object> params = new HashMap<String, Object>(); List<String> approvers = new ArrayList<String>(); approvers.add("john"); approvers.add("john"); params.put("approvers", approvers); ProcessInstance processInstance = ksession.startProcess("boundary-catch-error-event", params); assertProcessInstanceActive(processInstance); List<WorkItem> workItems = handler.getWorkItems(); assertThat(workItems).isNotNull(); assertThat(workItems.size()).isEqualTo(2); ksession.signalEvent("Outside", null, processInstance.getId()); assertProcessInstanceFinished(processInstance, ksession); ksession.dispose(); }
@Test public void startProcessInPersistentEnvironment() { String processId = "minimalProcess"; KieBase kbase = createKieBase(ProcessCreatorForHelp.newShortestProcess( processId ) ); StatefulKnowledgeSession crmPersistentSession = createSession(kbase); crmPersistentSession.startProcess(processId); crmPersistentSession.dispose(); }
@Before public void setUp() throws Exception { context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME); env = createEnvironment(context); kbase = createBase(); StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env); sessionId = ksession.getIdentifier(); ksession.dispose(); }
@Test public void noProcessInstancesLeftWithPreTxKSessionAndRollback() throws Exception { long[] notProcess = new long[4]; StatefulKnowledgeSession ksession = reloadKnowledgeSession(); UserTransaction ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" ); ut.begin(); notProcess[0] = ksession.createProcessInstance("org.jbpm.processinstance.helloworld", null).getId(); notProcess[1] = ksession.createProcessInstance("org.jbpm.processinstance.helloworld", null).getId(); ut.rollback(); // Validate that proc inst mgr cache is also flushed on rollback assertEquals(0, ksession.getProcessInstances().size()); ksession = reloadKnowledgeSession(ksession); assertEquals(0, ksession.getProcessInstances().size()); ksession.dispose(); assertProcessInstancesNotExist(notProcess); }
@Test public void create2ProcessInstancesInsideTransaction() throws Exception { long[] processId = new long[2]; UserTransaction ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" ); ut.begin(); StatefulKnowledgeSession ksession = reloadKnowledgeSession(); processId[0] = ksession.createProcessInstance("org.jbpm.processinstance.helloworld", null).getId(); processId[1] = ksession.createProcessInstance("org.jbpm.processinstance.helloworld", null).getId(); assertEquals(2, ksession.getProcessInstances().size()); // process instance manager cache flushed on tx ut.commit(); assertEquals(0, ksession.getProcessInstances().size()); ksession = reloadKnowledgeSession(ksession); assertEquals(0, ksession.getProcessInstances().size()); ksession.dispose(); assertProcessInstancesExist(processId); }
@Test public void noProcessInstancesLeftAfterRollback() throws Exception { long[] notProcess = new long[2]; UserTransaction ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" ); ut.begin(); StatefulKnowledgeSession ksession = reloadKnowledgeSession(); notProcess[0] = ksession.createProcessInstance("org.jbpm.processinstance.helloworld", null).getId(); notProcess[1] = ksession.createProcessInstance("org.jbpm.processinstance.helloworld", null).getId(); assertEquals(2, ksession.getProcessInstances().size()); ut.rollback(); // Validate that proc inst mgr cache is also flushed on rollback assertEquals(0, ksession.getProcessInstances().size()); ksession = reloadKnowledgeSession(ksession); assertEquals(0, ksession.getProcessInstances().size()); ksession.dispose(); assertProcessInstancesNotExist(notProcess); }
@Test public void create2ProcessInstances() throws Exception { long[] processId = new long[2]; StatefulKnowledgeSession ksession = reloadKnowledgeSession(); processId[0] = ksession.createProcessInstance("org.jbpm.processinstance.helloworld", null).getId(); processId[1] = ksession.createProcessInstance("org.jbpm.processinstance.helloworld", null).getId(); ksession.dispose(); assertProcessInstancesExist(processId); }
@Test public void createProcessInstanceAndGetStartDate() throws Exception { StatefulKnowledgeSession ksession = reloadKnowledgeSession(); long processId= ksession.createProcessInstance("org.jbpm.processinstance.helloworld", null).getId(); assertEquals(0, ksession.getProcessInstances().size()); RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) ksession.getProcessInstance(processId); assertNotNull("Process " + processId + " exist!", processInstance); assertNotNull("Process start at " + processInstance.getStartDate(), processInstance.getStartDate()); ksession.dispose(); }
@Test public void testSignalBoundaryEventOnSubprocessTakingDifferentPaths() throws Exception { KieBase kbase = createKnowledgeBase( "BPMN2-SignalBoundaryOnSubProcess.bpmn"); StatefulKnowledgeSession ksession = createKnowledgeSession(kbase); ProcessInstance processInstance = ksession.startProcess("jbpm.testing.signal"); assertProcessInstanceActive(processInstance); ksession.signalEvent("continue", null, processInstance.getId()); assertProcessInstanceFinished(processInstance, ksession); ksession.dispose(); ksession = createKnowledgeSession(kbase); processInstance = ksession.startProcess("jbpm.testing.signal"); assertProcessInstanceActive(processInstance); ksession.signalEvent("forward", null); assertProcessInstanceFinished(processInstance, ksession); ksession.dispose(); }
@Override protected StatefulKnowledgeSession disposeAndReloadSession(StatefulKnowledgeSession ksession, long ksessionId, KieBase kbase) { ksession.dispose(); EnvironmentBuilder envBuilder = new ProcessStorageEnvironmentBuilder( storage ); Environment env = KieServices.get().newEnvironment(); env.set( EnvironmentName.TRANSACTION_MANAGER, envBuilder.getTransactionManager() ); env.set( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, envBuilder.getPersistenceContextManager() ); return JPAKnowledgeService.loadStatefulKnowledgeSession( ksessionId, kbase, null, env ); }
public static StatefulKnowledgeSession getSerialisedStatefulKnowledgeSession(StatefulKnowledgeSession ksession, ObjectMarshallingStrategy [] strategies, boolean dispose) throws Exception { Marshaller marshaller = MarshallerFactory.newMarshaller( ksession.getKieBase(), strategies ); final byte [] b1 = serializeKnowledgeSession(marshaller, ksession); StatefulKnowledgeSession ksession2 = deserializeKnowledgeSession(marshaller, b1); final byte[] b2 = serializeKnowledgeSession(marshaller, ksession2); // bytes should be the same. if ( !areByteArraysEqual( b1, b2 ) ) { // throw new IllegalArgumentException( "byte streams for serialisation test are not equal" ); } ((StatefulKnowledgeSessionImpl) ksession2).setGlobalResolver( ((StatefulKnowledgeSessionImpl) ksession).getGlobalResolver() ); if ( dispose ) { ksession.dispose(); } return ksession2; }