[jboss-jira] [JBoss JIRA] Created: (JBRULES-2108) A rule does not fire for all objects satisfying the rule code.

Andrey Nechaev (JIRA) jira-events at lists.jboss.org
Thu Jun 4 09:48:56 EDT 2009


A rule does not fire for all objects satisfying the rule code.
--------------------------------------------------------------

                 Key: JBRULES-2108
                 URL: https://jira.jboss.org/jira/browse/JBRULES-2108
             Project: JBoss Drools
          Issue Type: Bug
      Security Level: Public (Everyone can see)
          Components: drools-core
    Affects Versions: 4.0.7
            Reporter: Andrey Nechaev
            Assignee: Mark Proctor


The following code shows the problem:
public class DroolsTest {
	private final static int NUM_FACTS = 20;
	private final static String rule = "" + 
		"package test\n" + 
		"import com.test.DroolsTest;\n" + 
		"import com.test.DroolsTest.Foo;\n" +
		"import com.test.DroolsTest.Bar;\n" +
		"rule test\n" + 
			"\twhen\n" + 
				"\t\tFoo($p : id < " + Integer.toString(NUM_FACTS) + ") && Bar(id == $p)\n" +
			"\tthen\n" +
				"\t\tDroolsTest.incCounter();\n" +
		"end";
	
	private static int counter;
	
	public static class Foo {
		private final int id;
		
		Foo(int id) {
			this.id = id;
		}
		
		public int getId() {
			return id;
		}
	}
	
	public static class Bar {
		private final int id;
		
		Bar(int id) {
			this.id = id;
		}
		
		public int getId() {
			return id;
		}
	}
	
	public static void main(String[] args) throws Exception {
		RuleBase rb;
		WorkingMemory wm;
		counter = 0;
		
		rb = RuleBaseFactory.newRuleBase();
		wm = rb.newStatefulSession();
				
		for(int i = 0; i < NUM_FACTS; i++) {
			wm.insert(new Foo(i));
			wm.insert(new Bar(i));
		}
		PackageBuilder bld = new PackageBuilder();
		bld.addPackageFromDrl(new StringReader(rule));
		
		rb.addPackage(bld.getPackage());
		System.out.println(counter == NUM_FACTS ? "passed" : "failed");
	}
	
	public static void incCounter() {
		++counter;
	}
}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list