ksession2.addEventListener( ael2 );
// -------------
// first, check the non-serialized session
// -------------
ksession1.insert( new Sensor( 10,
10 ) );
ksession1.fireAllRules();
ArgumentCaptor<AfterActivationFiredEvent> aafe1 = ArgumentCaptor.forClass( AfterActivationFiredEvent.class );
verify( ael1,
times( 1 ) ).afterActivationFired( aafe1.capture() );
List<AfterActivationFiredEvent> events1 = aafe1.getAllValues();
assertThat( events1.get( 0 ).getActivation().getDeclarationValue( "$avg" ),
is( (Object) 10 ) );
ksession1.insert( new Sensor( 20,
20 ) );
ksession1.fireAllRules();
verify( ael1,
times( 2 ) ).afterActivationFired( aafe1.capture() );
assertThat( events1.get( 1 ).getActivation().getDeclarationValue( "$avg" ),
is( (Object) 15 ) );
ksession1.insert( new Sensor( 30,
30 ) );
ksession1.fireAllRules();
verify( ael1,
times( 3 ) ).afterActivationFired( aafe1.capture() );
assertThat( events1.get( 2 ).getActivation().getDeclarationValue( "$avg" ),
is( (Object) 25 ) );
ksession1.dispose();
// -------------
// now we check the serialized session
// -------------
ArgumentCaptor<AfterActivationFiredEvent> aafe2 = ArgumentCaptor.forClass( AfterActivationFiredEvent.class );
ksession2.insert( new Sensor( 10,
10 ) );
ksession2.fireAllRules();
verify( ael2,
times( 1 ) ).afterActivationFired( aafe2.capture() );
List<AfterActivationFiredEvent> events2 = aafe2.getAllValues();
assertThat( events2.get( 0 ).getActivation().getDeclarationValue( "$avg" ),
is( (Object) 10 ) );
ksession2.insert( new Sensor( 20,
20 ) );
ksession2.fireAllRules();
verify( ael2,
times( 2 ) ).afterActivationFired( aafe2.capture() );
assertThat( events2.get( 1 ).getActivation().getDeclarationValue( "$avg" ),
is( (Object) 15 ) );
ksession2.insert( new Sensor( 30,
30 ) );
ksession2.fireAllRules();
verify( ael2,
times( 3 ) ).afterActivationFired( aafe2.capture() );
assertThat( events2.get( 2 ).getActivation().getDeclarationValue( "$avg" ),