Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-7525

Removal time of insertLogical

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • None
    • None
    • None
    • None
    • 2023 Week 30-32 (from Jul 24)
    • Hide
      package org.test;
      unit FactRules;
      import org.drools.ruleunits.api.RuleUnitData;
      import org.drools.ruleunits.api.DataStore;
      /* + java code equivalent to
      declare Fact
          value : Integer
      end
      
      declare Logical
          value : Integer
      end
      
      declare FactRules extends RuleUnitData
        facts: DataStore<Fact>
        logicals: DataStore<Logical>
      end
      */
      
      rule "Init" salience 10
        when
        then
          facts.add(new Fact(1));
          facts.add(new Fact(2));
      end
      
      /* These rules work as expected
      rule "Eliminate 1" salience 9
        when
          $fact : /facts[value == 1];
          /logicals[ value == 1];
        then
          facts.remove($fact);
      end
      
      rule "Eliminate 2" salience 8
        when
          $fact : /facts[value == 2];
          /logicals[ value == 2];
        then
          facts.remove($fact);
      end
      */
      
      // This rule causes problems
      rule "Eliminate all" salience 9
        when
          $fact : /facts[$val : value];
          /logicals[ value == $val];
        then
          facts.remove($fact);
      end
      
      rule "Logical" salience 7
        when
          /facts[value==1];
        then
          logicals.addLogical(new Logical(1));
          logicals.addLogical(new Logical(2));
      end

      Actual behavior (With Rule "Eliminate All")

       

      INS: Fact(value=1) 
      INS: Fact(value=2) 
      INS: Logical(value=1) 
      INS: Logical(value=2) 
      DEL: Fact(value=1) 
      DEL: Logical(value=1) 
      DEL: Logical(value=2) 
      DEL: Fact(value=2) <-- This is unexpected to me, as Logical(value=2) is already removed

       

       

      Expected behavior (achievable by replacing "eliminate all" with "eliminate 1+2"

      INS: Fact(value=1)
      INS: Fact(value=2)
      INS: Logical(value=1)
      INS: Logical(value=2)
      DEL: Fact(value=1)
      DEL: Logical(value=1)
      DEL: Logical(value=2) 
      // Fact(value=2) remains inserted

       

       

      Show
      package org.test; unit FactRules; import org.drools.ruleunits.api.RuleUnitData; import org.drools.ruleunits.api.DataStore; /* + java code equivalent to declare Fact     value : Integer end declare Logical     value : Integer end declare FactRules extends RuleUnitData   facts: DataStore<Fact>   logicals: DataStore<Logical> end */ rule "Init" salience 10   when   then     facts.add( new Fact(1));     facts.add( new Fact(2)); end /* These rules work as expected rule "Eliminate 1" salience 9   when     $fact : /facts[value == 1];     /logicals[ value == 1];   then     facts.remove($fact); end rule "Eliminate 2" salience 8   when     $fact : /facts[value == 2];     /logicals[ value == 2];   then     facts.remove($fact); end */ // This rule causes problems rule "Eliminate all" salience 9   when     $fact : /facts[$val : value];     /logicals[ value == $val];   then     facts.remove($fact); end rule "Logical" salience 7   when     /facts[value==1];   then     logicals.addLogical( new Logical(1));     logicals.addLogical( new Logical(2)); end Actual behavior (With Rule "Eliminate All")   INS: Fact(value=1) INS: Fact(value=2) INS: Logical(value=1) INS: Logical(value=2) DEL: Fact(value=1) DEL: Logical(value=1) DEL: Logical(value=2) DEL: Fact(value=2) <-- This is unexpected to me, as Logical(value=2) is already removed     Expected behavior (achievable by replacing "eliminate all" with "eliminate 1+2" INS: Fact(value=1) INS: Fact(value=2) INS: Logical(value=1) INS: Logical(value=2) DEL: Fact(value=1) DEL: Logical(value=1) DEL: Logical(value=2)  // Fact(value=2) remains inserted    
    • NEW
    • NEW
    • ---
    • ---

    Description

      Rules seem to be able to execute even after their precondition (insertLogical) has been removed.

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            kamilbowen Kamil Bowen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: