[
https://issues.jboss.org/browse/JBRULES-1602?page=com.atlassian.jira.plug...
]
RH Bugzilla Integration commented on JBRULES-1602:
--------------------------------------------------
Mark Proctor <mproctor(a)redhat.com> made a comment on [bug
810407|https://bugzilla.redhat.com/show_bug.cgi?id=810407]
cherry-picked into 5.3.x
mdproctor@M6400 /c/dev/drools54/drools (5.3.x|CHERRY-PICKING)
$ git commit
[5.3.x fbb6258] JBRULES-1602 The order of RHS statements shouldn't affect behavior
(insertLogical) (cherry picked from c
ommit e002b0e0dc98dcaa9b69fb49b6640f8787d7ff24)
8 files changed, 152 insertions(+), 15 deletions(-)
create mode 100644 drools-compiler/src/test/java/org/drools/YoungestFather.java
mdproctor@M6400 /c/dev/drools54/drools (5.3.x)
$ git cherry-pick -x 12b38cb8f33adbca0eb17afc13a9b9d190dd9ebf
[5.3.x 43f76cd] JBRULES-1602 The order of RHS statements shouldn't affect behavior
(insertLogical) (cherry picked from c
ommit 12b38cb8f33adbca0eb17afc13a9b9d190dd9ebf)
2 files changed, 20 insertions(+), 0 deletions(-)
mdproctor@M6400 /c/dev/drools54/drools (5.3.x)
$ git cherry-pick -x 0127924e8720621172551e47cb362018df07b716
[5.3.x 0ff734e] JBRULES-1602 The order of RHS statements shouldn't affect behavior
(insertLogical) (cherry picked from c
ommit 0127924e8720621172551e47cb362018df07b716)
2 files changed, 20 insertions(+), 0 deletions(-)
mdproctor@M6400 /c/dev/drools54/drools (5.3.x)
$ git push
Counting objects: 95, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (46/46), done.
Writing objects: 100% (59/59), 8.38 KiB, done.
Total 59 (delta 34), reused 7 (delta 5)
To git@github.com:droolsjbpm/drools.git
02700fe..0ff734e 5.3.x -> 5.3.x
The order of RHS statements shouldn't affect behavior
(insertLogical)
---------------------------------------------------------------------
Key: JBRULES-1602
URL:
https://issues.jboss.org/browse/JBRULES-1602
Project: Drools
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: drools-core
Affects Versions: 4.0.7
Environment: Drools 4.0.7 & 4.0.4, Java5, eclipse compiler, windows XP.
Reporter: Patrick Gras
Assignee: Edson Tirelli
Fix For: 5.4.0.CR1
I have a class 'Cat' that is dynamic (JavaBean with PropertyChangeSupport ) with
only a 'name' attribute.
Then I have the following rule:
rule "test"
when
$cat:Cat( name == "tom" )
then
$cat.setName("cat");
insertLogical(new String("test"));
end
When I test the rule against a Cat named tom, the logical inserted fact is not retracted.
(So the fact is inserted because the rule matches, but is not retracted even if the rule
is no more matching at the end.)
If I change the order of the RHS, it works fine. The fact is inserted and then retracted.
rule "test"
when
$cat:Cat( name == "tom" )
then
insertLogical(new String("test"));
$cat.setName("cat");
end
So the behavior depends on the ordering of the RHS statements.
Here is a complete example to show the problem:
public class Cat {
private String name;
protected PropertyChangeSupport changes = new PropertyChangeSupport(this);
public Cat(String name) {
super();
this.name = name;
}
public String getName() {
return this.name;
}
public void setName(String name) {
final String oldName = this.name;
this.name = name;
this.changes.firePropertyChange("name", oldName, name);
}
public void addPropertyChangeListener(final PropertyChangeListener listener) {
this.changes.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(
final PropertyChangeListener listener) {
this.changes.removePropertyChangeListener(listener);
}
}
public class RHSOrderingTest {
private static final String PACKAGE = "package ch.generali.pgr.rule ";
private static final String IMPORT = "import ch.generali.pgr.rules.Cat ";
private static final String WHEN = "rule \"test ok\" when $cat:Cat( name
== \"tom\" ) ";
private static final String THEN_OK = "then insertLogical(Integer.valueOf(1));
$cat.setName(\"cat\"); end";
private static final String THEN_KO = "then $cat.setName(\"cat\");
insertLogical(Integer.valueOf(1)); end";
private static final String RULE_OK = PACKAGE + IMPORT + WHEN + THEN_OK;
private static final String RULE_KO = PACKAGE + IMPORT + WHEN + THEN_KO;
private static final String QUERY = "query \"My test Integer\" integer :
Integer( intValue == 1 ) end";
public static void main(String[] args) {
boolean ok_1 = testWithRule(RULE_OK);
boolean ok_2 = testWithRule(RULE_KO);
System.out.println((ok_1 ? "SUCCESS: " : "FAILED: ") + THEN_OK);
System.out.println((ok_2 ? "SUCCESS: " : "FAILED: ") + THEN_KO);
}
private static boolean testWithRule(String rule) {
Cat tom = new Cat("tom");
RuleBase rb = createRuleBase(rule + "\n" + QUERY);
WorkingMemory wm = rb.newStatefulSession();
wm.insert(tom, true);
wm.fireAllRules();
QueryResults results = wm.getQueryResults("My test Integer");
return results.size() == 0;
}
private static RuleBase createRuleBase(String rules) {
try {
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
PackageBuilder packageBuilder = new PackageBuilder(conf);
Reader source = new StringReader(rules);
packageBuilder.addPackageFromDrl(source);
Package pkg = packageBuilder.getPackage();
ruleBase.addPackage(pkg);
return ruleBase;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira