[jboss-svn-commits] JBL Code SVN: r36877 - in labs/jbossrules/branches/5.1.x: drools-core/src/main/java/org/drools/common and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Apr 6 12:17:56 EDT 2011
Author: ge0ffrey
Date: 2011-04-06 12:17:56 -0400 (Wed, 06 Apr 2011)
New Revision: 36877
Modified:
labs/jbossrules/branches/5.1.x/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java
labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/common/PropagationContextImpl.java
labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/core/util/debug/SessionInspector.java
labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java
labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java
Log:
JBRULES-2810: Fixing tuple order on modify tuple calls. Adding test case. (backported from git repo to svn repo - originally done by etirelli)
Modified: labs/jbossrules/branches/5.1.x/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java
===================================================================
--- labs/jbossrules/branches/5.1.x/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java 2011-04-06 16:16:08 UTC (rev 36876)
+++ labs/jbossrules/branches/5.1.x/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java 2011-04-06 16:17:56 UTC (rev 36877)
@@ -1,5 +1,10 @@
package org.drools.integrationtests;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -33,6 +38,7 @@
import org.drools.StatefulSession;
import org.drools.StockTick;
import org.drools.WorkingMemory;
+import org.drools.audit.WorkingMemoryConsoleLogger;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
@@ -49,7 +55,6 @@
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.conf.ClockTypeOption;
import org.drools.time.SessionPseudoClock;
-import static org.mockito.Mockito.*;
public class FirstOrderLogicTest extends TestCase {
protected RuleBase getRuleBase() throws Exception {
@@ -447,6 +452,23 @@
list.size() );
}
+ public void testExists3() throws Exception {
+ final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ kbuilder.add( ResourceFactory.newClassPathResource( "test_Exists_JBRULES_2810.drl",
+ FirstOrderLogicTest.class ),
+ ResourceType.DRL );
+
+ assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
+
+ final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
+ WorkingMemoryConsoleLogger logger = new WorkingMemoryConsoleLogger( ksession );
+ ksession.fireAllRules();
+ ksession.dispose();
+ }
+
public void testForall() throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Forall.drl" ) ) );
Modified: labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/common/PropagationContextImpl.java
===================================================================
--- labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/common/PropagationContextImpl.java 2011-04-06 16:16:08 UTC (rev 36876)
+++ labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/common/PropagationContextImpl.java 2011-04-06 16:17:56 UTC (rev 36877)
@@ -189,4 +189,10 @@
this.originOffset = originOffset;
}
+ @Override
+ public String toString() {
+ return "PropagationContextImpl [activeActivations=" + activeActivations + ", dormantActivations=" + dormantActivations + ", entryPoint=" + entryPoint + ", factHandle=" + factHandle + ", leftTuple=" + leftTuple + ", originOffset="
+ + originOffset + ", propagationNumber=" + propagationNumber + ", rule=" + rule + ", type=" + type + "]";
+ }
+
}
Modified: labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/core/util/debug/SessionInspector.java
===================================================================
--- labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/core/util/debug/SessionInspector.java 2011-04-06 16:16:08 UTC (rev 36876)
+++ labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/core/util/debug/SessionInspector.java 2011-04-06 16:17:56 UTC (rev 36877)
@@ -29,6 +29,7 @@
import org.drools.reteoo.EntryPointNode;
import org.drools.reteoo.EvalConditionNode;
import org.drools.reteoo.ExistsNode;
+import org.drools.reteoo.ForallNotNode;
import org.drools.reteoo.FromNode;
import org.drools.reteoo.JoinNode;
import org.drools.reteoo.LeftInputAdapterNode;
@@ -88,6 +89,8 @@
BetaNodeVisitor.INSTANCE );
this.visitors.put( NotNode.class,
BetaNodeVisitor.INSTANCE );
+ this.visitors.put( ForallNotNode.class,
+ BetaNodeVisitor.INSTANCE );
this.visitors.put( ExistsNode.class,
BetaNodeVisitor.INSTANCE );
this.visitors.put( AccumulateNode.class,
@@ -133,7 +136,7 @@
nodeStack,
info );
} else {
- throw new RuntimeException( "No visitor found for node: " + parent );
+ throw new RuntimeException( "No visitor found for node class: " + parent.getClass()+" node: "+parent );
}
visitChildren( parent,
nodeStack,
Modified: labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java 2011-04-06 16:16:08 UTC (rev 36876)
+++ labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java 2011-04-06 16:17:56 UTC (rev 36877)
@@ -276,11 +276,15 @@
// iterate to find all child tuples for the shared node
while ( childLeftTuple != null && childLeftTuple.getRightParent() == parentRightTuple ) {
// this will iterate for each child node when the
- // the current node is shared
+ // the current node is shared
+
+ // preserve the current LeftTuple, as we need to iterate to the next before re-adding
+ LeftTuple temp = childLeftTuple;
childLeftTuple.getLeftTupleSink().modifyLeftTuple( childLeftTuple,
context,
workingMemory );
childLeftTuple = childLeftTuple.getLeftParentNext();
+ temp.reAddRight();
}
return childLeftTuple;
}
@@ -294,10 +298,14 @@
while ( childLeftTuple != null && childLeftTuple.getLeftParent() == parentLeftTuple ) {
// this will iterate for each child node when the
// the current node is shared
+
+ // preserve the current LeftTuple, as we need to iterate to the next before re-adding
+ LeftTuple temp = childLeftTuple;
childLeftTuple.getLeftTupleSink().modifyLeftTuple( childLeftTuple,
context,
workingMemory );
childLeftTuple = childLeftTuple.getRightParentNext();
+ temp.reAddLeft();
}
return childLeftTuple;
}
Modified: labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2011-04-06 16:16:08 UTC (rev 36876)
+++ labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2011-04-06 16:17:56 UTC (rev 36877)
@@ -241,15 +241,11 @@
workingMemory,
true );
} else {
- // preserve the current LeftTuple, as we need to iterate to the next before re-adding
- LeftTuple temp = childLeftTuple;
childLeftTuple = this.sink.propagateModifyChildLeftTuple( childLeftTuple,
leftTuple,
context,
workingMemory,
true );
- // we must re-add this to ensure deterministic iteration
- temp.reAddLeft();
}
} else if ( childLeftTuple != null && childLeftTuple.getLeftParent() == leftTuple ) {
childLeftTuple = this.sink.propagateRetractChildLeftTuple( childLeftTuple,
@@ -329,15 +325,11 @@
workingMemory,
true );
} else {
- // preserve the current LeftTuple, as we need to iterate to the next before re-adding
- LeftTuple temp = childLeftTuple;
childLeftTuple = this.sink.propagateModifyChildLeftTuple( childLeftTuple,
rightTuple,
context,
workingMemory,
true );
- // we must re-add this to ensure deterministic iteration
- temp.reAddRight();
}
} else if ( childLeftTuple != null && childLeftTuple.getRightParent() == rightTuple ) {
childLeftTuple = this.sink.propagateRetractChildLeftTuple( childLeftTuple,
Modified: labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
===================================================================
--- labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java 2011-04-06 16:16:08 UTC (rev 36876)
+++ labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java 2011-04-06 16:17:56 UTC (rev 36877)
@@ -117,7 +117,6 @@
public void assertLeftTuple(final LeftTuple tuple,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
-
// creating a dummy fact handle to wrap the tuple
final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( tuple,
workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.getEntryPoint(),
@@ -147,10 +146,9 @@
final InternalWorkingMemory workingMemory) {
final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );
-
// retrieve handle from memory
final InternalFactHandle factHandle = (InternalFactHandle) memory.remove( tuple );
-
+
for ( RightTuple rightTuple = factHandle.getFirstRightTuple(); rightTuple != null; rightTuple = (RightTuple) rightTuple.getHandleNext() ) {
rightTuple.getRightTupleSink().retractRightTuple( rightTuple,
context,
@@ -332,4 +330,12 @@
return this.tupleMemoryEnabled == other.tupleMemoryEnabled && this.tupleSource.equals( other.tupleSource );
}
+ @Override
+ public String toString() {
+ return "RightInputAdapterNode(" + id + ")[ tupleMemoryEnabled=" + tupleMemoryEnabled + ", tupleSource=" + tupleSource + ", source="
+ + source + ", associations=" + associations.keySet() + ", partitionId=" + partitionId + "]";
+ }
+
+
+
}
Modified: labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java 2011-04-06 16:16:08 UTC (rev 36876)
+++ labs/jbossrules/branches/5.1.x/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java 2011-04-06 16:17:56 UTC (rev 36877)
@@ -239,6 +239,8 @@
childLeftTuple.getLeftTupleSink().modifyLeftTuple( childLeftTuple,
context,
workingMemory );
+ // re-order right to keep order consistency
+ childLeftTuple.reAddRight();
return childLeftTuple.getLeftParentNext();
}
@@ -250,6 +252,8 @@
childLeftTuple.getLeftTupleSink().modifyLeftTuple( childLeftTuple,
context,
workingMemory );
+ // re-order right to keep order consistency
+ childLeftTuple.reAddLeft();
return childLeftTuple.getRightParentNext();
}
More information about the jboss-svn-commits
mailing list