splitRule2,
splitRule2.getLhs(),
buildContext );
// proces instance
final RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
processInstance.setWorkingMemory( workingMemory );
processInstance.setProcess( process );
assertEquals( ProcessInstance.STATE_PENDING,
processInstance.getState() );
final RuleFlowGroupImpl ruleFlowGroup0 = (RuleFlowGroupImpl) agenda.getRuleFlowGroup( "rule-flow-group-0" );
final RuleFlowGroupImpl ruleFlowGroup1 = (RuleFlowGroupImpl) agenda.getRuleFlowGroup( "rule-flow-group-1" );
final RuleFlowGroupImpl ruleFlowGroup2 = (RuleFlowGroupImpl) agenda.getRuleFlowGroup( "rule-flow-group-2" );
final RuleFlowGroupImpl ruleFlowGroup3 = (RuleFlowGroupImpl) agenda.getRuleFlowGroup( "rule-flow-group-3" );
final LeftTuple tuple0 = new LeftTuple( new DefaultFactHandle( 1,
"cheese" ),
null,
true );
node0.assertLeftTuple( tuple0,
context0,
workingMemory );
final LeftTuple tuple1 = new LeftTuple( new DefaultFactHandle( 1,
"cheese" ),
null,
true );
node0.assertLeftTuple( tuple1,
context0,
workingMemory );
final LeftTuple tuple2 = new LeftTuple( new DefaultFactHandle( 1,
"cheese" ),
null,
true );
node1.assertLeftTuple( tuple2,
context0,
workingMemory );
final LeftTuple tuple3 = new LeftTuple( new DefaultFactHandle( 1,
"cheese" ),
null,
true );
node2.assertLeftTuple( tuple3,
context0,
workingMemory );
final LeftTuple tuple4 = new LeftTuple( new DefaultFactHandle( 1,
"cheese" ),
null,
true );
node3.assertLeftTuple( tuple4,
context0,
workingMemory );
final LeftTuple splitTuple1 = new LeftTuple( new DefaultFactHandle( 1,
"cheese" ),
null,
true );
splitNode1.assertLeftTuple( splitTuple1,
context0,
workingMemory );
final LeftTuple splitTuple2 = new LeftTuple( new DefaultFactHandle( 1,
"cheese" ),
null,
true );
splitNode2.assertLeftTuple( splitTuple2,
context0,
workingMemory );
final RuleFlowGroupImpl systemRuleFlowGroup = (RuleFlowGroupImpl) agenda.getRuleFlowGroup( "DROOLS_SYSTEM" );
// RuleFlowGroups should be populated, but the agenda shouldn't
assertEquals( 2,
ruleFlowGroup0.size() );
assertEquals( 1,
ruleFlowGroup1.size() );
assertEquals( 1,
ruleFlowGroup2.size() );
assertEquals( 1,
ruleFlowGroup3.size() );
assertEquals( 2,
systemRuleFlowGroup.size() );
assertEquals( 0,
agenda.agendaSize() );
// Activate process instance, the activations stay in the group,
// but should now also be in the Agenda
processInstance.start();
assertEquals( ProcessInstance.STATE_ACTIVE,
processInstance.getState() );
assertEquals( 2,
ruleFlowGroup0.size() );
assertEquals( 2,
agenda.agendaSize() );
// As we fire each rule they are removed from both the Agenda and the RuleFlowGroup
agenda.fireNextItem( null );
assertEquals( 1,
ruleFlowGroup0.size() );
assertEquals( 1,
agenda.agendaSize() );
// XOR split should activate group1
agenda.fireNextItem( null );
workingMemory.executeQueuedActions();
assertEquals( 0,
ruleFlowGroup0.size() );
assertEquals( 1,
ruleFlowGroup1.size() );
assertEquals( 1,
ruleFlowGroup2.size() );
assertEquals( 1,
agenda.agendaSize() );
// executing group1, XOR join should activate group3
agenda.fireNextItem( null );
workingMemory.executeQueuedActions();
assertEquals( 0,
ruleFlowGroup1.size() );
assertEquals( 1,
ruleFlowGroup2.size() );
assertEquals( 1,
ruleFlowGroup3.size() );
assertEquals( 1,
agenda.agendaSize() );
// executing rule3, and finishing execution
agenda.fireNextItem( null );
workingMemory.executeQueuedActions();
assertEquals( 0,
ruleFlowGroup0.size() );
assertEquals( 0,
ruleFlowGroup1.size() );
assertEquals( 1,
ruleFlowGroup2.size() );
assertEquals( 0,
ruleFlowGroup3.size() );
assertEquals( 0,
agenda.agendaSize() );
assertEquals( ProcessInstance.STATE_COMPLETED,
processInstance.getState() );
}