[jboss-svn-commits] JBL Code SVN: r31873 - in labs/jbossrules/branches/true_modify_20100215: drools-core/src/main/java/org/drools/reteoo and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Feb 28 15:27:56 EST 2010
Author: tirelli
Date: 2010-02-28 15:27:55 -0500 (Sun, 28 Feb 2010)
New Revision: 31873
Modified:
labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/FromNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngineTest.java
Log:
JBRULES-2339: JBRULES-2340: fixing tests
Modified: labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java 2010-02-28 14:10:36 UTC (rev 31872)
+++ labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java 2010-02-28 20:27:55 UTC (rev 31873)
@@ -172,7 +172,6 @@
final Package pkg = SerializationHelper.serializeObject( builder.getPackage() );
org.drools.reteoo.ReteooRuleBase reteooRuleBase = null;
- // org.drools.leaps.LeapsRuleBase leapsRuleBase = null;
RuleBase ruleBase = getRuleBase();
reteooRuleBase = (org.drools.reteoo.ReteooRuleBase) ruleBase;
ruleBase.addPackage( pkg );
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2010-02-28 14:10:36 UTC (rev 31872)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2010-02-28 20:27:55 UTC (rev 31873)
@@ -852,9 +852,9 @@
}
}
- private LeftTuple[] splitList(final LeftTuple parent,
- final AccumulateContext accctx,
- final boolean isUpdatingSink) {
+ protected LeftTuple[] splitList(final LeftTuple parent,
+ final AccumulateContext accctx,
+ final boolean isUpdatingSink) {
LeftTuple[] matchings = new LeftTuple[2];
// save the matchings list
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/BetaNode.java 2010-02-28 14:10:36 UTC (rev 31872)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/BetaNode.java 2010-02-28 20:27:55 UTC (rev 31873)
@@ -58,7 +58,7 @@
ObjectSinkNode,
RightTupleSink,
NodeMemory {
-
+
// ------------------------------------------------------------
// Instance members
// ------------------------------------------------------------
@@ -79,7 +79,7 @@
private ObjectSinkNode previousObjectSinkNode;
private ObjectSinkNode nextObjectSinkNode;
- protected boolean objectMemory = true; // hard coded to true
+ protected boolean objectMemory = true; // hard coded to true
protected boolean tupleMemoryEnabled;
protected boolean concurrentRightTupleMemory = false;
@@ -131,7 +131,7 @@
objectMemory = in.readBoolean();
tupleMemoryEnabled = in.readBoolean();
concurrentRightTupleMemory = in.readBoolean();
-
+
super.readExternal( in );
}
@@ -147,7 +147,7 @@
out.writeBoolean( objectMemory );
out.writeBoolean( tupleMemoryEnabled );
out.writeBoolean( concurrentRightTupleMemory );
-
+
super.writeExternal( out );
}
@@ -161,7 +161,7 @@
}
return array;
}
-
+
public Behavior[] getBehaviors() {
return this.behavior.getBehaviors();
}
@@ -239,10 +239,8 @@
// handle special cases for Collect and Accumulate to make sure they tidy up their specific data
// like destroying the local FactHandles
if ( object instanceof CollectMemory ) {
- ((CollectNode) this).doRemove( workingMemories[i], ( CollectMemory ) object );
memory = (( CollectMemory )object).betaMemory;
} else if ( object instanceof AccumulateMemory ) {
- ((AccumulateNode) this).doRemove( workingMemories[i], ( AccumulateMemory ) object );
memory = (( AccumulateMemory )object).betaMemory;
} else {
memory = ( BetaMemory ) object;
@@ -250,19 +248,29 @@
Iterator it = memory.getLeftTupleMemory().iterator();
for ( LeftTuple leftTuple = (LeftTuple) it.next(); leftTuple != null; leftTuple = (LeftTuple) it.next() ) {
- if( ! this.isInUse() ) {
- leftTuple.unlinkFromLeftParent();
- leftTuple.unlinkFromRightParent();
- } else if( context.getCleanupAdapter() != null ) {
+ if( context.getCleanupAdapter() != null ) {
for( LeftTuple child = leftTuple.firstChild; child != null; child = child.getLeftParentNext() ) {
- if( child.getLeftTupleSink() == node ) {
+ if( child.getLeftTupleSink() == this ) {
+ // this is a match tuple on collect and accumulate nodes, so just unlink it
+ leftTuple.unlinkFromLeftParent();
+ leftTuple.unlinkFromRightParent();
+ } else {
context.getCleanupAdapter().cleanUp( child, workingMemories[i] );
}
}
-
}
+ leftTuple.unlinkFromLeftParent();
+ leftTuple.unlinkFromRightParent();
}
+ // handle special cases for Collect and Accumulate to make sure they tidy up their specific data
+ // like destroying the local FactHandles
+ if ( object instanceof CollectMemory ) {
+ ((CollectNode) this).doRemove( workingMemories[i], ( CollectMemory ) object );
+ } else if ( object instanceof AccumulateMemory ) {
+ ((AccumulateNode) this).doRemove( workingMemories[i], ( AccumulateMemory ) object );
+ }
+
if( ! this.isInUse() ) {
it = memory.getRightTupleMemory().iterator();
for ( RightTuple rightTuple = (RightTuple) it.next(); rightTuple != null; rightTuple = (RightTuple) it.next() ) {
@@ -278,11 +286,6 @@
leftTuple = temp;
}
}
-
- if ( rightTuple.getRightTupleSink() == null ) {
- // special case for FromNode
- workingMemories[i].getFactHandleFactory().destroyFactHandle( rightTuple.getFactHandle() );
- }
rightTuple.unlinkFromRightParent();
}
workingMemories[i].clearNodeMemory( this );
@@ -302,11 +305,11 @@
}
}
-
+
public void modifyObject(InternalFactHandle factHandle,
ModifyPreviousTuples modifyPreviousTuples,
PropagationContext context,
- InternalWorkingMemory workingMemory) {
+ InternalWorkingMemory workingMemory) {
RightTuple rightTuple = modifyPreviousTuples.removeRightTuple( this );
if ( rightTuple != null ) {
rightTuple.reAdd();
@@ -341,7 +344,7 @@
context,
workingMemory );
}
- }
+ }
public boolean isObjectMemoryEnabled() {
return objectMemory;
@@ -358,18 +361,16 @@
public void setLeftTupleMemoryEnabled(boolean tupleMemoryEnabled) {
this.tupleMemoryEnabled = tupleMemoryEnabled;
}
-
-
public boolean isConcurrentRightTupleMemory() {
- return concurrentRightTupleMemory;
- }
+ return concurrentRightTupleMemory;
+ }
- public void setConcurrentRightTupleMemory(boolean concurrentRightTupleMemory) {
- this.concurrentRightTupleMemory = concurrentRightTupleMemory;
- }
+ public void setConcurrentRightTupleMemory(boolean concurrentRightTupleMemory) {
+ this.concurrentRightTupleMemory = concurrentRightTupleMemory;
+ }
- public String toString() {
+ public String toString() {
return "[ " + this.getClass().getSimpleName() + "(" + this.id + ") ]";
}
@@ -482,16 +483,16 @@
public void setPreviousObjectSinkNode(final ObjectSinkNode previous) {
this.previousObjectSinkNode = previous;
}
-
+
public RightTuple createRightTuple(InternalFactHandle handle,
RightTupleSink sink) {
if ( !this.concurrentRightTupleMemory ) {
- return new RightTuple(handle,
- sink);
+ return new RightTuple( handle,
+ sink );
} else {
- return new ConcurrentRightTuple(handle,
- sink);
+ return new ConcurrentRightTuple( handle,
+ sink );
}
}
-
+
}
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2010-02-28 14:10:36 UTC (rev 31872)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2010-02-28 20:27:55 UTC (rev 31873)
@@ -388,7 +388,7 @@
}
// else do nothing, was false before and false now.
}
- }
+ }
}
this.constraints.resetTuple( memory.betaMemory.getContext() );
@@ -763,9 +763,9 @@
}
}
- private LeftTuple[] splitList(final LeftTuple parent,
- final CollectContext colctx,
- final boolean isUpdatingSink) {
+ protected LeftTuple[] splitList(final LeftTuple parent,
+ final CollectContext colctx,
+ final boolean isUpdatingSink) {
LeftTuple[] matchings = new LeftTuple[2];
// save the matchings list
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java 2010-02-28 14:10:36 UTC (rev 31872)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java 2010-02-28 20:27:55 UTC (rev 31873)
@@ -336,15 +336,15 @@
if ( leftTuple.getBlocker() == null ) {
// not blocked
+ memory.getLeftTupleMemory().add( leftTuple ); // add to memory so other fact handles can attempt to match
+
if ( leftTuple.firstChild != null ) {
// with previous children, retract
- memory.getLeftTupleMemory().add( leftTuple ); // add to memory so other fact handles can attempt to match
this.sink.propagateRetractLeftTuple( leftTuple,
context,
workingMemory );
}
// with no previous children. do nothing.
-
} else if ( leftTuple.firstChild == null ) {
// blocked, with no previous children, assert
this.sink.propagateAssertLeftTuple( leftTuple,
@@ -418,10 +418,12 @@
// iterate all the existing previous blocked LeftTuples
for ( LeftTuple leftTuple = (LeftTuple) firstBlocked; leftTuple != null; ) {
LeftTuple temp = leftTuple.getBlockedNext();
+
+ leftTuple.setBlockedPrevious( null ); // must null these as we are re-adding them to the list
+ leftTuple.setBlockedNext( null );
+
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;
@@ -429,8 +431,6 @@
}
leftTuple.setBlocker( null );
- leftTuple.setBlockedPrevious( null );
- leftTuple.setBlockedNext( null );
this.constraints.updateFromTuple( memory.getContext(),
workingMemory,
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/FromNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2010-02-28 14:10:36 UTC (rev 31872)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2010-02-28 20:27:55 UTC (rev 31873)
@@ -93,19 +93,14 @@
final InternalWorkingMemory workingMemory) {
final FromMemory memory = (FromMemory) workingMemory.getNodeMemory( this );
- Map<Object, RightTuple> matches = null;
- if( this.tupleMemoryEnabled ) {
+ Map<Object, RightTuple> matches = null;
+ if ( this.tupleMemoryEnabled ) {
memory.betaMemory.getLeftTupleMemory().add( leftTuple );
matches = new HashMap<Object, RightTuple>();
memory.betaMemory.getCreatedHandles().put( leftTuple,
matches );
}
- if ( this.sink.size() == 0 ) {
- // nothing to do
- return;
- }
-
this.betaConstraints.updateFromTuple( memory.betaMemory.getContext(),
workingMemory,
leftTuple );
@@ -128,7 +123,7 @@
context,
workingMemory,
memory );
- if( this.tupleMemoryEnabled ) {
+ if ( this.tupleMemoryEnabled ) {
addToCreatedHandlesMap( matches,
rightTuple );
}
@@ -305,11 +300,27 @@
final FromMemory memory = (FromMemory) workingMemory.getNodeMemory( this );
memory.betaMemory.getLeftTupleMemory().remove( leftTuple );
- memory.betaMemory.getCreatedHandles().remove( leftTuple );
+ destroyCreatedHandles( workingMemory,
+ memory,
+ leftTuple );
+ this.sink.propagateRetractLeftTuple( leftTuple,
+ context,
+ workingMemory );
+ }
- this.sink.propagateRetractLeftTupleDestroyRightTuple( leftTuple,
- context,
- workingMemory );
+ @SuppressWarnings("unchecked")
+ private void destroyCreatedHandles(final InternalWorkingMemory workingMemory,
+ final FromMemory memory,
+ final LeftTuple leftTuple) {
+ Map<Object, RightTuple> matches = (Map<Object, RightTuple>) memory.betaMemory.getCreatedHandles().remove( leftTuple );
+ for ( RightTuple rightTuple : matches.values() ) {
+ for ( RightTuple current = rightTuple; current != null; ) {
+ RightTuple next = (RightTuple) current.getNext();
+ workingMemory.getFactHandleFactory().destroyFactHandle( current.getFactHandle() );
+ current.unlinkFromRightParent();
+ current = next;
+ }
+ }
}
public void attach() {
@@ -348,18 +359,17 @@
}
if ( !this.isInUse() ) {
- for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
- FromMemory memory = (FromMemory) workingMemories[i].getNodeMemory( this );
+ for ( InternalWorkingMemory workingMemory : workingMemories ) {
+ FromMemory memory = (FromMemory) workingMemory.getNodeMemory( this );
Iterator it = memory.betaMemory.getLeftTupleMemory().iterator();
for ( LeftTuple leftTuple = (LeftTuple) it.next(); leftTuple != null; leftTuple = (LeftTuple) it.next() ) {
+ destroyCreatedHandles( workingMemory,
+ memory,
+ leftTuple );
leftTuple.unlinkFromLeftParent();
leftTuple.unlinkFromRightParent();
}
-
- // RightTuple is already disconnected via the child LeftTuple in the sink nodes
- // special case exists in the BetaNode to handle destroying of the FactHandle
-
- workingMemories[i].clearNodeMemory( this );
+ workingMemory.clearNodeMemory( this );
}
}
@@ -382,7 +392,7 @@
for ( LeftTuple leftTuple = (LeftTuple) tupleIter.next(); leftTuple != null; leftTuple = (LeftTuple) tupleIter.next() ) {
Map<Object, RightTuple> matches = (Map<Object, RightTuple>) memory.betaMemory.getCreatedHandles().get( leftTuple );
for ( RightTuple rightTuples : matches.values() ) {
- for( RightTuple rightTuple = rightTuples; rightTuple != null; rightTuple = (RightTuple)rightTuples.getNext() ) {
+ for ( RightTuple rightTuple = rightTuples; rightTuple != null; rightTuple = (RightTuple) rightTuples.getNext() ) {
this.sink.propagateAssertLeftTuple( leftTuple,
rightTuple,
context,
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2010-02-28 14:10:36 UTC (rev 31872)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2010-02-28 20:27:55 UTC (rev 31873)
@@ -348,6 +348,11 @@
if ( !node.isInUse() ) {
removeObjectSink( (ObjectSink) node );
}
+ if ( ! this.isInUse() ) {
+ for( InternalWorkingMemory workingMemory : workingMemories ) {
+ workingMemory.clearNodeMemory( this );
+ }
+ }
}
/**
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngineTest.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngineTest.java 2010-02-28 14:10:36 UTC (rev 31872)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngineTest.java 2010-02-28 20:27:55 UTC (rev 31873)
@@ -725,41 +725,6 @@
memory.getLeftTupleMemory().size() );
}
- public void testRuleTerminalNodeStep() throws IOException {
- String str = "TestCase 'testOTN'\nTest 'dummy'\n";
- str += "ObjectTypeNode:\n";
- str += " otn0, java.lang.Integer;\n";
- str += "LeftInputAdapterNode:\n";
- str += " lian0, otn0;\n";
- str += "RuleTerminalNode:\n";
- str += " rtn0, lian0;\n";
- str += "Facts:\n";
- str += " new org.drools.Person('darth', 35), new org.drools.Person('bobba', 35);\n";
- str += "assert:\n";
- str += " otn0, [h0, h1];\n";
- str += "rtn0:\n";
- str += " leftMemory,[[h0], [h1]];\n";
-
- NodeTestResult result = executeTest( str );
- Map<String, Object> map = result.context;
-
- ReteooWorkingMemory wm = ( ReteooWorkingMemory ) map.get( "WorkingMemory" );
- final RuleTerminalNode rtn = ( RuleTerminalNode ) map.get( "rtn0" );
-
- NodeMemory nodeMemory = new NodeMemory() {
- public Object createMemory(RuleBaseConfiguration config) {
- return new UnsupportedOperationException();
- }
-
- public int getId() {
- return rtn.getId();
- }
- };
-
- Set<LeftTuple> set = (Set<LeftTuple>) wm.getNodeMemory(nodeMemory);
- assertEquals( 2, set.size() );
- }
-
public void testNotNodeStep() throws IOException {
String str = "TestCase 'testOTN'\nTest 'dummy'\n";
str += "ObjectTypeNode:\n";
@@ -773,25 +738,24 @@
str += "NotNode:\n";
str += " not0, lian0, otn1;\n";
str += " age, !=, p1;\n";
- str += "RuleTerminalNode:\n";
- str += " rtn0, not0;\n";
+ str += "LeftTupleSink:\n";
+ str += " sink, not0;\n";
str += "Facts:\n";
str += " new org.drools.Person('darth', 35), new org.drools.Person('bobba', 35);\n";
str += "assert:\n";
str += " otn0, [h0];\n";
str += " otn1, [h1];\n";
- str += "rtn0:\n";
- str += " leftMemory, [[h0]];\n";
+ str += "sink:\n";
+ str += " verify, assertLeft, count, 1;\n";
str += "With:\n";
str += " h1, age = 36;\n";
str += "modify:\n";
str += " otn1, [h1];\n";
- str += "rtn0:\n";
- str += " leftMemory, [];\n";
+ str += "sink:\n";
+ str += " verify, retractLeft, count, 1;\n";
NodeTestResult result = executeTest( str );
Map<String, Object> map = result.context;
-
}
private void print(DslStep[] steps) {
More information about the jboss-svn-commits
mailing list