timeService.advanceTime( new Date().getTime(), TimeUnit.MILLISECONDS );
List list = new ArrayList();
ksession.setGlobal( "list", list );
FactA fact1 = new FactA();
fact1.setField1( "f1" );
fact1.setField2( 500 );
fact1.setField4( 1000 );
FactHandle fh = (FactHandle) ksession.insert (fact1 );
ksession.fireAllRules();
assertEquals( 0, list.size() );
timeService.advanceTime( 1100, TimeUnit.MILLISECONDS );
ksession.fireAllRules();
assertEquals( 1, list.size() );
assertEquals( fact1, list.get( 0 ) );
timeService.advanceTime( 1100, TimeUnit.MILLISECONDS );
ksession.fireAllRules();
assertEquals( 2, list.size() );
assertEquals( fact1, list.get( 1 ) );
timeService.advanceTime( 400, TimeUnit.MILLISECONDS );
ksession.fireAllRules();
assertEquals( 3, list.size() );
assertEquals( fact1, list.get( 2 ) );
list.clear();
// the activation state of the rule is not changed so the timer isn't reset
// since the timer alredy fired it will only use only the period that now will be set to 2000
fact1.setField2( 300 );
fact1.setField4( 2000 );
ksession.update( fh, fact1 );
ksession.fireAllRules();
// 100 has passed of the 1000, from the previous schedule
// so that should be deducted from the 2000 period above, meaning