Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Drools validate all other rules when using an Agenda Filter to fire a specifc rule?

I have a whole bunch of rules and I am trying to write some unit tests for them. In my tests, I am using this:

int rulesFired = kSession.fireAllRules(new RuleNameEqualsAgendaFilter("rule name 1"));

The thing I have noticed is that although the amount of rules fired returned is 1, Drools still tries to validate against any other rule where the conditions are met. I sometimes receive error messages from other rules that are not defined in my rule name equals agenda filter because the conditions match based on what I am inserting in my kSession for the unit test.

For example I have:

rule "test1"
    when
        $var : Map(this["key"] == "gold")
    then
        do something
    end

rule "test2"
    when
        $var : Map(this["key"] == "gold" && this["other"] == "silver")
    then
        do something
    end

and in my test for rule1 I have a map with just "key". When I run the test with a filter for "test1", I will receive a null pointer because I do not have a value for "other" in my map, even though the rule I am filtering for does not care about "other"

Why does this happen? I can't find any documentation on it anywhere. It's as if Drools has to validate all the rules and syntax in my DRL file before filtering.

like image 392
Seephor Avatar asked Dec 05 '25 16:12

Seephor


1 Answers

The code for evaluating rule conditions results from a combination of all rules, possibly combining identical conditions or parts of conditions such as patterns or constraints in a way that reduces the overall effort. Thus, there is no way the evaluation of conditions of individual rules can be suppressed at runtime.

like image 196
laune Avatar answered Dec 08 '25 05:12

laune



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!