[jboss-svn-commits] JBL Code SVN: r31761 - in labs/jbossrules/branches/true_modify_20100215: drools-compiler/src/test/java/org/drools/rule/builder/dialect/java and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Feb 21 12:44:25 EST 2010
Author: tirelli
Date: 2010-02-21 12:44:24 -0500 (Sun, 21 Feb 2010)
New Revision: 31761
Added:
labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/resources/org/drools/reteoo/test/NotNodeModifyTest2.nodeTestCase
Removed:
labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/resources/org/drools/reteoo/test/ForallNodeAssertRetractTest.data
Modified:
labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/JavaConsequenceBuilderTest.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/NotNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/java/org/drools/reteoo/test/dsl/NotNodeStep.java
Log:
JBRULES-2340: JBRULES-2339: fixing tests
Modified: labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2010-02-21 17:09:11 UTC (rev 31760)
+++ labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2010-02-21 17:44:24 UTC (rev 31761)
@@ -91,6 +91,7 @@
import org.drools.Worker;
import org.drools.WorkingMemory;
import org.drools.Cheesery.Maturity;
+import org.drools.audit.WorkingMemoryConsoleLogger;
import org.drools.audit.WorkingMemoryFileLogger;
import org.drools.audit.WorkingMemoryInMemoryLogger;
import org.drools.base.ClassObjectType;
@@ -2644,6 +2645,7 @@
ruleBase.addPackage( pkg );
ruleBase = SerializationHelper.serializeObject( ruleBase );
WorkingMemory workingMemory = ruleBase.newStatefulSession();
+ WorkingMemoryConsoleLogger logger = new WorkingMemoryConsoleLogger(workingMemory);
final List list = new ArrayList();
workingMemory.setGlobal( "list",
@@ -2658,13 +2660,15 @@
// workingMemory = SerializationHelper.serializeObject(workingMemory);
workingMemory.fireAllRules();
+ List<String> results = (List<String>) workingMemory.getGlobal( "list" );
+ System.out.println(results);
assertEquals( 5,
- ((List) workingMemory.getGlobal( "list" )).size() );
- assertTrue( ((List) workingMemory.getGlobal( "list" )).contains( "first" ) );
- assertTrue( ((List) workingMemory.getGlobal( "list" )).contains( "second" ) );
- assertTrue( ((List) workingMemory.getGlobal( "list" )).contains( "third" ) );
- assertTrue( ((List) workingMemory.getGlobal( "list" )).contains( "fourth" ) );
- assertTrue( ((List) workingMemory.getGlobal( "list" )).contains( "fifth" ) );
+ results.size() );
+ assertTrue( results.contains( "first" ) );
+ assertTrue( results.contains( "second" ) );
+ assertTrue( results.contains( "third" ) );
+ assertTrue( results.contains( "fourth" ) );
+ assertTrue( results.contains( "fifth" ) );
}
Modified: labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/JavaConsequenceBuilderTest.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/JavaConsequenceBuilderTest.java 2010-02-21 17:09:11 UTC (rev 31760)
+++ labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/JavaConsequenceBuilderTest.java 2010-02-21 17:44:24 UTC (rev 31761)
@@ -135,8 +135,12 @@
analysis,
(String) ruleDescr.getConsequence() );
- String expected = " System.out.println(\"this is a test\");\n" + "{ org.drools.Cheese __obj__ = (org.drools.Cheese) ( $cheese );\n" + "modifyRetract( __obj__ );\n" + "__obj__.setPrice( 10 );\n" + "__obj__.setAge( age );\n"
- + "modifyInsert( __obj__ );}\n" + "System.out.println(\"we are done\");\n";
+ String expected = " System.out.println(\"this is a test\");\n" +
+ "{ org.drools.Cheese __obj__ = (org.drools.Cheese) ( $cheese );\n" +
+ "__obj__.setPrice( 10 );\n" +
+ "__obj__.setAge( age );\n" +
+ "update( __obj__ );}\n" +
+ "System.out.println(\"we are done\");\n";
assertNotNull( context.getErrors().toString(),
fixed );
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java 2010-02-21 17:09:11 UTC (rev 31760)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java 2010-02-21 17:44:24 UTC (rev 31761)
@@ -55,11 +55,11 @@
// ------------------------------------------------------------
// Instance members
// ------------------------------------------------------------
-
+
/**
*
*/
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
/** The semantic <code>Test</code>. */
private EvalCondition condition;
@@ -205,6 +205,68 @@
workingMemory );
}
+ public void modifyLeftTuple(InternalFactHandle factHandle,
+ ModifyPreviousTuples modifyPreviousTuples,
+ PropagationContext context,
+ InternalWorkingMemory workingMemory) {
+ LeftTuple leftTuple = modifyPreviousTuples.removeLeftTuple( this );
+ if ( leftTuple != null ) {
+ leftTuple.reAdd(); //
+ // LeftTuple previously existed, so continue as modify
+ modifyLeftTuple( leftTuple,
+ context,
+ workingMemory );
+ } else {
+ // LeftTuple does not exist, so create and continue as assert
+ assertLeftTuple( new LeftTuple( factHandle,
+ this,
+ true ),
+ context,
+ workingMemory );
+ }
+ }
+
+ public void modifyLeftTuple(LeftTuple leftTuple,
+ PropagationContext context,
+ InternalWorkingMemory workingMemory) {
+ final EvalMemory memory = (EvalMemory) workingMemory.getNodeMemory( this );
+ boolean wasPropagated = false;
+
+ if ( memory.tupleMemory.contains( leftTuple ) ) {
+ memory.tupleMemory.remove( leftTuple );
+ wasPropagated = true;
+ }
+ final boolean allowed = this.condition.isAllowed( leftTuple,
+ workingMemory,
+ memory.context );
+
+ if ( allowed ) {
+ // re-add tuple to the end of the list
+ memory.tupleMemory.add( leftTuple );
+ if ( wasPropagated ) {
+ // modify
+ this.sink.propagateModifyChildLeftTuple( leftTuple,
+ context,
+ workingMemory,
+ this.tupleMemoryEnabled );
+ } else {
+ // assert
+ this.sink.propagateAssertLeftTuple( leftTuple,
+ context,
+ workingMemory,
+ this.tupleMemoryEnabled );
+ }
+ } else {
+ if( wasPropagated ) {
+ // retract
+ this.sink.propagateRetractLeftTuple( leftTuple,
+ context,
+ workingMemory );
+ }
+ // else do nothing
+ }
+ }
+
/**
* Produce a debug string.
*
@@ -262,19 +324,19 @@
if ( !node.isInUse() ) {
removeTupleSink( (LeftTupleSink) node );
}
-
+
if ( !this.isInUse() ) {
for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
- EvalMemory memory = ( EvalMemory ) workingMemories[i].getNodeMemory( this );
+ EvalMemory memory = (EvalMemory) workingMemories[i].getNodeMemory( this );
Iterator it = memory.getLeftTupleMemory().iterator();
for ( LeftTuple leftTuple = (LeftTuple) it.next(); leftTuple != null; leftTuple = (LeftTuple) it.next() ) {
leftTuple.unlinkFromLeftParent();
leftTuple.unlinkFromRightParent();
- }
+ }
workingMemories[i].clearNodeMemory( this );
}
}
-
+
if ( !context.alreadyVisited( this.tupleSource ) ) {
this.tupleSource.remove( context,
builder,
@@ -326,10 +388,10 @@
public void setPreviousLeftTupleSinkNode(final LeftTupleSinkNode previous) {
this.previousTupleSinkNode = previous;
}
-
+
public short getType() {
return NodeTypeEnums.EvalConditionNode;
- }
+ }
public static class EvalMemory
implements
@@ -368,19 +430,4 @@
}
}
- public void modifyLeftTuple(InternalFactHandle factHandle,
- ModifyPreviousTuples modifyPreviousTuples,
- PropagationContext context,
- InternalWorkingMemory workingMemory) {
- // TODO Auto-generated method stub
-
- }
-
- public void modifyLeftTuple(LeftTuple leftTuple,
- PropagationContext context,
- InternalWorkingMemory workingMemory) {
- // TODO Auto-generated method stub
-
- }
-
}
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/NotNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2010-02-21 17:09:11 UTC (rev 31760)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2010-02-21 17:44:24 UTC (rev 31761)
@@ -146,7 +146,6 @@
this.constraints.resetFactHandle( memory.getContext() );
}
-
/**
*/
public void retractRightTuple(final RightTuple rightTuple,
@@ -354,25 +353,23 @@
// now process existing blocks, we only process existing and not new from above loop
// determine if we are in the same bucket or not, as if we are we need to re-test the current FactHandle
- boolean sameIndex = (leftMemory.isIndexed() && firstLeftTuple == leftMemory.getFirst( firstBlocked ));
+ //boolean sameIndex = (leftMemory.isIndexed() && firstLeftTuple == leftMemory.getFirst( firstBlocked ));
final RightTuple rootBlocker = (RightTuple) rightTuple.getNext();
// iterate all the existing previous blocked LeftTuples
for ( LeftTuple leftTuple = (LeftTuple) firstBlocked; leftTuple != null; ) {
- if ( sameIndex && this.constraints.isAllowedCachedRight( memory.getContext(),
- leftTuple ) ) {
- LeftTuple temp = leftTuple.getBlockedNext();
+ LeftTuple temp = leftTuple.getBlockedNext();
+ if ( this.constraints.isAllowedCachedRight( memory.getContext(),
+ leftTuple ) ) {
leftTuple.setBlockedPrevious( null ); // must null these as we are re-adding them to the list
leftTuple.setBlockedNext( null );
// in the same bucket and it still blocks, so add back into blocked list
rightTuple.addBlocked( leftTuple ); // no need to set on LeftTuple, as it already has the reference
- leftTuple = temp.getBlockedNext();
+ leftTuple = temp;
continue;
}
- LeftTuple temp = leftTuple.getBlockedNext();
-
leftTuple.setBlocker( null );
leftTuple.setBlockedPrevious( null );
leftTuple.setBlockedNext( null );
@@ -415,7 +412,7 @@
memory.getRightTupleMemory().remove( rightTuple );
memory.getRightTupleMemory().add( rightTuple );
}
-
+
/**
*/
protected void propagateAssertLeftTuple(final PropagationContext context,
@@ -426,7 +423,6 @@
workingMemory,
this.tupleMemoryEnabled );
}
-
/**
*/
@@ -436,7 +432,8 @@
this.sink.propagateRetractLeftTuple( leftTuple,
context,
workingMemory );
- }
+ }
+
/**
*/
protected void propagateModifyChildLeftTuple(final PropagationContext context,
@@ -446,7 +443,7 @@
context,
workingMemory,
this.tupleMemoryEnabled );
- }
+ }
/**
*/
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/java/org/drools/reteoo/test/dsl/NotNodeStep.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/java/org/drools/reteoo/test/dsl/NotNodeStep.java 2010-02-21 17:09:11 UTC (rev 31760)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/java/org/drools/reteoo/test/dsl/NotNodeStep.java 2010-02-21 17:44:24 UTC (rev 31761)
@@ -20,6 +20,8 @@
import java.util.List;
import java.util.Map;
+import org.drools.common.BetaConstraints;
+import org.drools.common.EmptyBetaConstraints;
import org.drools.common.SingleBetaConstraints;
import org.drools.reteoo.LeftTupleSource;
import org.drools.reteoo.MockObjectSource;
@@ -30,6 +32,7 @@
import org.drools.rule.BehaviorManager;
import org.drools.rule.Declaration;
import org.drools.spi.BetaNodeFieldConstraint;
+import org.mockito.Mockito;
public class NotNodeStep
implements
@@ -53,38 +56,43 @@
LeftTupleSource leftTupleSource;
if ( "mock".equals( leftInput ) ) {
- leftTupleSource = new MockTupleSource( buildContext.getNextId() );
+ leftTupleSource = Mockito.mock( LeftTupleSource.class );;
} else {
leftTupleSource = (LeftTupleSource) context.get( leftInput );
}
ObjectSource rightObjectSource;
if ( "mock".equals( rightInput ) ) {
- rightObjectSource = new MockObjectSource( buildContext.getNextId() );
+ rightObjectSource = Mockito.mock( ObjectSource.class );;
} else {
rightObjectSource = (ObjectSource) context.get( rightInput );
}
- a = args.get( 1 );
- String fieldName = a[0].trim();
- String operator = a[1].trim();
- String var = a[2].trim();
+ BetaConstraints constraints;
+ if( args.size() > 1 ) {
+ a = args.get( 1 );
+ String fieldName = a[0].trim();
+ String operator = a[1].trim();
+ String var = a[2].trim();
- Declaration declr = (Declaration) context.get( var );
+ Declaration declr = (Declaration) context.get( var );
- BetaNodeFieldConstraint betaConstraint;
- try {
- betaConstraint = this.reteTesterHelper.getBoundVariableConstraint( declr.getPattern(),
- fieldName,
- declr,
- operator );
- } catch ( IntrospectionException e ) {
- throw new IllegalArgumentException();
+ BetaNodeFieldConstraint betaConstraint;
+ try {
+ betaConstraint = this.reteTesterHelper.getBoundVariableConstraint( declr.getPattern(),
+ fieldName,
+ declr,
+ operator );
+ } catch ( IntrospectionException e ) {
+ throw new IllegalArgumentException();
+ }
+
+ constraints = new SingleBetaConstraints( betaConstraint,
+ buildContext.getRuleBase().getConfiguration() );
+ } else {
+ constraints = new EmptyBetaConstraints();
}
- SingleBetaConstraints constraints = new SingleBetaConstraints( betaConstraint,
- buildContext.getRuleBase().getConfiguration() );
-
NotNode notNode = new NotNode( buildContext.getNextId(),
leftTupleSource,
rightObjectSource,
Deleted: labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/resources/org/drools/reteoo/test/ForallNodeAssertRetractTest.data
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/resources/org/drools/reteoo/test/ForallNodeAssertRetractTest.data 2010-02-21 17:09:11 UTC (rev 31760)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/resources/org/drools/reteoo/test/ForallNodeAssertRetractTest.data 2010-02-21 17:44:24 UTC (rev 31761)
@@ -1,223 +0,0 @@
-ObjectTypeNode
- otnLeft1, org.drools.Person
-LeftInputAdapterNode
- lian1, otnLeft1
-ObjectTypeNode
- otnRight1, org.drools.Bus
-ObjectTypeNode
- otnRight2, org.drools.Person
-Binding
- p1, 0, org.drools.Person, city
-ForAllNode
- forall1, lian1,
-
- not1, , otnRight1
- age, !=, p1
-JoinNode
- join2, not1, otnRight2
- age, ==,
-Facts
- new org.drools.Person('darth', 35), new org.drools.Person('bobba', 35)
- new org.drools.Person('yoda', 35), new org.drools.Person('luke', 35)
- new org.drools.Person('dave', 35), new org.drools.Person('bob', 36)
- new org.drools.Person('obi', 36), new org.drools.Person('han', 37)
-
- // Person( $state ) forall( Bus(
-/**
- * check single left assertion and retraction
- */
-assert
- otnLeft1 [h0]
-not1
- leftMemory [[h0]]
-join2
- leftMemory [[h0]]
-retract
- otnLeft1 [h0]
-not1
- leftMemory []
-join2
- leftMemory []
-
-/**
- * check single right assertion and retraction
- */
-assert
- otnRight1 [h1]
-not1
- rightMemory [h1]
-join2
- leftMemory []
-retract
- otnRight1 [h1]
-not1
- rightMemory []
-
-/**
- * check single left then right assertion, where age == age (does not match not)
- */
-assert
- otnLeft1 [h0]
-not1
- leftMemory [[h0]]
- rightMemory []
-join2
- leftMemory [[h0]]
-assert
- otnRight1 [h1]
-not1
- leftMemory [[h0]]
- rightMemory [h1]
-join2
- leftMemory [[h0]]
-retract
- otnRight1 [h1]
- otnRight1 []
-join2
- leftMemory [[h0]]
-retract
- otnLeft1 [h0]
-not1
- leftMemory []
- rightMemory []
-join2
- leftMemory []
-
-/**
- * check single left then right assertion, where age != age (matches not)
- */
-assert
- otnLeft1 [h0]
-not1
- leftMemory [[h0]] // h0 is here, it'll disapear soon....
- rightMemory []
-join2
- leftMemory [[h0]]
-assert
- otnRight1 [h5]
-not1
- leftMemory [] // h0 disappears as h5 blocks it, and removes it from memory
- rightMemory [h5]
-join2
- leftMemory []
-retract
- otnRight1 [h5]
-not1
- leftMemory [[h0]] // h0 is put back in, as h5 no longer blocks
- rightMemory []
-join2
- leftMemory [[h0]]
-retract
- otnLeft1 [h0]
-not1
- leftMemory []
- rightMemory []
-join2
- leftMemory []
-
-
-/**
- * check single right then left assertion, where age != age (matches not)
- */
-assert
- otnRight1 [h5]
-not1
- leftMemory []
- rightMemory [h5]
-join2
- leftMemory []
-assert
- otnLeft1 [h0]
-not1
- leftMemory [] // although it's inserted, you can't see it in the memory as h5 blocks it
- rightMemory [h5]
-join2
- leftMemory []
-retract
- otnRight1 [h5]
-not1
- leftMemory [[h0]] // h5 no longer blocks, so put back in
- rightMemory []
-join2
- leftMemory [[h0]]
-retract
- otnLeft1 [h0]
-not1
- leftMemory []
- rightMemory []
-join2
- leftMemory []
-
-/**
- * check single right then left assertion, where age == age (does not match not)
- */
-assert
- otnRight1 [h1]
-not1
- leftMemory []
- rightMemory [h1]
-join2
- leftMemory []
-assert
- otnLeft1 [h0]
-not1
- leftMemory [[h0]]
- rightMemory [h1]
-join2
- leftMemory [[h0]]
-retract
- otnRight1 [h1]
-not1
- leftMemory [[h0]]
- rightMemory []
-join2
- leftMemory [[h0]]
-retract
- otnLeft1 [h0]
-not1
- leftMemory []
- rightMemory []
-join2
- leftMemory []
-
-// here
-
-
-/**
- * assert two left and two right, with iterative retract and assert, age != age (not matches)
- */
-assert
- otnLeft1 [h0, h1]
-not1
- leftMemory [[h0], [h1]]
- rightMemory []
-join2
- leftMemory [[h0], [h1]]
-assert
- otnRight1 [h5]
-not1
- leftMemory [] //h0 and h1 are blocked, by h5, so removed
- rightMemory [h5, h6]
-join2
- leftMemory []
-assert
- otnRight1 [h6]
-not1
- leftMemory [] //h0 and h1 are still blocked
- rightMemory [h5, h6]
-join2
- leftMemory []
-retract
- otnRight1 [h5] // retract h5, the facts should still be blocked now by h6
-not1
- leftMemory [] //h0 and h1 are still blocked
- rightMemory [h6]
-join2
- leftMemory []
-retract
- otnRight1 [h6] // now there are no blockers
-not1
- leftMemory [[h0], [h1]] // both facts go back in
- rightMemory []
-join2
- leftMemory [[h0], [h1]] // both facts propagate
\ No newline at end of file
Added: labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/resources/org/drools/reteoo/test/NotNodeModifyTest2.nodeTestCase
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/resources/org/drools/reteoo/test/NotNodeModifyTest2.nodeTestCase (rev 0)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/resources/org/drools/reteoo/test/NotNodeModifyTest2.nodeTestCase 2010-02-21 17:44:24 UTC (rev 31761)
@@ -0,0 +1,44 @@
+TestCase "Not Node modify"
+
+import org.drools.Person;
+import org.drools.Cheese;
+
+Setup
+ NotNode:
+ not, mock, mock;
+ LeftTupleSink:
+ sink, not;
+ Facts:
+ new Person('darth', 35), // h0
+ new Person('bobba', 35), // h1
+ new Cheese('stilton', 10); // h2
+
+/**
+ * check single left, then right assertion, then modify right and still match
+ */
+Test "Not node modify right, still matches"
+ assert:
+ not, [[h0]];
+ not:
+ leftMemory, [[h0]];
+ rightMemory, [];
+ sink:
+ verify, assertLeft, count, 1;
+ assert:
+ not, [h2];
+ not:
+ leftMemory, [];
+ rightMemory, [h2];
+ sink:
+ verify, assertLeft, count, 1;
+ verify, retractLeft, count, 1;
+ modify:
+ not, [h2];
+ not:
+ leftMemory, [];
+ rightMemory, [h2];
+ sink:
+ verify, assertLeft, count, 1;
+ verify, retractLeft, count, 1;
+ verify, modifyLeft, count, 0; // not node does not propagate a modify from the right
+
Property changes on: labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/resources/org/drools/reteoo/test/NotNodeModifyTest2.nodeTestCase
___________________________________________________________________
Name: svn:executable
+ *
More information about the jboss-svn-commits
mailing list