[rules-users] Drools 6.0.1 Negative Patterns in Stream Mode not working
Mark Proctor
mproctor at codehaus.org
Wed May 7 13:21:56 EDT 2014
Can you try 6.1 beta2? And if there is still a bug, please open a jira:
http://mvnrepository.com/artifact/org.drools/drools-core/6.1.0.Beta2
Ideally please submit a self contained unit test, as a pull request. As explained here:
http://docs.jboss.org/drools/release/5.5.0.Final/droolsjbpm-introduction-docs/html/gettingstarted.html
Mark
On 7 May 2014, at 14:44, RichardAmbridge <richard.ambridge at gmail.com> wrote:
> I am using drools 6.0.1 and I have the following test.
>
> public class DroolsTest {
>
> public DroolsTest() {
> }
>
> @Test
> public void work() throws InterruptedException, IOException,
> ClassNotFoundException {
>
> StringBuilder sb = new StringBuilder();
> sb.append("package drools\n");
> sb.append("import drools.MyObject;\n\n");
>
> sb.append("declare MyObject\n"
> + " @role ( event )\n"
> + "end\n\n");
>
> sb.append("rule \"Template2\"\n"
> + "\n"
> + "salience 0\n"
> + "dialect \"mvel\"\n"
> + "when\n"
> + " $s : MyObject(val==0)\n"
> + " not( MyObject(val==1, this after [0s,5s] $s ) )\n"
> + "\n"
> + "then\n"
> + " System.out.println(\"Template 2 fired\")\n"
> + " $s.name=\"2\";\n"
> + "\n"
> + "end\n");
>
> KieServices kieServices = KieServices.Factory.get();
>
> KieFileSystem kfs = kieServices.newKieFileSystem();
> kfs.write("src/main/resources/rules.drl", sb.toString());
>
> KieBuilder kieBuilder = kieServices.newKieBuilder(kfs);
> kieBuilder.buildAll();
> Results results = kieBuilder.getResults();
> assertFalse(results.hasMessages(Message.Level.ERROR));
> if (results.hasMessages(Message.Level.WARNING)) {
> System.out.println("Warnings logged");
> }
> KieContainer kieContainer =
> kieServices.newKieContainer(kieBuilder.getKieModule().getReleaseId());
>
> KieBaseConfiguration kieBaseConfiguration =
> kieServices.newKieBaseConfiguration();
> kieBaseConfiguration.setOption(EventProcessingOption.STREAM);
> KieBase kieBase = kieContainer.newKieBase(kieBaseConfiguration);
> KieSession ksession = kieBase.newKieSession();
>
> MyObject one = new MyObject();
> one.val = 0;
>
> FactHandle fh1 = ksession.insert(one);
> System.out.println("Insert one");
> ksession.fireAllRules();
> for (int i = 0; i < 13; i++) {
> System.out.println("Sleep:" + i);
> Thread.sleep(1000);
> //After 5 seconds, rule should fire
> }
> assertEquals("2", one.name);
>
> System.out.println("End");
> ksession.halt();
> ksession.dispose();
> }
>
> public class MyObject implements Serializable {
>
> String name;
> int val;
> boolean fired;
>
> public String getName() {
> return name;
> }
>
> public void setName(String name) {
> this.name = name;
> }
>
> public int getVal() {
> return val;
> }
>
> public void setVal(int val) {
> this.val = val;
> }
>
> public boolean isFired() {
> return fired;
> }
>
> public void setFired(boolean fired) {
> this.fired = fired;
> }
>
> }
> }
>
>
> The rule is using
> + " $s : MyObject(val==0)\n"
> + " not( MyObject(val==1, this after [0s,5s] $s ) )\n"
>
> So, if a MyObject with val==0 is inserted, then after 5 seconds no MyObject
> with val==1 is found the rule will fire.
> This works in Drools 5.5.0
>
> In 6.0.1 the rule doesn't fire.
>
> Please help. I want to use drools 6 but cannot with this problem.
>
> Thanks
>
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Drools-6-0-1-Negative-Patterns-in-Stream-Mode-not-working-tp4029463.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
More information about the rules-users
mailing list