Bug 1274394 - Logical insert does not retract a fact if its condition ceases to be true
Logical insert does not retract a fact if its condition ceases to be true
Product: JBoss BRMS Platform 6
Classification: JBoss
Component: BRE (Show other bugs)
Unspecified Unspecified
urgent Severity high
: ---
: ---
Assigned To: Mario Fusco
Marek Winkler
Depends On:
  Show dependency treegraph
Reported: 2015-10-22 12:01 EDT by Marek Winkler
Modified: 2015-10-26 04:38 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2015-10-26 04:38:34 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Marek Winkler 2015-10-22 12:01:28 EDT
Description of problem:

Assume the following rule:

rule "Insert all persons in collection"
        $coll: Collection()
        $person : Person(age < 50) from $coll

and the following test:

    public void testChangeElement() {
        KieSession ksession = getKbase().newKieSession();

        Collection<Person> collection = new ArrayList<Person>();

        for (int i = 1; i < 5; i++) {
            collection.add(new Person("Person " + i, null, 10 * i));

        FactHandle handle = ksession.insert(collection);

        // before change - expecting 5 facts
        Assertions.assertThat(ksession.getFactCount()).isEqualTo((long) 5);

        ksession.update(handle, collection);

        // after change - expecting 4 facts
        Assertions.assertThat(ksession.getFactCount()).isEqualTo((long) 4);  // this assertion fails

The second assertion fails because there are still 5 facts in the WM (insertLogical seems not to retract the fact when the condition supporting it stops being true). The same test passed in 6.1.x, I am not sure if this is a bug, or an expected change of behavior.

Version-Release number of selected component (if applicable):
BRMS 6.2.0 ER4 (most likely a change before ER3)

How reproducible:

Steps to Reproduce:

A PR with the reproducer will be attached soon.

Actual results:
insertLogical does not retract the fact when its condition stops being true.

Expected results:
insertLogical should retract the fact when its condition stops being true.
Comment 2 Marek Winkler 2015-10-23 06:34:56 EDT
The reproducer can be found here: https://github.com/droolsjbpm/drools/pull/522
Comment 3 Marek Winkler 2015-10-23 06:43:46 EDT
I have analyzed the test once again and I found that the problem is related to incorrectly defined equals method in class LogicalInsertTest.Person - please see the reproducer for details.

I think that this might be just a change in behavior since BRMS 6.1.x which might not have required properly defined equals and hashcode methods for logically inserted facts (the test passed with that BRMS version). Is this true?

If this is an intended change, should it be highlighted in documentation (something like "BxMS 6.2 requires you to define properly equals and hashcode methods on logically inserted facts")?
Comment 4 Marek Winkler 2015-10-26 04:38:34 EDT
After having a chat with Mario, he confirmed that this behavior is intended, so I am closing this BZ.

Note You need to log in before you can comment on or make changes to this bug.