private PoolingDataSource ds1;
private EntityManagerFactory emf;
@Test
public void testTimerRuleAfterIntReloadSession() throws Exception {
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSession ksession = createSession( kbase );
// must advance time or it won't save.
SessionPseudoClock clock = (SessionPseudoClock) ksession.<SessionClock>getSessionClock();
clock.advanceTime( 300,
TimeUnit.MILLISECONDS );
// if we do not call 'ksession.fireAllRules()', this test will run successfully.
ksession.fireAllRules();
clock = (SessionPseudoClock) ksession.<SessionClock>getSessionClock();
clock.advanceTime( 300,
TimeUnit.MILLISECONDS );
ksession = disposeAndReloadSession( ksession,
kbase );
clock = (SessionPseudoClock) ksession.<SessionClock>getSessionClock();
clock.advanceTime( 300,
TimeUnit.MILLISECONDS );
// build timer rule, if the rule is fired, the list size will increase every 500ms
String timerRule = "package org.drools.test\n" +
"global java.util.List list \n" +
"rule TimerRule \n" +
" timer (int:1000 500) \n" +
"when \n" + "then \n" +
" list.add(list.size()); \n" +
" end";
Resource resource = ResourceFactory.newByteArrayResource( timerRule.getBytes() );
Collection<KnowledgePackage> kpackages = buildKnowledgePackage( resource,
ResourceType.DRL );
kbase.addKnowledgePackages( kpackages );
clock = (SessionPseudoClock) ksession.<SessionClock>getSessionClock();
clock.advanceTime( 10,
TimeUnit.MILLISECONDS );
ksession.fireAllRules();