Mario Fusco created DROOLS-601:
----------------------------------
Summary: Using queries in combination with agenda-groups leads to wrong
firings
Key: DROOLS-601
URL:
https://issues.jboss.org/browse/DROOLS-601
Project: Drools
Issue Type: Bug
Affects Versions: 6.2.0.Beta1, 6.1.0.Final
Reporter: Mario Fusco
Assignee: Mark Proctor
When running the following test case:
{code}
@Test
public void testQueryWithAgendaGroup() {
String drl =
"package org.drools.test; " +
"global java.util.List list; " +
"query foo( Integer $i ) " +
" $i := Integer() " +
"end " +
"rule Detect " +
"agenda-group 'one' " +
"when " +
" foo( $i ; ) " +
"then " +
" list.add( $i ); " +
"end " +
"rule OnceMore " +
"agenda-group 'two' " +
"no-loop " +
"when " +
" $i : Integer() " +
"then " +
" update( $i );" +
"end " +
"";
KieHelper helper = new KieHelper();
helper.addContent( drl, ResourceType.DRL );
KieSession kieSession = helper.build().newKieSession();
List<Integer> list = new ArrayList<Integer>();
kieSession.setGlobal( "list", list );
FactHandle handle = kieSession.insert( 42 );
Agenda agenda = kieSession.getAgenda();
agenda.getAgendaGroup("two").setFocus();
agenda.getAgendaGroup("one").setFocus();
kieSession.fireAllRules();
assertEquals( Arrays.asList( 42 ), list );
kieSession.delete( handle );
kieSession.insert( -99 );
agenda.getAgendaGroup("two").setFocus();
agenda.getAgendaGroup("one").setFocus();
kieSession.fireAllRules();
assertEquals( Arrays.asList( 42, -99 ), list );
}
{code}
The "Detect" rule, the one containing the query, fires twice with 42 even if the
second time that fact shold be already been deleted. In particular the sequence of
relevant events when running this test is the following:
1. 1st fire, 42 updated
1.1. process update in PhreakRuleTerminalNode of OnceMore
1.1.1. blocked by no-loop
1.2. process update in PhreakQueryTerminalNode
1.2.1. update added to leftTupleSets of queryResult
1.2.2. rule Detect doesn't fire again because it is in an inactive agenda-group
2. 42 deleted
2.1. the deleted factHandle refers to the RTNLeftTuple that is then added to the deleted
leftTupleSets of the LIANode having as sink the RTN of rule OnceMore. Unfortunately
there's no relationship between the deleted factHandle and the query activated by that
fact.
3. 2nd fire
3.1. now AG "one" has focus so evaluates PhreakRuleTerminalNode of Detect
using the updated leftTuple of point 1.2.1. - ERROR!!!
3.2. process deleted 42 and inserted -99 in PhreakRuleTerminalNode of OnceMore
3.3. process deleted 42 and inserted -99 in PhreakQueryTerminalNode, doesn't fire it
because AG "one" is not active
--
This message was sent by Atlassian JIRA
(v6.3.1#6329)