strange behaviour after enable session persistence
cyu021 Sep 5, 2014 12:59 PMHi all,
I have an example that extends JbpmJUnitBaseTestCase to create Kiesession, let's name this example ExA.
In ExA, the process will be waiting for external event to continue and complete.
So I do startProcess(), signalEvent(), and getProcessInstances() in 3 different methods.
After startProcess(), the process is waiting for external signal and the state is active (1).
Then getProcessInstances() confirms that there is 1 undergoing process.
Finally, signalEvent() triggers the process to continue and its state becomes complete (2).
In ExA, I use the following code snippet to get KieSession to work with:
manager = createRuntimeManager(bpmfiles);
engine = getRuntimeEngine(null);
ksession = engine.getKieSession();
Then I decide to take persistence approach and not to extend JbpmJUnitBaseTestCase no more to run the example, let's call it ExB.
In ExB, I use the following code snippet to get KieSession:
ds = new PoolingDataSource();
ds.setUniqueName("jdbc/testDS");
ds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");
ds.setAllowLocalTransactions(true);
ds.setMaxPoolSize(3);
ds.getDriverProperties().put("driverClassName", "com.mysql.jdbc.Driver");
ds.getDriverProperties().put("Url", "jdbc:mysql://localhost:3306/jbpm");
ds.getDriverProperties().put("password", "jbpm");
ds.getDriverProperties().put("user", "jbpm");
ds.init();
KieServices kservices = KieServices.Factory.get();
KieStoreServices kstore = kservices.getStoreServices();
//Create an environment variable with all the database configuration content
Environment environment = kservices.newEnvironment();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
TransactionManager tm = TransactionManagerServices.getTransactionManager();
environment.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
environment.set(EnvironmentName.TRANSACTION_MANAGER, tm);
//KieSession configuration object to configure special components
KieSessionConfiguration ksconf = kservices.newKieSessionConfiguration();
//KieBase we will use to create and restore the runtime from the database
KieBase kbase = kservices.getKieClasspathContainer().getKieBase();
//Invocation to create a new persistent session
ksession = kstore.newKieSession(kbase, ksconf, environment);
After startProcess(), the process is waiting for external signal and the state is active (1), as expected.
However processinstancelog table is empty and getProcessInstances() returns null --> this is stange!
So I skip getProcessInstances() and run again.
Finally, signalEvent() triggers the process to continue, but its state stays in active (1) --> this is strange.
I attach PTest.java and BPMService.java for your reference.
PTest.java is the test code I run, and BPMService.java is the actual code to deal with the process.
I need your advise to sort out this problem, thank you.
-
PTest.java 1.2 KB
-
BPMService.java 5.9 KB