Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JBRULES-2776 Left and Right Unlinking.
- Loading branch information
Showing
26 changed files
with
1,085 additions
and
93 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
drools-compiler/src/test/java/org/drools/integrationtests/LRUnlinkingTest.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,118 @@ | ||
package org.drools.integrationtests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.drools.Person; | ||
import org.drools.RuleBase; | ||
import org.drools.RuleBaseConfiguration; | ||
import org.drools.RuleBaseFactory; | ||
import org.drools.WorkingMemory; | ||
import org.drools.common.InternalFactHandle; | ||
import org.drools.compiler.PackageBuilder; | ||
import org.drools.rule.Package; | ||
import org.junit.Test; | ||
|
||
public class LRUnlinkingTest { | ||
|
||
@Test | ||
public void multipleJoinsUsingSameOTN() throws Exception { | ||
|
||
final PackageBuilder builder = new PackageBuilder(); | ||
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LRUnlinking.drl" ) ) ); | ||
final Package pkg = builder.getPackage(); | ||
|
||
final RuleBaseConfiguration conf = new RuleBaseConfiguration(); | ||
conf.setLRUnlinkingEnabled( true ); | ||
RuleBase ruleBase = RuleBaseFactory.newRuleBase( conf ); | ||
|
||
ruleBase.addPackage( pkg ); | ||
ruleBase = SerializationHelper.serializeObject( ruleBase ); | ||
|
||
final WorkingMemory wmOne = ruleBase.newStatefulSession(); | ||
final WorkingMemory wmTwo = ruleBase.newStatefulSession(); | ||
|
||
final List<Person> listOne = new ArrayList<Person>(); | ||
final List<Person> listTwo = new ArrayList<Person>(); | ||
|
||
wmOne.setGlobal( "results", | ||
listOne ); | ||
wmTwo.setGlobal( "results", | ||
listTwo ); | ||
|
||
Person name = new Person(); | ||
Person likes = new Person(); | ||
Person age = new Person(); | ||
Person hair = new Person(); | ||
Person happy = new Person(); | ||
Person match = new Person(); | ||
|
||
name.setName( "Ana" ); | ||
likes.setLikes( "Chocolate" ); | ||
age.setAge( 30 ); | ||
hair.setHair( "brown" ); | ||
happy.setHappy( true ); | ||
|
||
match.setName( "Leo" ); | ||
match.setLikes( "Chocolate" ); | ||
match.setAge( 30 ); | ||
match.setHair( "brown" ); | ||
match.setHappy( true ); | ||
|
||
// WM One - first round of inserts | ||
wmOne.insert( name ); | ||
wmOne.insert( likes ); | ||
wmOne.insert( age ); | ||
|
||
wmOne.fireAllRules(); | ||
|
||
assertEquals( "Should not have fired", | ||
0, | ||
listOne.size() ); | ||
|
||
// WM Two - first round o inserts | ||
wmTwo.insert( name ); | ||
wmTwo.insert( likes ); | ||
wmTwo.insert( age ); | ||
|
||
wmTwo.fireAllRules(); | ||
|
||
assertEquals( "Should not have fired", | ||
0, | ||
listTwo.size() ); | ||
|
||
wmOne.insert( hair ); | ||
wmOne.insert( happy ); | ||
InternalFactHandle matchHandle = (InternalFactHandle) wmOne.insert( match ); | ||
|
||
wmOne.fireAllRules(); | ||
|
||
assertTrue( "Should have fired", | ||
listOne.size() > 0); | ||
|
||
assertEquals("Should have inserted the match Person", | ||
matchHandle.getObject(), | ||
listOne.get( 0 )); | ||
|
||
wmTwo.fireAllRules(); | ||
|
||
assertEquals( "Should not have fired", | ||
0, | ||
listTwo.size() ); | ||
|
||
wmTwo.insert( hair ); | ||
wmTwo.insert( happy ); | ||
wmTwo.insert( match ); | ||
|
||
wmTwo.fireAllRules(); | ||
|
||
assertTrue( "Should have fired", | ||
listTwo.size() > 0); | ||
|
||
} | ||
|
||
} |
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
19 changes: 19 additions & 0 deletions
19
drools-compiler/src/test/resources/org/drools/integrationtests/test_LRUnlinking.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,19 @@ | ||
package org.drools; | ||
|
||
global java.util.List results; | ||
|
||
rule "Test LR unlinking with multiple joins on the same object type" | ||
when | ||
$p1 : Person ($name : name != null) | ||
$p2 : Person ($likes : likes != null) | ||
$p3 : Person ($age : age != null) | ||
$p4 : Person ($hair : hair != null) | ||
$p5 : Person ($happy : happy != null) | ||
$p6 : Person (name != $name, | ||
likes == $likes, | ||
age == $age, | ||
hair == $hair, | ||
happy == $happy) | ||
then | ||
results.add( $p6 ); | ||
end |
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
Oops, something went wrong.