// how to configure the clock?
SessionPseudoClock clock = (SessionPseudoClock) wm.getSessionClock();
clock.advanceTime( 5,
TimeUnit.SECONDS ); // 5 seconds
EventFactHandle handle1 = (EventFactHandle) wm.insert( new OrderEvent( "1",
"customer A",
70 ) );
assertEquals( 5000,
handle1.getStartTimestamp() );
assertEquals( 0,
handle1.getDuration() );
// wm = SerializationHelper.getSerialisedStatefulSession( wm );
// results = (List) wm.getGlobal( "results" );
// clock = (SessionPseudoClock) wm.getSessionClock();
wm.fireAllRules();
assertEquals( 1,
results.size() );
assertEquals( 70,
((Number) results.get( 0 )).intValue() );
// advance clock and assert new data
clock.advanceTime( 10,
TimeUnit.SECONDS ); // 10 seconds
EventFactHandle handle2 = (EventFactHandle) wm.insert( new OrderEvent( "2",
"customer A",
60 ) );
assertEquals( 15000,
handle2.getStartTimestamp() );
assertEquals( 0,
handle2.getDuration() );
wm.fireAllRules();
assertEquals( 2,
results.size() );
assertEquals( 65,
((Number) results.get( 1 )).intValue() );
// advance clock and assert new data
clock.advanceTime( 10,
TimeUnit.SECONDS ); // 10 seconds
EventFactHandle handle3 = (EventFactHandle) wm.insert( new OrderEvent( "3",
"customer A",
50 ) );
assertEquals( 25000,
handle3.getStartTimestamp() );
assertEquals( 0,
handle3.getDuration() );
wm.fireAllRules();
assertEquals( 3,
results.size() );
assertEquals( 60,
((Number) results.get( 2 )).intValue() );
// advance clock and assert new data
clock.advanceTime( 10,
TimeUnit.SECONDS ); // 10 seconds
EventFactHandle handle4 = (EventFactHandle) wm.insert( new OrderEvent( "4",
"customer A",
25 ) );
assertEquals( 35000,
handle4.getStartTimestamp() );
assertEquals( 0,
handle4.getDuration() );
wm.fireAllRules();
// first event should have expired, making average under the rule threshold, so no additional rule fire
assertEquals( 3,
results.size() );
// advance clock and assert new data
clock.advanceTime( 10,
TimeUnit.SECONDS ); // 10 seconds
EventFactHandle handle5 = (EventFactHandle) wm.insert( new OrderEvent( "5",
"customer A",
70 ) );
assertEquals( 45000,
handle5.getStartTimestamp() );
assertEquals( 0,
handle5.getDuration() );
// wm = SerializationHelper.serializeObject(wm);
wm.fireAllRules();
// still under the threshold, so no fire
assertEquals( 3,
results.size() );
// advance clock and assert new data
clock.advanceTime( 10,
TimeUnit.SECONDS ); // 10 seconds
EventFactHandle handle6 = (EventFactHandle) wm.insert( new OrderEvent( "6",
"customer A",
115 ) );
assertEquals( 55000,
handle6.getStartTimestamp() );
assertEquals( 0,