Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
[KIE-686] fix peer update propagation for FromNode (#5584) (#21) (#22)
Browse files Browse the repository at this point in the history
* [KIE-686] fix peer update propagation for FromNode

* Update drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/UnexpectedLoopTest.java



* Fixed for Java 8 compatibility

---------

Co-authored-by: Toshiya Kobayashi <[email protected]>
Co-authored-by: Mario Fusco <[email protected]>
  • Loading branch information
3 people authored Nov 16, 2023
1 parent d13e8f7 commit bf32293
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import static org.drools.core.phreak.AddRemoveRule.forceFlushLeftTuple;
import static org.drools.core.phreak.AddRemoveRule.forceFlushWhenRiaNode;
import static org.drools.core.reteoo.NodeTypeEnums.hasNodeMemory;
import static org.drools.core.reteoo.NodeTypeEnums.AccumulateNode;

public class SegmentPropagator {

Expand Down Expand Up @@ -131,7 +131,7 @@ private static void updateChildLeftTupleDuringInsert(LeftTuple childLeftTuple, T
break;
default:
// no clash, so just add
if ( hasNodeMemory( childLeftTuple.getTupleSink() ) ) {
if ( childLeftTuple.getTupleSink().getType() == AccumulateNode ) {
trgLeftTuples.addInsert(childLeftTuple);
} else {
trgLeftTuples.addUpdate(childLeftTuple);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.drools.compiler.integrationtests;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.drools.compiler.integrationtests.model.CalcFact;
import org.drools.compiler.integrationtests.model.Item;
import org.drools.compiler.integrationtests.model.RecordFact;
import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.KieBaseUtil;
import org.drools.testcoverage.common.util.TestParametersUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.kie.api.KieBase;
import org.kie.api.runtime.KieSession;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(Parameterized.class)
public class UnexpectedLoopTest {

private final KieBaseTestConfiguration kieBaseTestConfiguration;

public UnexpectedLoopTest(final KieBaseTestConfiguration kieBaseTestConfiguration) {
this.kieBaseTestConfiguration = kieBaseTestConfiguration;
}

@Parameterized.Parameters(name = "KieBase type={0}")
public static Collection<Object[]> getParameters() {
return TestParametersUtil.getKieBaseCloudConfigurations(true);
}

@Test
public void joinFromFromPeerUpdate_shouldNotLoop() {

final KieBase kieBase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration,
"org/drools/compiler/integrationtests/joinFromFrom.drl");
final KieSession ksession = kieBase.newKieSession();
try {
RecordFact record1 = new RecordFact(null, 0);
Item item1 = new Item(null);
CalcFact calcFact = new CalcFact(new ArrayList<>(Arrays.asList(item1)), 4144);

ksession.insert("test");
ksession.insert(record1);
ksession.insert(item1);
ksession.insert(calcFact);

int fired = ksession.fireAllRules(10);

assertThat(fired).as("Unexpected loop detected. Expects firing R2 once").isEqualTo(1);
} finally {
ksession.dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.drools.compiler.integrationtests.model;

import java.util.List;

public class CalcFact {

private List<Item> itemList;
private int lineNumber;

public CalcFact(List<Item> itemList, int lineNumber) {
this.itemList = itemList;
this.lineNumber = lineNumber;
}

public List<Item> getItemList() {
return itemList;
}

public void setItemList(List<Item> itemList) {
this.itemList = itemList;
}

public int getLineNumber() {
return lineNumber;
}

@Override
public String toString() {
return "CalcFact{" +
"itemList=" + itemList +
", lineNumber=" + lineNumber +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.drools.compiler.integrationtests.model;

public class Item {

private String decomposedPointFlag;

public Item(String decomposedPointFlag) {
this.decomposedPointFlag = decomposedPointFlag;
}

public String getDecomposedPointFlag() {
return decomposedPointFlag;
}

public void setDecomposedPointFlag(String decomposedPointFlag) {
this.decomposedPointFlag = decomposedPointFlag;
}

@Override
public String toString() {
return "Item{" +
"pointFlag='" + decomposedPointFlag + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.drools.compiler.integrationtests.model;

import java.math.BigDecimal;

public class RecordFact {

private BigDecimal decomposedPoint;
private int lineNumber;

public RecordFact(BigDecimal decomposedPoint, int lineNumber) {
this.decomposedPoint = decomposedPoint;
this.lineNumber = lineNumber;
}

public BigDecimal getDecomposedPoint() {
return decomposedPoint;
}

public void setDecomposedPoint(BigDecimal decomposedPoint) {
this.decomposedPoint = decomposedPoint;
}

public int getLineNumber() {
return lineNumber;
}

@Override
public String toString() {
return "RecordFact{" +
", decomposedPoint=" + decomposedPoint +
", lineNumber=" + lineNumber +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.drools.compiler.integrationtests;

import org.drools.compiler.integrationtests.model.CalcFact;
import org.drools.compiler.integrationtests.model.Item;
import org.drools.compiler.integrationtests.model.RecordFact;

dialect "mvel"

rule R1
when
String()
CalcFact( $lineNumber : lineNumber, $itemList : itemList )
Integer()
then
end

rule R2
when
String()
$fact : CalcFact( $itemList : itemList )
$item : Item( decomposedPointFlag == null ) from $itemList
$record : RecordFact( decomposedPoint == null )
not RecordFact( lineNumber == $fact.lineNumber )
then
modify($record){
decomposedPoint = null
}
modify($item){
decomposedPointFlag = "1"
}
modify($fact){
itemList = $itemList
}
System.out.println("[DEBUG] after $item=" + $item);
end

0 comments on commit bf32293

Please sign in to comment.