try {
// First interaction
clock.advanceTime( 5,
TimeUnit.SECONDS ); // 5 seconds
ksession.insert( new OrderEvent( "1",
"customer A",
70 ) );
ksession.fireAllRules();
assertEquals( 1,
timeResults.size() );
assertEquals( 1,
timeResults.get( 0 ).intValue() );
assertEquals( 1,
lengthResults.size() );
assertEquals( 1,
lengthResults.get( 0 ).intValue() );
// Second interaction: advance clock and assert new data
clock.advanceTime( 10,
TimeUnit.SECONDS ); // 10 seconds
ksession.insert( new OrderEvent( "2",
"customer A",
60 ) );
ksession.fireAllRules();
assertEquals( 2,
timeResults.size() );
assertEquals( 2,
timeResults.get( 1 ).intValue() );
assertEquals( 2,
lengthResults.size() );
assertEquals( 2,
lengthResults.get( 1 ).intValue() );
// Third interaction: advance clock and assert new data
clock.advanceTime( 10,
TimeUnit.SECONDS ); // 10 seconds
ksession.insert( new OrderEvent( "3",
"customer A",
50 ) );
ksession.fireAllRules();
assertEquals( 3,
timeResults.size() );
assertEquals( 3,
timeResults.get( 2 ).intValue() );
assertEquals( 3,
lengthResults.size() );
assertEquals( 3,
lengthResults.get( 2 ).intValue() );
// Fourth interaction: advance clock and assert new data
clock.advanceTime( 10,
TimeUnit.SECONDS ); // 10 seconds
ksession.insert( new OrderEvent( "4",
"customer A",
25 ) );
ksession.fireAllRules();
// first event should have expired now
assertEquals( 4,
timeResults.size() );
assertEquals( 3,
timeResults.get( 3 ).intValue() );
assertEquals( 4,
lengthResults.size() );
assertEquals( 3,
lengthResults.get( 3 ).intValue() );
// Fifth interaction: advance clock and assert new data
clock.advanceTime( 5,
TimeUnit.SECONDS ); // 10 seconds
ksession.insert( new OrderEvent( "5",
"customer A",
70 ) );
ksession.fireAllRules();
assertEquals( 5,