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

Infinite loop when updating a fact inside a shared subnetwork

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Critical
    • 7.0.0.Beta3
    • None
    • core engine
    • None
    • NEW
    • NEW

    Description

      Updating a fact evaluated inside a shared subnetwork may cause an infinite loop as demonstrated by the following unit test:

          @Test(timeout = 10000L)
          public void testUpdateOnSharedSubnetwork() {
              String drl =
                      "import " + AtomicInteger.class.getCanonicalName() + ";\n" +
                      "global java.util.List list;\n" +
                      "rule R1y when\n" +
                      "    AtomicInteger() \n" +
                      "    Number() from accumulate ( AtomicInteger( ) and $s : String( ) ; count($s) )" +
                      "    eval(false)\n" +
                      "then\n" +
                      "end\n" +
                      "\n" +
                      "rule R2 when\n" +
                      "    $i : AtomicInteger( get() < 3 )\n" +
                      "then\n" +
                      "    $i.incrementAndGet();" +
                      "    insert(\"test\" + $i.get());" +
                      "    update($i);" +
                      "end\n" +
                      "\n" +
                      "rule R1x when\n" +
                      "    AtomicInteger() \n" +
                      "    $c : Number() from accumulate ( AtomicInteger( ) and $s : String( ) ; count($s) )\n" +
                      "    eval(true)\n" +
                      "then\n" +
                      "    list.add($c);" +
                      "end\n";
      
              KieSession kieSession = new KieHelper().addContent( drl, ResourceType.DRL )
                                                     .build().newKieSession();
      
              List<Number> list = new ArrayList<Number>();
              kieSession.setGlobal( "list", list );
      
              kieSession.insert( new AtomicInteger( 0 ) );
              kieSession.insert( "test" );
      
              kieSession.fireAllRules();
      
              assertEquals(1, list.size());
              assertEquals(4, list.get(0).intValue());
          }
      

      Attachments

        Issue Links

          Activity

            People

              mfusco@redhat.com Mario Fusco
              mfusco@redhat.com Mario Fusco
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: