[jboss-jira] [JBoss JIRA] (DROOLS-1302) OOPath ReactiveList remove cases

Matteo Mortari (JIRA) issues at jboss.org
Thu Oct 20 06:31:00 EDT 2016


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

Matteo Mortari edited comment on DROOLS-1302 at 10/20/16 6:30 AM:
------------------------------------------------------------------

As discussed in presence the previous solution in ReactiveList :

{code:java}
    @Override
    public boolean add(T t) {
        boolean result = list.add(t);
        ReactiveObjectUtil.notifyModification(t, getLeftTuples(), ModificationType.ADD);
        if (t instanceof ReactiveObject) {
            for (Tuple lts : getLeftTuples()) {
                ((ReactiveObject) t).addLeftTuple(lts);
            }
        }
        return result;
    }
{code}

is not really ideal as this case fails by creating twice the match:

{code:java}
    @Test
    public void testMatteo2() {
        String drl =
                "import org.drools.compiler.xpath.*;\n" +
                "global java.util.List list\n" +
                "\n" +
                "rule R when\n" +
                "  Man( $usage: /wife/children{age > 10}/toys/usage{level > 10} )\n" +
                "then\n" +
                "  list.add( $usage );\n" +
                "end\n";

        KieBase kbase = new KieHelper().addContent( drl, ResourceType.DRL ).build();
        KieSession ksession = kbase.newKieSession();

        List<String> list = new ArrayList<String>();
        ksession.setGlobal( "list", list );

        Woman alice = new Woman( "Alice", 38 );
        Man bob = new Man( "Bob", 40 );
        bob.setWife( alice );

        ksession.insert( bob );
        ksession.fireAllRules();
        
        list.clear();
        Child eleonor = new Child( "Eleonor", 10 );
        alice.addChild( eleonor );
        Toy toy = new Toy( "eleonor toy 1" );
        eleonor.addToy( toy );
        Usage usage = new Usage();
        toy.setUsage(usage);
        usage.setLevel(0);
        eleonor.setAge(11);
        ksession.fireAllRules();
        System.out.println(list);
        

        usage.setLevel(99);
        ksession.fireAllRules();
        System.out.println(list);
    }
{code}

(removing the first of the 3 fires, does not exhibit the issue, so as discussed this could be related with the fact the from node create the fh twice.)

(having the first setter to  usage.setLevel(99); instead of above  usage.setLevel(0); would exhibit the issue multiplied, at the 2/3 fired having 2 match, at the 3/3 fired having 4 match)



was (Author: tari_manga):
As discussed in presence the previous solution in ReactiveList :

{code:java}
    @Override
    public boolean add(T t) {
        boolean result = list.add(t);
        ReactiveObjectUtil.notifyModification(t, getLeftTuples(), ModificationType.ADD);
        if (t instanceof ReactiveObject) {
            for (Tuple lts : getLeftTuples()) {
                ((ReactiveObject) t).addLeftTuple(lts);
            }
        }
        return result;
    }
{code}

is not really ideal as this case fails by creating twice the match:

{code:java}
    @Test
    public void testMatteo2() {
        String drl =
                "import org.drools.compiler.xpath.*;\n" +
                "global java.util.List list\n" +
                "\n" +
                "rule R when\n" +
                "  Man( $usage: /wife/children{age > 10}/toys/usage{level > 10} )\n" +
                "then\n" +
                "  list.add( $usage );\n" +
                "end\n";

        KieBase kbase = new KieHelper().addContent( drl, ResourceType.DRL ).build();
        KieSession ksession = kbase.newKieSession();

        List<String> list = new ArrayList<String>();
        ksession.setGlobal( "list", list );

        Woman alice = new Woman( "Alice", 38 );
        Man bob = new Man( "Bob", 40 );
        bob.setWife( alice );

        ksession.insert( bob );
        ksession.fireAllRules();
        
        list.clear();
        Child eleonor = new Child( "Eleonor", 10 );
        alice.addChild( eleonor );
        Toy toy = new Toy( "eleonor toy 1" );
        eleonor.addToy( toy );
        Usage usage = new Usage();
        toy.setUsage(usage);
        usage.setLevel(99);
        eleonor.setAge(11);
        ksession.fireAllRules();
        System.out.println(list);
        

        usage.setLevel(99);
        ksession.fireAllRules();
        System.out.println(list);
    }
{code}


> OOPath ReactiveList remove cases
> --------------------------------
>
>                 Key: DROOLS-1302
>                 URL: https://issues.jboss.org/browse/DROOLS-1302
>             Project: Drools
>          Issue Type: Bug
>          Components: core engine
>    Affects Versions: 6.5.0.CR2
>            Reporter: Matteo Mortari
>            Assignee: Mario Fusco
>            Priority: Minor
>             Fix For: 7.0.0.Beta2
>
>
> * Removing element from ReactiveList is not covered
> * Ensure removing from 1 out of many ReactiveList does affect only the relevant lists when  issuing modification to a ReactiveObject



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the jboss-jira mailing list