KnowledgeSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption( ClockTypeOption.get( "pseudo" ) );
List list = new ArrayList();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession( conf, null );
PseudoClockScheduler timeService = ( PseudoClockScheduler ) ksession.<SessionClock>getSessionClock();
DateFormat df = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" );
Date date = df.parse( "2009-01-01T00:00:00.000-0000" );
ksession.getCalendars().set( "cal1", calTrue );
ksession.getCalendars().set( "cal2", calTrue );
timeService.advanceTime( date.getTime(), TimeUnit.MILLISECONDS );
ksession.setGlobal( "list", list );
ksession.insert( "o1" );
ksession.fireAllRules();
assertEquals( 1, list.size() );
ksession.getCalendars().set( "cal2", calFalse );
timeService.advanceTime( 10, TimeUnit.SECONDS );
ksession.insert( "o2" );
ksession.fireAllRules();
assertEquals( 1, list.size() );
ksession.getCalendars().set( "cal1", calFalse );
timeService.advanceTime( 10, TimeUnit.SECONDS );
ksession.insert( "o3" );
ksession.fireAllRules();
assertEquals( 1, list.size() );
ksession.getCalendars().set( "cal1", calTrue );
ksession.getCalendars().set( "cal2", calTrue );
timeService.advanceTime( 30, TimeUnit.SECONDS );
ksession.insert( "o4" );
ksession.fireAllRules();
assertEquals( 2, list.size() );
}