[jboss-svn-commits] JBL Code SVN: r36028 - in labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test: java/org/drools/reteoo/test/dsl and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 23 01:14:48 EST 2010
Author: leo_gomes
Date: 2010-11-23 01:14:48 -0500 (Tue, 23 Nov 2010)
New Revision: 36028
Modified:
labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java
labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngineTest.java
labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/java/org/drools/reteoo/test/dsl/ConfigStep.java
labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/ExistsNodeAssertRetractTest.nodeTestCase
labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/NotNodeAssertRetractTest.nodeTestCase
labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/RightUnlinkingComplex.nodeTestCase
labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/RightUnlinkingModify.nodeTestCase
Log:
JBRULES-2776: Fixing problems with ReteDslTestEngine and improving L&R tests.
Modified: labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java
===================================================================
--- labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java 2010-11-23 04:39:43 UTC (rev 36027)
+++ labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java 2010-11-23 06:14:48 UTC (rev 36028)
@@ -326,7 +326,7 @@
+ print(leftMemory, lrUnlinkingEnabled));
} else if (expectedLeftTuples.isEmpty()
&& leftMemory.size() == 0) {
- return;
+ continue;
}
// we always lookup from the first element, in case it's
@@ -351,7 +351,7 @@
if (lrUnlinkingEnabled) {
// When L&R Unlinking is active, we need to sort the tuples here,
// because we might have asserted things in the wrong order,
- // because linking a node's side means populating its memory
+ // since linking a node's side means populating its memory
// from the OTN which stores things in a hash-set, so insertion order is not kept.
Collections.sort(leftTuples, new LeftTupleComparator());
}
@@ -375,7 +375,7 @@
listString, vars);
RightTupleMemory rightMemory = memory.getRightTupleMemory();
-
+
if (expectedFactHandles.isEmpty()
&& rightMemory.size() != 0) {
throw new AssertionFailedError("line " + step.getLine()
@@ -383,7 +383,7 @@
+ print(rightMemory));
} else if (expectedFactHandles.isEmpty()
&& rightMemory.size() == 0) {
- return;
+ continue;
}
RightTuple first = new RightTuple(
@@ -394,7 +394,24 @@
.getNext()) {
actualRightTuples.add(rightTuple);
}
+
+ if(lrUnlinkingEnabled) {
+ // FIXME:
+ // This is a temporary hack, because I think there might be a bug
+ // in the above iteration. To be verified with ETirelli.
+ actualRightTuples.clear();
+
+ Iterator it = rightMemory.iterator();
+ for (RightTuple rt = (RightTuple) it.next(); rt != null; rt = (RightTuple) it.next()) {
+ actualRightTuples.add(rt);
+ }
+ // Need to sort before comparing, because with L&R unlinking
+ // the order of insertion is not kept.
+ Collections.sort(actualRightTuples, new RightTupleComparator());
+ }
+
+
if (expectedFactHandles.size() != actualRightTuples.size()) {
throw new AssertionFailedError("line " + step.getLine()
+ ": right Memory expected "
@@ -945,7 +962,20 @@
return 0;
}
}
+
+ private final class RightTupleComparator implements Comparator<RightTuple> {
+ public int compare(RightTuple o1, RightTuple o2) {
+
+ int diff = o1.getFactHandle().getId() - o2.getFactHandle().getId();
+
+ if (diff != 0)
+ return diff;
+
+ return 0;
+ }
+ }
+
public static class EmptyNotifier extends RunNotifier {
public static final EmptyNotifier INSTANCE = new EmptyNotifier();
Modified: labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngineTest.java
===================================================================
--- labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngineTest.java 2010-11-23 04:39:43 UTC (rev 36027)
+++ labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngineTest.java 2010-11-23 06:14:48 UTC (rev 36028)
@@ -741,7 +741,7 @@
public void testConfigOptions() throws IOException {
String str = "TestCase 'testOTN'\nTest 'dummy'\n";
str += "Config:\n";
- str += " lrUnlinkingEnabled, true;\n";
+ str += " drools.lrUnlinkingEnabled, true;\n";
str += "ObjectTypeNode:\n";
str += " otn1, java.lang.Integer;\n";
Modified: labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/java/org/drools/reteoo/test/dsl/ConfigStep.java
===================================================================
--- labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/java/org/drools/reteoo/test/dsl/ConfigStep.java 2010-11-23 04:39:43 UTC (rev 36027)
+++ labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/java/org/drools/reteoo/test/dsl/ConfigStep.java 2010-11-23 06:14:48 UTC (rev 36028)
@@ -12,9 +12,33 @@
import org.drools.reteoo.builder.BuildContext;
/**
- * A step in the setup of a nodeTestCase, it allows configuration parameters to
- * be passed.
+ * <p>
+ * A step in the setup of a nodeTestCase, it allows any configuration parameters
+ * to be passed. </br> Note that the RuleBase and Working Memory are recreated
+ * and changed in the context, so the configuration step should be the first one
+ * in the setup of your nodeTestCase or you may face inconsistent behavior.
+ * </p>
+ * <b>Usage:</b>
*
+ * <pre>
+ * Setup
+ * Config:
+ * drools.lrUnlinkingEnabled, true;
+ * ObjectTypeNode:
+ * otnLeft1, org.drools.Person;
+ * LeftInputAdapterNode:
+ * lian0, otnLeft1;
+ * ObjectTypeNode:
+ * otnRight1, org.drools.Person;
+ * Binding:
+ * p1, 0, org.drools.Person, age;
+ * JoinNode:
+ * join1, lian0, otnRight1;
+ * age, !=, p1;
+ * Facts:
+ * new org.drools.Person('darth', 35), new org.drools.Person('bobba', 36),
+ *</pre>
+ *
* @author lgomes
*
*/
@@ -25,7 +49,7 @@
RuleBaseConfiguration conf = new RuleBaseConfiguration();
for (String[] configOption : args) {
- conf.setProperty("drools." + configOption[0], configOption[1]);
+ conf.setProperty(configOption[0], configOption[1]);
}
ReteooRuleBase rbase = new ReteooRuleBase("ID", conf);
Modified: labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/ExistsNodeAssertRetractTest.nodeTestCase
===================================================================
--- labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/ExistsNodeAssertRetractTest.nodeTestCase 2010-11-23 04:39:43 UTC (rev 36027)
+++ labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/ExistsNodeAssertRetractTest.nodeTestCase 2010-11-23 06:14:48 UTC (rev 36028)
@@ -131,7 +131,7 @@
otnRight1, [h5];
exists1:
leftMemory, []; //h0 and h1 are blocked, by h5, so removed
- rightMemory, [h5, h6];
+ rightMemory, [h5];
join2:
leftMemory, [[h0], [h1]];
assert:
Modified: labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/NotNodeAssertRetractTest.nodeTestCase
===================================================================
--- labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/NotNodeAssertRetractTest.nodeTestCase 2010-11-23 04:39:43 UTC (rev 36027)
+++ labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/NotNodeAssertRetractTest.nodeTestCase 2010-11-23 06:14:48 UTC (rev 36028)
@@ -198,7 +198,7 @@
otnRight1, [h5];
not1:
leftMemory, []; //h0 and h1 are blocked, by h5, so removed
- rightMemory, [h5, h6];
+ rightMemory, [h5];
join2:
leftMemory, [];
assert:
Modified: labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/RightUnlinkingComplex.nodeTestCase
===================================================================
--- labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/RightUnlinkingComplex.nodeTestCase 2010-11-23 04:39:43 UTC (rev 36027)
+++ labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/RightUnlinkingComplex.nodeTestCase 2010-11-23 06:14:48 UTC (rev 36028)
@@ -1,8 +1,12 @@
TestCase "RightUnlinkingComplex"
+/*
+* A bit more complex, this test case shows that memories get properly populated
+* when there are loops like the one between Join1 and Join2 here.
+*/
Setup
Config:
- lrUnlinkingEnabled, true;
+ drools.lrUnlinkingEnabled, true;
ObjectTypeNode:
otnLeft1, org.drools.Person;
LeftInputAdapterNode:
@@ -27,19 +31,21 @@
Facts:
new org.drools.Person('darth', 35, 'stilton'), new org.drools.Person('bobba', 36, 'brie'),
new org.drools.Person('yoda', 37, 'cammembert'), new org.drools.Person('luke', 38, 'minas'),
- new org.drools.Person('dave', 33, 'prato'), new org.drools.Person('bob', 32, 'parmigiano'),
- new org.drools.Person('dave', 31, 'stilton'), new org.drools.Person('bob', 30, 'minas');
+ new org.drools.Person('dave', 33, 'prato'), new org.drools.Person('bob', 32, 'stilton'),
+ new org.drools.Person('dave', 31, 'parmigiano'), new org.drools.Person('bob', 30, 'minas');
Test "RightUnlinkingComplex"
assert:
otnRight1, [h1];
+
join1:
leftMemory, [];
- rightMemory, []; // right is side is unlinked - PROBLEM here!
+ rightMemory, []; // right side is unlinked.
assert:
- otnLeft1, [h0];
+ otnLeft1, [h0]; // a left propagation will link the right side and trigger
+ // its population by calling updateSink in the OTN.
join1:
leftMemory, [[h0]];
rightMemory, [h1];
@@ -54,4 +60,44 @@
otnRight2, [h3];
join3:
leftMemory, [];
- rightMemory, [];
+ rightMemory, []; // right memory remains empty, since node is unlinked.
+
+ assert:
+ otnRight1, [h5]; // age is != and likes ==
+ join1:
+ leftMemory, [[h0]];
+ rightMemory, [h1, h5];
+ join2:
+ leftMemory, [[h0,h1],[h0,h5]];
+ rightMemory, [h1,h5];
+ join3:
+ leftMemory, [[h0,h1,h5], [h0,h5,h5]];
+ rightMemory, [h3]; // populated, since right side is now linked.
+
+ assert:
+ otnRight2, [h7];
+ join3:
+ rightMemory, [h3,h7]; // now right memory is linked
+ // and can be asserted normally.
+
+ retract:
+ otnRight1, [h5];
+ join1:
+ rightMemory, [h1];
+ join2:
+ leftMemory, [[h0,h1]];
+ rightMemory, [h1];
+ join3:
+ leftMemory, [];
+ rightMemory, [h3,h7];
+
+ // Now, even if the left memory is empty, the right side will stay
+ // linked to avoid churn.
+ assert:
+ otnRight2, [h2];
+ join3:
+ leftMemory, [];
+ rightMemory, [h2,h3,h7];
+
+
+
Modified: labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/RightUnlinkingModify.nodeTestCase
===================================================================
--- labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/RightUnlinkingModify.nodeTestCase 2010-11-23 04:39:43 UTC (rev 36027)
+++ labs/jbossrules/branches/lr_unlinking_20101116/drools-core/src/test/resources/org/drools/reteoo/test/RightUnlinkingModify.nodeTestCase 2010-11-23 06:14:48 UTC (rev 36028)
@@ -2,7 +2,7 @@
Setup
Config:
- lrUnlinkingEnabled, true;
+ drools.lrUnlinkingEnabled, true;
ObjectTypeNode:
otnLeft1, org.drools.Person;
LeftInputAdapterNode:
More information about the jboss-svn-commits
mailing list