Bug 1274394 - Logical insert does not retract a fact if its condition ceases to be true
Summary: Logical insert does not retract a fact if its condition ceases to be true
Alias: None
Product: JBoss BRMS Platform 6
Classification: Retired
Component: BRE
Version: 6.2.0
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
: ---
Assignee: Mario Fusco
QA Contact: Marek Winkler
Depends On:
TreeView+ depends on / blocked
Reported: 2015-10-22 16:01 UTC by Marek Winkler
Modified: 2015-10-26 08:38 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2015-10-26 08:38:34 UTC
Type: Bug

Attachments (Terms of Use)

Description Marek Winkler 2015-10-22 16:01:28 UTC
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 10:34:56 UTC
The reproducer can be found here: https://github.com/droolsjbpm/drools/pull/522

Comment 3 Marek Winkler 2015-10-23 10:43:46 UTC
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 08:38:34 UTC
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.