When I run a test case against drools from within eclipse, it will return the
expected results the first time, but fails every time after that. I'd like
to know what's going on and if my rules are written correctly.
The object of the rule is to check to see a particular IP address has
submitted more than 5 failed payments in the last 24 hours (indicated by
responseCode == 0). The input to this is a List containing all payments from
the IP address and a helper object to indicate whether further action needs
to be taken by way of a boolean flag.
declare Payment
@role( event )
@timestamp( created )
end
rule "Block IP with more than 5 failed payments in the last 24 hours"
when
$fact : BlockRuleResponse()
$count : Number( intValue > 4 ) from accumulate(
Payment(responseCode == 0, $id : id) over window:time(
24h ),
count( $id ) )
then
System.out.println("More than 5 failures in 24 hours");
System.out.println( $count );
$fact.setBlocked( true );
end
The code in my test case which runs this is:
BlockRuleResponse result = new BlockRuleResponse();
result.setBlocked(false);
// Add all commands to this rule session
List<Command> cmds = new ArrayList<Command>();
cmds.add(CommandFactory.newInsert(result));
cmds.add(CommandFactory.newInsertElements(payments));
StatelessKnowledgeSession ksession =
getBase().newStatelessKnowledgeSession();
ksession.execute(CommandFactory.newBatchExecution(cmds));
log.debug(result.isBlocked());
return result.isBlocked();
The getBase() method just returns a KnowlegdeBase containing the rule above.
I then create two Lists of payment objects, one with creation dates set to
new Date(), the other with creation dates set more than 24 hours ago. I run
these through the rules engine and the result returned is always true.
I've tried using cloud + stream mode and also using a stateful session and
inserting the donations then firing all rules but none of this seems to
work. Stream mode always returns false, likewise stateful sessions always
return false whereas stateless cloud mode always returns true after the
first run.
Anyone have any idea what I'm missing?
--
View this message in context:
http://n3.nabble.com/Rules-returning-unexpected-results-tp68205p68205.html
Sent from the Drools - User mailing list archive at
Nabble.com.