Hi All,
I'm new to Drools and learning from the book "Mastering JBoss Drools 6". In the examples provided at:
there is an example rule in Chapter 02 called order-discount-rules.drl
When testing this rule I found that the results are not correct. The rule seems to always fire not matter what. I believe the issue is with the $lines assignment:
$o: Order( $lines : orderLines.size >= 2, $customer: customer, discount == null )
This doesn't look like proper syntax to me. So, when I modify that line to look like this:
$o: Order( orderLines.size >= 2, $lines : orderLines, $customer: customer, discount == null )
The rule starts getting skipped when it's supposed to be skipped. i.e. if the data doesn't match the condition, the rule condition doesn't evaluate to true.
However, when the rule is supposed to be triggered (because the test data matches the rule conditions) the rule only gets triggered sporadically. i.e. if I run the rule with a positive test case 10 times, the rule only gets triggered maybe 5 out of 10 times.
Further, I found that if I assign a salience of -100 (the lowest priority of all rules), then the rule gets triggered 10 out of 10 times. That is because this rule depends on other rules being fired, which modify the data in memory to produce the state required for this rule to trigger.
This indicates to me that the rule is only being triggered when the engine happens to initially evaluate this rule later than the rules this one depends on. Either the engine has randomly decided to run this rule last, or I have to tell the engine to run it last.
Finally, this indicates to me that there is a bug in Drools that prevents this type of query from knowing about changes to its data in memory. Even though the other rules run after this one, and the state of the data creates a positive test case for this condition, this rule doesn't get re-triggered. It's always evaluated only once.
P.S. I tried this logic in both Drools 6.3.0.Final and 7.0.0.Final and found they behave the same.
Any and all help would be appreciated on this. I think the code examples in drools6-dev-guide should be updated to reflect the correct syntax.