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

Eval does not behave as intended

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 6.1.0.Beta3
    • 6.1.0.Final
    • None
    • None
    • Hide

      package org.example;

      import java.util.Date;

      declare Thing

      end

      declare IDProperty
      subject : Thing
      object : int
      end

      declare StatusEvent
      @role(event)
      @timestamp(timestamp)
      thingId : int
      timestamp : Date
      end

      rule init
      when
      then
      Thing t = new Thing();
      insert (t);
      insert (new IDProperty(t, 1));

      insert (new StatusEvent(1, new Date(0)));
      insert (new StatusEvent(1, new Date(1)));
      end

      rule notLast1
      when
      $t : Thing()
      IDProperty(subject == $t, $id : object)

      // Constraint
      $ev : StatusEvent(thingId == $id)

      exists(
      // Constraint
      StatusEvent(this after $ev, $id == thingId)
      )
      then
      System.out.println("(1) not last " + $ev);
      end

      rule notLast2
      when
      $t : Thing()
      IDProperty(subject == $t, $id : object)

      // Constraint
      $ev : StatusEvent(thingId == $id)

      exists(
      // Eval
      StatusEvent(this after $ev, $evId : thingId)
      and
      eval($evId == $id)
      )
      then
      System.out.println("(2) not last " + $ev);
      end

      rule notLast3
      when
      $t : Thing()
      IDProperty(subject == $t, $id : object)

      // Eval
      $ev : StatusEvent()
      eval($ev.getThingId() == $id)

      exists(
      // Constraint
      StatusEvent(this after $ev, $id == thingId)
      )
      then
      System.out.println("(3) not last " + $ev);
      end

      rule notLast4
      when

      $t : Thing()
      IDProperty(subject == $t, $id : object)

      // Eval
      $ev : StatusEvent()
      eval($ev.getThingId() == $id)

      exists(
      // Eval
      StatusEvent(this after $ev, $evId : thingId)
      and
      eval($evId == $id)
      )
      then
      System.out.println("(4) not last " + $ev);
      end

      Output:

      (1) not last StatusEvent( thingId=1, timestamp=Thu Jan 01 01:00:00 CET 1970 )
      (2) not last StatusEvent( thingId=1, timestamp=Thu Jan 01 01:00:00 CET 1970 )
      (3) not last StatusEvent( thingId=1, timestamp=Thu Jan 01 01:00:00 CET 1970 )

      Rule "notLast4" doesn't fire

      Show
      package org.example; import java.util.Date; declare Thing end declare IDProperty subject : Thing object : int end declare StatusEvent @role(event) @timestamp(timestamp) thingId : int timestamp : Date end rule init when then Thing t = new Thing(); insert (t); insert (new IDProperty(t, 1)); insert (new StatusEvent(1, new Date(0))); insert (new StatusEvent(1, new Date(1))); end rule notLast1 when $t : Thing() IDProperty(subject == $t, $id : object) // Constraint $ev : StatusEvent(thingId == $id) exists( // Constraint StatusEvent(this after $ev, $id == thingId) ) then System.out.println("(1) not last " + $ev); end rule notLast2 when $t : Thing() IDProperty(subject == $t, $id : object) // Constraint $ev : StatusEvent(thingId == $id) exists( // Eval StatusEvent(this after $ev, $evId : thingId) and eval($evId == $id) ) then System.out.println("(2) not last " + $ev); end rule notLast3 when $t : Thing() IDProperty(subject == $t, $id : object) // Eval $ev : StatusEvent() eval($ev.getThingId() == $id) exists( // Constraint StatusEvent(this after $ev, $id == thingId) ) then System.out.println("(3) not last " + $ev); end rule notLast4 when $t : Thing() IDProperty(subject == $t, $id : object) // Eval $ev : StatusEvent() eval($ev.getThingId() == $id) exists( // Eval StatusEvent(this after $ev, $evId : thingId) and eval($evId == $id) ) then System.out.println("(4) not last " + $ev); end Output: (1) not last StatusEvent( thingId=1, timestamp=Thu Jan 01 01:00:00 CET 1970 ) (2) not last StatusEvent( thingId=1, timestamp=Thu Jan 01 01:00:00 CET 1970 ) (3) not last StatusEvent( thingId=1, timestamp=Thu Jan 01 01:00:00 CET 1970 ) Rule "notLast4" doesn't fire

    Description

      Under certain conditions, eval does not behave as intended, when nested in a sub-network.

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            matrium_jira Fabian Meyer (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: