StatefulKnowledgeSession ksession = InfinispanKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
int origNumObjects = ksession.getObjects().size();
int id = ksession.getId();
ProcessInstance processInstance = ksession.startProcess( "org.drools.test.TestProcess" );
ksession.insert( "TestString" );
logger.debug( "Started process instance " + processInstance.getId() );
TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
WorkItem workItem = handler.getWorkItem();
assertNotNull( workItem );
ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession( id, kbase, null, env );
processInstance = ksession.getProcessInstance( processInstance.getId() );
assertNotNull( processInstance );
ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession( id, kbase, null, env );
ksession.getWorkItemManager().completeWorkItem( workItem.getId(),
null );
workItem = handler.getWorkItem();
assertNotNull( workItem );
ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession( id, kbase, null, env );
processInstance = ksession.getProcessInstance( processInstance.getId() );
assertNotNull( processInstance );
ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession( id, kbase, null, env );
ksession.getWorkItemManager().completeWorkItem( workItem.getId(),
null );
workItem = handler.getWorkItem();
assertNotNull( workItem );
ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession( id, kbase, null, env );
processInstance = ksession.getProcessInstance( processInstance.getId() );
assertNotNull( processInstance );
ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession( id, kbase, null, env );
ksession.getWorkItemManager().completeWorkItem( workItem.getId(),
null );
workItem = handler.getWorkItem();
assertNull( workItem );
ksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession( id, kbase, null, env );
processInstance = ksession.getProcessInstance( processInstance.getId() );
assertEquals( origNumObjects + 1,
ksession.getObjects().size() );
for ( Object o : ksession.getObjects() ) {
logger.debug( o.toString() );
}