public void testAgendaGroupLockOnActive() {
final AbstractWorkingMemory workingMemory = (AbstractWorkingMemory) ruleBase.newStatefulSession();
final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
// create the agendaGroup
final InternalAgendaGroup agendaGroup = new AgendaGroupQueueImpl("agendaGroup",
ruleBase);
agenda.addAgendaGroup(agendaGroup);
// 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 RuleTerminalNodeLeftTuple tuple = new RuleTerminalNodeLeftTuple(new DefaultFactHandle(1,
"cheese"),
node,
true);
final PropagationContext context = pctxFactory.createPropagationContext(0,
PropagationContext.INSERTION,
rule,
null,
new DefaultFactHandle());
// When both the rule is lock-on-active and the agenda group is active, activations should be ignored
rule.setLockOnActive(true);
((InternalRuleFlowGroup) agendaGroup).setAutoDeactivate(false);
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());
}