[jboss-jira] [JBoss JIRA] Closed: (JBRULES-1179) Premature rule execution
Mark Proctor (JIRA)
jira-events at lists.jboss.org
Wed Sep 12 22:24:11 EDT 2007
[ http://jira.jboss.com/jira/browse/JBRULES-1179?page=all ]
Mark Proctor closed JBRULES-1179.
---------------------------------
Resolution: Rejected
not a bug, user didn't realise that addPackage calls fireAllRules at the end.
> Premature rule execution
> ------------------------
>
> Key: JBRULES-1179
> URL: http://jira.jboss.com/jira/browse/JBRULES-1179
> Project: JBoss Rules
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Affects Versions: 4.0.1
> Environment: JDK 1.5, Mac OS X 10.4
> Reporter: Markus Reitz
> Assigned To: Edson Tirelli
> Fix For: 4.0.2
>
>
> Using the rules
> package test
>
> rule "A"
>
> when
> exists(x : String() and
> y : String(this!=x))
>
> then
> System.out.println("x!=y exists.");
> end
>
> rule "B"
>
> when
> not(exists(x : String() and
> y : String(this!=x)))
>
> then
> System.out.println("x!=y does not exist.");
> end
> as input for the following program (java DroolsTest <name of rule file>)
> import org.drools.*;
> import org.drools.compiler.*;
> import org.drools.rule.Package;
> import java.io.*;
> public class DroolsTest {
> private RuleBase rules;
> private StatefulSession memory;
> public DroolsTest(File file) throws Exception {
> rules =RuleBaseFactory.newRuleBase();
> memory=rules.newStatefulSession();
>
> rules.addPackage(loadPackage(file));
> }
> protected Package loadPackage(File file) throws IOException {
> FileInputStream stream=null;
>
> try {
> stream=new FileInputStream(file);
>
> return(loadPackage(stream));
> }
> finally {
> if (stream!=null)
> stream.close();
> }
> }
> protected Package loadPackage(InputStream stream) throws IOException {
> try {
> PackageBuilder builder=new PackageBuilder();
> builder.addPackageFromDrl(new InputStreamReader(stream));
> return(builder.getPackage());
> }
> catch(Exception ex) {
> throw new IOException();
> }
> }
>
> public StatefulSession getSession() {
> return(memory);
> }
>
> public static void main(String ... args) {
> try {
> DroolsTest test=new DroolsTest(new File(args[0]));
>
> System.out.println("Inserting ...");
>
> test.getSession().insert(new String("42"));
> test.getSession().insert(new String("42"));
> test.getSession().insert(new String("1701"));
> test.getSession().insert(new String("0815"));
> test.getSession().insert(new String("4711"));
> System.out.println("Done.");
>
> System.out.println("Firing rules ...");
>
> test.getSession().fireAllRules();
>
> System.out.println("Done.");
> }
> catch (Exception ex) {
> ex.printStackTrace();
> }
> }
> }
> creates the output
> x!=y does not exist.
> Inserting ...
> Done.
> Firing rules ...
> x!=y exists.
> Done.
> Premature firing of rules seems to occur ("x!=y does not exist" before fireAllRules is invoked), which is not the expected behaviour.
--
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
More information about the jboss-jira
mailing list