final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
// create the agendaGroup
final InternalAgendaGroup agendaGroup = new BinaryHeapQueueAgendaGroup( "agendaGroup",
ruleBase );
agenda.addAgendaGroup( agendaGroup );
final LeftTupleImpl tuple = new LeftTupleImpl( new DefaultFactHandle( 1,
"cheese" ),
null,
true );
// create a rule for the agendaGroup
final Rule rule = new Rule( "test-rule",
"agendaGroup" );
final RuleTerminalNode node = new RuleTerminalNode( 2,
new MockTupleSource( 2 ),
rule,
rule.getLhs(),
0,
buildContext );
final PropagationContext context = new PropagationContextImpl( 0,
PropagationContext.ASSERTION,
rule,
null,
null );
// When both the rule is lock-on-active and the agenda group is active, activations should be ignored
rule.setLockOnActive( true );
agendaGroup.setActive( true );
node.assertLeftTuple( tuple,
context,
workingMemory );
// activation should be ignored
assertEquals( 0,
agendaGroup.size() );
// lock-on-active is now false so activation should propagate
rule.setLockOnActive( false );
node.assertLeftTuple( tuple,
context,
workingMemory );
agenda.unstageActivations();
assertEquals( 1,
agendaGroup.size() );
// even if lock-on-active is true, unless the agenda group is active the activation will still propagate
rule.setLockOnActive( true );
agendaGroup.setActive( false );
node.assertLeftTuple( tuple,
context,
workingMemory );
agenda.unstageActivations();
assertEquals( 2,
agendaGroup.size() );
}