[jboss-jira] [JBoss JIRA] (DROOLS-32) Infinite rule execution (happens sometimes only)
Dominik Bieringer (JIRA)
jira-events at lists.jboss.org
Fri Feb 8 08:48:51 EST 2013
Dominik Bieringer created DROOLS-32:
---------------------------------------
Summary: 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: Mark Proctor
Priority: Critical
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