[jboss-jira] [JBoss JIRA] (DROOLS-32) Infinite rule execution (happens sometimes only)

Mario Fusco (JIRA) jira-events at lists.jboss.org
Fri Feb 8 11:26:51 EST 2013


     [ https://issues.jboss.org/browse/DROOLS-32?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mario Fusco resolved DROOLS-32.
-------------------------------

    Fix Version/s: 5.6
                   6.0.0.Alpha1
       Resolution: Done


The problem was caused by the jit optimizer that didn't compile properly a constraint containing an operation on BigDecimal.

Another workaround in 5.5 is to avoid operation on BigDecimals in constraints and, for instance, rewrite it as:

 Model(price < (cost.add(0.10B)))
                
> Infinite rule execution (happens sometimes only)
> ------------------------------------------------
>
>                 Key: DROOLS-32
>                 URL: https://issues.jboss.org/browse/DROOLS-32
>             Project: Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>    Affects Versions: 5.5
>            Reporter: Dominik Bieringer
>            Assignee: Mario Fusco
>            Priority: Critical
>             Fix For: 5.6, 6.0.0.Alpha1
>
>
> using 
> {code}
> <dependency>
> 	<groupId>org.drools</groupId>
> 	<artifactId>drools-core</artifactId>
> 	<version>5.5.1-SNAPSHOT</version>
> </dependency>
> <dependency>
> 	<groupId>org.drools</groupId>
> 	<artifactId>drools-compiler</artifactId>
> 	<version>5.5.1-SNAPSHOT</version>
> </dependency>
> {code}
> and main
> {code}
> import java.math.BigDecimal;
> import java.util.Collection;
> import org.drools.KnowledgeBase;
> import org.drools.KnowledgeBaseFactory;
> import org.drools.builder.KnowledgeBuilder;
> import org.drools.builder.KnowledgeBuilderFactory;
> import org.drools.builder.ResourceType;
> import org.drools.definition.KnowledgePackage;
> import org.drools.io.ResourceFactory;
> import org.drools.runtime.StatefulKnowledgeSession;
> public class Test {
> 	public static void main(String[] args) {
> 		final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
> 		kbuilder.add(ResourceFactory.newClassPathResource("Pricing.drl", Test.class), ResourceType.DRL);
> 		final Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
> 		KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
> 		kbase.addKnowledgePackages(pkgs);
> 		for (int i = 0; i < 5000; i++) {
> 			final Model model = new Model();
> 			model.setCost(new BigDecimal("2.43"));
> 			model.setPrice(new BigDecimal("2.43"));
> 			final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
> 			ksession.insert(model);
> 			int fired = ksession.fireAllRules(1000);
> 			if (fired >= 1000)
> 				throw new RuntimeException("loop");
> 		}
> 	}
> 	public static class Model {
> 		private BigDecimal cost;
> 		private BigDecimal price;
> 		public BigDecimal getCost() {
> 			return cost;
> 		}
> 		public void setCost(BigDecimal cost) {
> 			this.cost = cost;
> 		}
> 		public BigDecimal getPrice() {
> 			return price;
> 		}
> 		public void setPrice(BigDecimal price) {
> 			this.price = price;
> 		}
> 	}
> }
> {code}
> and rule file
> {code}
> import Test.Model;
> import java.math.BigDecimal;
> rule "minCost" dialect "mvel" 
> 	when
> 		$product : Model(price < (cost + 0.10B))
> 	then
> 		modify ($product) { price = $product.cost + 0.10B }
> end
> {code}
> Most of the time the above rule is fired once, but every around 25th time the rule is fired multiple times (until the limit of 1000 is reached). However, changing the rule to the following solves the problem:
> {code}
> import Test.Model;
> import java.math.BigDecimal;
> rule "minCost" dialect "mvel" 
> 	when
> 		$product : Model(price < (cost + 0.10B))
> 		eval($product.price < ($product.cost + 0.10B))
> 	then
> 		modify ($product) { price = $product.cost + 0.10B }
> end
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jboss-jira mailing list