}
Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
final StatefulSession session = ruleBase.newStatefulSession();
List<Message> myList = new ArrayList<Message>();
session.setGlobal("myList", myList);
new Thread(new Runnable() {
public void run() {
session.fireUntilHalt();
}
}).start();
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", 800);
params.put("y", 200);
ProcessInstance processInstance = ( ProcessInstance )
session.startProcess("org.drools.timer", params);
assertEquals(0, myList.size());
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
assertEquals(1, ((InternalProcessRuntime) ((InternalWorkingMemory) session).getProcessRuntime()).getTimerManager().getTimers().size());
session.halt();
final StatefulSession session2 = getSerialisedStatefulSession( session );
myList = (List<Message>) session2.getGlobal( "myList" );
new Thread(new Runnable() {
public void run() {
session2.fireUntilHalt();
}
}).start();
processInstance = ( ProcessInstance ) session2.getProcessInstance( processInstance.getId() );
assertEquals(1, ((InternalProcessRuntime) ((InternalWorkingMemory) session2).getProcessRuntime()).getTimerManager().getTimers().size());
// test that the delay works
try {
Thread.sleep(400);
} catch (InterruptedException e) {
// do nothing
}
assertEquals(0, myList.size());
// test that the period works
try {
Thread.sleep(1300);
} catch (InterruptedException e) {
// do nothing
}
assertEquals(5, myList.size());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
session2.halt();
}