This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KIE-686] fix peer update propagation for FromNode (#5584)
* [KIE-686] fix peer update propagation for FromNode * Update drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/UnexpectedLoopTest.java Co-authored-by: Toshiya Kobayashi <[email protected]> * Fixed for Java 8 compatibility --------- Co-authored-by: Toshiya Kobayashi <[email protected]>
- Loading branch information
1 parent
a7cb32c
commit dadb65a
Showing
6 changed files
with
207 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...er-integration/src/test/java/org/drools/compiler/integrationtests/UnexpectedLoopTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...mpiler-integration/src/test/java/org/drools/compiler/integrationtests/model/CalcFact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + | ||
'}'; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...t-compiler-integration/src/test/java/org/drools/compiler/integrationtests/model/Item.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + '\'' + | ||
'}'; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...iler-integration/src/test/java/org/drools/compiler/integrationtests/model/RecordFact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + | ||
'}'; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...iler-integration/src/test/resources/org/drools/compiler/integrationtests/joinFromFrom.drl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |