[
http://jira.jboss.com/jira/browse/JBRULES-387?page=all ]
Geoffrey De Smet updated JBRULES-387:
-------------------------------------
Attachment: JBRULES-387-testcase-trunk.patch
I 've attached a patch for the drools trunk which has a testcase that isolates the
problem.
Here is it exactly what I attached in that .patch file:
public void testExists387() throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader(
getClass().getResourceAsStream( "test_Exists387.drl" ) ) );
final Package pkg = builder.getPackage();
final RuleBase ruleBase = getRuleBase();
ruleBase.addPackage( pkg );
final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
Person p1 = new Person( "p1", "stilton", 20 );
p1.setStatus("europe");
workingMemory.assertObject( p1 );
Person p2 = new Person( "p2", "stilton", 30 );
p2.setStatus("europe");
FactHandle c2FactHandle = workingMemory.assertObject( p2 );
Person p3 = new Person( "p3", "stilton", 40 );
p3.setStatus("europe");
workingMemory.assertObject( p3 );
workingMemory.fireAllRules();
List cheeseList = workingMemory.getObjects( Cheese.class );
assertEquals( 2, cheeseList.size() );
p2.setStatus("america");
workingMemory.modifyObject( c2FactHandle, p2 );
workingMemory.fireAllRules();
cheeseList = workingMemory.getObjects( Cheese.class );
// cheeseList still contains a cheese for the person with a age of 30
// but that should have been logically retracted
assertEquals( 1, cheeseList.size() );
}
package com.sample
import org.drools.Cheese
import org.drools.Person
rule "Supply cheese for every 2 persons with the same status"
when
p : Person($status : status, $age : age)
exists Person(status == $status, age > $age);
then
assertLogical(new Cheese("Cheese for person with age " + $age, 10));
end
Using exists together with facts of the same type can break
auto-retraction of logically asserted objects
---------------------------------------------------------------------------------------------------------
Key: JBRULES-387
URL:
http://jira.jboss.com/jira/browse/JBRULES-387
Project: JBoss Rules
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: Reteoo
Affects Versions: 3.0.3
Environment: Windows XP, java 1.5
Reporter: Geoffrey De Smet
Assigned To: Edson Tirelli
Attachments: JBRULES-387-testcase-trunk.patch, JBRULES-387.zip, screenshot-1.jpg
I assert 3 Lesson objects in my memory.
I got 1 rule, which creates logically asserted HardConstraint objects.
In some cases (not always), those logically asserted objects aren't retracted when
they should be, which leads to HardContaints just adding more and more. They aren't
logically retracted as they should be when:
- exists is combined with fact selections of the same class
- the modified object trigged the rule by the exists part, not by the the fact selection
part
I 'll attach a maven 2 configured proof of concept to repreduce it:
mvn install eclipse:eclipse idea:idea
Run net.sf.tabudrool.app.TabudroolApp
Click "Load unsolvedSchedule2.xml" (the second button on the left)
Notice the HardConstraint = 2 at the bottom
Click "Move lesson"
Move "[net.sf.tabudrool.domain.Lesson-1] 0: teacher0 + group0" to timeslot 1.
Notice that HardConstraint = 3 instead 1 at the bottom,
because - as you can see in the log - the previous HardConstraint objects didn't get
retracted.
Here's the drl:
rule teacherCanOnlyTeachOneGroupAtATime
when
$lesson : Lesson($id : id, $teacher : teacher, $timeslot : timeslot)
exists Lesson(id > $id, teacher == $teacher, timeslot == $timeslot)
then
System.out.println(" teacherCanOnlyTeachOneGroupAtATime: " + $lesson);
assertLogical(new HardConstraint(1));
end
Here's a log:
teacherCanOnlyTeachOneGroupAtATime: [net.sf.tabudrool.domain.Lesson-1] 0: teacher0 +
group0
teacherCanOnlyTeachOneGroupAtATime: [net.sf.tabudrool.domain.Lesson-0] 0: teacher0 +
group0
[ObjectAsserted: handle=[fid:9:9];
object=net.sf.tabudrool.domain.HardConstraint@1f42731]
[ObjectAsserted: handle=[fid:10:10];
object=net.sf.tabudrool.domain.HardConstraint@53abbb]
2006-08-03 19:24:35,796 [AWT-EventQueue-0] INFO
net.sf.tabudrool.swingui.WorkflowFrame$MoveAction.actionPerformed(WorkflowFrame.java:201)
Moving [[net.sf.tabudrool.domain.Lesson-1] 0: teacher0 + group0] to [1]
[ObjectModified: handle=[fid:7:11]; old_object=[net.sf.tabudrool.domain.Lesson-1] 1:
teacher0 + group0; new_object=[net.sf.tabudrool.domain.Lesson-1] 1: teacher0 + group0]
teacherCanOnlyTeachOneGroupAtATime: [net.sf.tabudrool.domain.Lesson-1] 1: teacher0 +
group0
[ObjectAsserted: handle=[fid:11:12];
object=net.sf.tabudrool.domain.HardConstraint@1c8b884]
As you can see: net.sf.tabudrool.domain.HardConstraint@1f42731 and
net.sf.tabudrool.domain.HardConstraint@53abbb weren't retracted (at least one should
be).
Earlier this week I posted a dud jira issue, as far as I can tell from discussing on irc
(with conan), this looks like a genuine issue...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira