[jboss-jira] [JBoss JIRA] (DROOLS-1346) Unwanted firing modifying an event over a window:time

Matteo Mortari (JIRA) issues at jboss.org
Thu Oct 27 13:11:01 EDT 2016


    [ https://issues.jboss.org/browse/DROOLS-1346?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13313164#comment-13313164 ] 

Matteo Mortari commented on DROOLS-1346:
----------------------------------------


{code:java}
@Test(timeout=10000)
    public void test01724123() {
        // 01724123
        String drl =
                "package " + MutableEvent.class.getPackage().getName() + "\n" +
                "declare " + MutableEvent.class.getCanonicalName() + "\n" +
                "   @role( event ) \n" +
                "end\n" +
                "rule \"Delete old fact\"\n" + 
                "    when\n" + 
                "        $event : MutableEvent(!condition)\n" + 
                "        String()\n" + 
                "    then\n" + 
                "        retract($event);\n" + 
                "end\n" + 
                "\n" + 
                "rule \"Generate new fail\"\n" + 
                "    when\n" + 
                "        $lineFail : MutableEvent() over window:time ( 10h )\n" + 
                "        not String()\n" + 
                "    then\n" + 
                "        modify($lineFail) {\n" + 
                "            setCondition(true)\n" + 
                "        }\n" + 
                "        insert(\"check\");\n" + 
                "end";

        KieHelper helper = new KieHelper();
        helper.addContent( drl, ResourceType.DRL );
        KieBase kbase = helper.build( EventProcessingOption.STREAM );
        KieSession ksession = kbase.newKieSession();
        
        ksession.addEventListener(new DefaultAgendaEventListener() {
            @Override
            public void afterMatchFired(AfterMatchFiredEvent event) {
                super.afterMatchFired(event);
                System.out.println(event);
            }
        });

        ksession.insert(new MutableEvent());
        int fired = ksession.fireAllRules();

        assertEquals(1, fired);
    }
    
    public static class MutableEvent implements Serializable {

        private boolean condition = false;

        public boolean isCondition() {
            return condition;
        }

        public void setCondition(boolean condition) {
            this.condition = condition;
        }

        @Override
        public String toString() {
            StringBuilder builder = new StringBuilder();
            builder.append("MutableEvent [condition=").append(condition).append("]");
            return builder.toString();
        }
    }
{code}


> Unwanted firing modifying an event over a window:time
> -----------------------------------------------------
>
>                 Key: DROOLS-1346
>                 URL: https://issues.jboss.org/browse/DROOLS-1346
>             Project: Drools
>          Issue Type: Bug
>          Components: core engine
>            Reporter: Mario Fusco
>            Assignee: Mario Fusco
>
> Steps to reproduce:
> 1. In a first rule pattern match on an event over window:time
> 2. In the consequence of the rule change the value of a field of that event
> 3. Have a second rule that shouldn't match the value of the field changed by the former rule
> 4. This second rule fires even if it shouldn't



--
This message was sent by Atlassian JIRA
(v7.2.2#72004)


More information about the jboss-jira mailing list