use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class JbpmJUnitTestCase method createKnowledgeSession.
protected KieSession createKnowledgeSession() {
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession result = runtime.getKieSession();
if (sessionPersistence) {
logService = new JPAAuditLogService(environment.getEnvironment());
} else {
logger = new WorkingMemoryInMemoryLogger((StatefulKnowledgeSession) result);
}
// knowledgeSessionSetLocal.get().add(result);
return result;
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class ProcessMain method main.
public static final void main(String[] args) throws Exception {
JBPMHelper.startUp();
// load up the knowledge base
KieBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = JBPMHelper.newStatefulKnowledgeSession(kbase);
// start a new process instance
ksession.startProcess("com.sample.bpmn.hello");
logger.info("Process started ...");
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class SerializedTimerRollbackTest method testSerizliableTestsWithExternalRollback.
@Test
public void testSerizliableTestsWithExternalRollback() {
try {
createRuntimeManager("org/jbpm/test/functional/timer/HumanTaskWithBoundaryTimer.bpmn");
RuntimeEngine runtimeEngine = getRuntimeEngine();
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
logger.debug("Created knowledge session");
TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
List<Long> committedProcessInstanceIds = new ArrayList<Long>();
for (int i = 0; i < 10; i++) {
tm.begin();
Map<String, Object> params = new HashMap<String, Object>();
params.put("test", "john");
logger.debug("Creating process instance: {}", i);
ProcessInstance pi = ksession.startProcess("PROCESS_1", params);
if (i % 2 == 0) {
committedProcessInstanceIds.add(pi.getId());
tm.commit();
} else {
tm.rollback();
}
}
Connection c = getDs().getConnection();
Statement st = c.createStatement();
ResultSet rs = st.executeQuery("select rulesbytearray from sessioninfo");
rs.next();
Blob b = rs.getBlob("rulesbytearray");
assertNotNull(b);
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
ProtobufMarshaller marshaller = new ProtobufMarshaller(builder.newKieBase(), new MarshallingConfigurationImpl());
StatefulKnowledgeSession session = marshaller.unmarshall(b.getBinaryStream());
assertNotNull(session);
TimerManager timerManager = ((InternalProcessRuntime) ((InternalKnowledgeRuntime) session).getProcessRuntime()).getTimerManager();
assertNotNull(timerManager);
Collection<TimerInstance> timers = timerManager.getTimers();
assertNotNull(timers);
assertEquals(5, timers.size());
for (TimerInstance timerInstance : timers) {
assertTrue(committedProcessInstanceIds.contains(timerInstance.getProcessInstanceId()));
ksession.abortProcessInstance(timerInstance.getProcessInstanceId());
}
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(0, tasks.size());
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown");
}
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class ProcessMarshallingTest method testMarshallingProcessInstanceWithTimer.
@Test
@Ignore
public void testMarshallingProcessInstanceWithTimer() throws Exception {
String process = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"ruleflow\" id=\"com.sample.ruleflow\" package-name=\"com.sample\" >\n" + "\n" + " <header>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <timerNode id=\"4\" name=\"Timer\" delay=\"200\" />\n" + " <end id=\"3\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"4\" />\n" + " <connection from=\"4\" to=\"3\" />\n" + " </connections>\n" + "\n" + "</process>\n";
builder.addProcessFromXml(new StringReader(process));
final KieSession session = createKieSession(builder.getPackages());
session.startProcess("com.sample.ruleflow", null);
assertEquals(1, session.getProcessInstances().size());
session.halt();
final StatefulKnowledgeSession session2 = getSerialisedStatefulKnowledgeSession(session);
int sleeps = 3;
int procInstsAlive = session2.getProcessInstances().size();
while (procInstsAlive > 0 && sleeps > 0) {
Thread.sleep(1000);
--sleeps;
procInstsAlive = session2.getProcessInstances().size();
}
assertEquals(0, session2.getProcessInstances().size());
session2.halt();
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class ProcessMarshallingTest method testTimerOnUnmarshalledSession.
@Test
public void testTimerOnUnmarshalledSession() throws Exception {
String process = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"ruleflow\" id=\"com.sample.ruleflow\" package-name=\"com.sample\" >\n" + "\n" + " <header>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <timerNode id=\"4\" name=\"Timer\" delay=\"1000\" />\n" + " <end id=\"3\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"4\" />\n" + " <connection from=\"4\" to=\"3\" />\n" + " </connections>\n" + "\n" + "</process>\n";
builder.addProcessFromXml(new StringReader(process));
KieSession session = createKieSession(builder.getPackages());
session.startProcess("com.sample.ruleflow", null);
// serialize session
Marshaller marshaller = MarshallerFactory.newMarshaller(session.getKieBase());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
marshaller.marshall(baos, session);
byte[] b1 = baos.toByteArray();
baos.close();
// hope that timer hasn't fired yet?
assertEquals(1, session.getProcessInstances().size());
// dispose of session
session.dispose();
// deserialize session
ByteArrayInputStream bais = new ByteArrayInputStream(b1);
StatefulKnowledgeSession session2 = (StatefulKnowledgeSession) marshaller.unmarshall(bais);
// make sure time job runs
int sleeps = 3;
int procInstsAlive = session2.getProcessInstances().size();
while (procInstsAlive > 0 && sleeps > 0) {
Thread.yield();
Thread.sleep(1000);
--sleeps;
procInstsAlive = session2.getProcessInstances().size();
}
// verify
assertEquals(0, session2.getProcessInstances().size());
}
Aggregations