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

KieContainer#updateToVersion removing rules with accumulate

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • None
    • 7.16.0.Final
    • core engine
    • None
    • 2019 Week 02-04, 2019 Week 05-07
    • 5
    • Hide

      Consider the rule file: SimpleRuleWithAccumulate.drl

      dialect "mvel"
      dialect "java"

      declare MySum
      val : Integer @key
      end

      rule "Simple rule 2"
      when
      accumulate($i : Integer(intValue > 5);
      $s : sum($i))
      then
      insertLogical(new MySum($s))
      end

      The test which reproduces the bug:

      @Test
      public void ruleRemovalTest() {

      /**

      • Create the kie container based on a simple rule from
      • SimpleRuleWithAccumulate.drl
        */
        KieServices kieServices = KieServices.Factory.get();
        KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
        kieFileSystem.write(ResourceFactory.newFileResource("src/test/java/rulesengine/SimpleRuleWithAccumulate.drl"));
        KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
        kieBuilder.buildAll();
        KieModule kieModule = kieBuilder.getKieModule();
        KieContainer kieContainer = kieServices.newKieContainer(kieModule.getReleaseId());
        KieSession kieSession = kieContainer.newKieSession();

      /**

      • Insert three Integer objects: 3, 7, 9
        */
        kieSession.insert(new Integer(3));
        kieSession.insert(new Integer(7));
        kieSession.insert(new Integer(9));
        Assert.assertEquals(3, kieSession.getObjects().size());

      /**

      • Fire all rules, verify that one object of type MySum is created
        */
        kieSession.fireAllRules();
        System.out.println("***************************************************");
        System.out.println("Objects in the working memory after all rules fired");
        for (Object o : kieSession.getObjects()) { System.out.println(o); }
        System.out.println("***************************************************");
        Assert.assertEquals(4, kieSession.getObjects().size());

        /**
        * Update the kie base using the kie module which no longer contains
        * SimpleRuleWithAccumulate.drl
        */
        kieFileSystem = kieServices.newKieFileSystem();
        kieBuilder = kieServices.newKieBuilder(kieFileSystem);
        kieBuilder.buildAll();
        kieModule = kieBuilder.getKieModule();
        kieContainer.updateToVersion(kieModule.getReleaseId());
        KieBase kieBase = kieContainer.getKieBase();
        kieBase.removeRule("defaultpkg", "Simple rule 2");

        /**
        * Fire all rules. Logically inserted objects of MySum should be automatically
        * removed from the working memory
        */
        kieSession.fireAllRules();
        System.out.println("***************************************************");
        System.out.println("Objects in the working memory after the SimpleRule.drl is removed");
        for (Object o : kieSession.getObjects()) { System.out.println(o); }

        System.out.println("***************************************************");
        Assert.assertEquals(3, kieSession.getObjects().size());
        }

      Show
      Consider the rule file: SimpleRuleWithAccumulate.drl dialect "mvel" dialect "java" declare MySum val : Integer @key end rule "Simple rule 2" when accumulate($i : Integer(intValue > 5); $s : sum($i)) then insertLogical(new MySum($s)) end The test which reproduces the bug: @Test public void ruleRemovalTest() { /** Create the kie container based on a simple rule from SimpleRuleWithAccumulate.drl */ KieServices kieServices = KieServices.Factory.get(); KieFileSystem kieFileSystem = kieServices.newKieFileSystem(); kieFileSystem.write(ResourceFactory.newFileResource("src/test/java/rulesengine/SimpleRuleWithAccumulate.drl")); KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem); kieBuilder.buildAll(); KieModule kieModule = kieBuilder.getKieModule(); KieContainer kieContainer = kieServices.newKieContainer(kieModule.getReleaseId()); KieSession kieSession = kieContainer.newKieSession(); /** Insert three Integer objects: 3, 7, 9 */ kieSession.insert(new Integer(3)); kieSession.insert(new Integer(7)); kieSession.insert(new Integer(9)); Assert.assertEquals(3, kieSession.getObjects().size()); /** Fire all rules, verify that one object of type MySum is created */ kieSession.fireAllRules(); System.out.println("***************************************************"); System.out.println("Objects in the working memory after all rules fired"); for (Object o : kieSession.getObjects()) { System.out.println(o); } System.out.println("***************************************************"); Assert.assertEquals(4, kieSession.getObjects().size()); /** * Update the kie base using the kie module which no longer contains * SimpleRuleWithAccumulate.drl */ kieFileSystem = kieServices.newKieFileSystem(); kieBuilder = kieServices.newKieBuilder(kieFileSystem); kieBuilder.buildAll(); kieModule = kieBuilder.getKieModule(); kieContainer.updateToVersion(kieModule.getReleaseId()); KieBase kieBase = kieContainer.getKieBase(); kieBase.removeRule("defaultpkg", "Simple rule 2"); /** * Fire all rules. Logically inserted objects of MySum should be automatically * removed from the working memory */ kieSession.fireAllRules(); System.out.println("***************************************************"); System.out.println("Objects in the working memory after the SimpleRule.drl is removed"); for (Object o : kieSession.getObjects()) { System.out.println(o); } System.out.println("***************************************************"); Assert.assertEquals(3, kieSession.getObjects().size()); }
    • User Experience
    • NEW
    • NEW

    Description

      Consider a rule with accumulate pattern in the LHS which logically inserts an object in the RHS. Build the KieModule from the KieFileSystem including this rule, create the KieContainer and the KieSession. Insert the facts. Everything works fine.
      Create a new KieModule excluding this rule from the KieFileSystem, update the KieContainer. Expect the logically inserted fact to be retracted, as the rule which trigged its creation is no longer present. Turns out that the fact is still present in the working memory

      Attachments

        Issue Links

          Activity

            People

              mfusco@redhat.com Mario Fusco
              olga13 Olga Rodionova (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: