[jboss-svn-commits] JBL Code SVN: r13536 - in labs/jbossrules/trunk: drools-compiler/src/test/resources/org/drools/integrationtests and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jul 15 11:33:28 EDT 2007
Author: tirelli
Date: 2007-07-15 11:33:28 -0400 (Sun, 15 Jul 2007)
New Revision: 13536
Added:
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CollectAlphaRestriction.drl
Modified:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
Log:
JBRULES-982: fixing bug on collect node when the source pattern contains an alpha restriction
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java 2007-07-15 14:02:38 UTC (rev 13535)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java 2007-07-15 15:33:28 UTC (rev 13536)
@@ -462,6 +462,67 @@
}
+ public void testCollectModifyAlphaRestriction() throws Exception {
+ // read in the source
+ final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_CollectAlphaRestriction.drl" ) );
+ final RuleBase ruleBase = loadRuleBase( reader );
+
+ final WorkingMemory wm = ruleBase.newStatefulSession();
+ final List results = new ArrayList();
+
+ wm.setGlobal( "results",
+ results );
+
+ final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
+ 10 ), new Cheese( "stilton",
+ 2 ), new Cheese( "stilton",
+ 5 ), new Cheese( "brie",
+ 15 ), new Cheese( "brie",
+ 16 ), new Cheese( "provolone",
+ 8 )};
+
+ final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
+ for ( int i = 0; i < cheese.length; i++ ) {
+ cheeseHandles[i] = wm.insert( cheese[i] );
+ }
+
+ // ---------------- 1st scenario
+ int fireCount = 0;
+ wm.fireAllRules();
+ Assert.assertEquals( ++fireCount,
+ results.size() );
+ Assert.assertEquals( 3,
+ ((Collection) results.get( fireCount - 1 )).size() );
+ Assert.assertEquals( ArrayList.class.getName(),
+ results.get( fireCount - 1 ).getClass().getName() );
+
+ // ---------------- 2nd scenario
+ final int index = 1;
+ cheese[index].setType( "brie" );
+ wm.update( cheeseHandles[index],
+ cheese[index] );
+ wm.fireAllRules();
+
+ Assert.assertEquals( ++fireCount,
+ results.size() );
+ Assert.assertEquals( 2,
+ ((Collection) results.get( fireCount - 1 )).size() );
+ Assert.assertEquals( ArrayList.class.getName(),
+ results.get( fireCount - 1 ).getClass().getName() );
+
+ // ---------------- 3rd scenario
+ wm.retract( cheeseHandles[2] );
+ wm.fireAllRules();
+
+ Assert.assertEquals( ++fireCount,
+ results.size() );
+ Assert.assertEquals( 1,
+ ((Collection) results.get( fireCount - 1 )).size() );
+ Assert.assertEquals( ArrayList.class.getName(),
+ results.get( fireCount - 1 ).getClass().getName() );
+
+ }
+
private RuleBase loadRuleBase(final Reader reader) throws IOException,
DroolsParserException,
Exception {
Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CollectAlphaRestriction.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CollectAlphaRestriction.drl (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CollectAlphaRestriction.drl 2007-07-15 15:33:28 UTC (rev 13536)
@@ -0,0 +1,12 @@
+package org.drools;
+
+import java.util.ArrayList;
+
+global java.util.List results;
+
+rule "Collect Alpha Restriction" salience 70
+ when
+ $cheeseList : ArrayList(size > 0) from collect( Cheese( type == "stilton" ) );
+ then
+ results.add($cheeseList);
+end
Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CollectAlphaRestriction.drl
___________________________________________________________________
Name: svn:executable
+ *
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2007-07-15 14:02:38 UTC (rev 13535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2007-07-15 15:33:28 UTC (rev 13536)
@@ -234,7 +234,8 @@
for ( int i = 0; i < tuples.length; i++ ) {
ReteTuple tuple = (ReteTuple) tuples[i];
if ( this.constraints.isAllowedCachedRight( tuple ) ) {
- this.modifyTuple( tuple,
+ this.modifyTuple( true,
+ tuple,
handle,
context,
workingMemory );
@@ -266,7 +267,8 @@
ReteTuple tuple = (ReteTuple) tuples[i];
if ( this.constraints.isAllowedCachedRight( tuple ) ) {
- this.modifyTuple( tuple,
+ this.modifyTuple( false,
+ tuple,
handle,
context,
workingMemory );
@@ -283,7 +285,8 @@
* @param context
* @param workingMemory
*/
- public void modifyTuple(final ReteTuple leftTuple,
+ public void modifyTuple(final boolean isAssert,
+ final ReteTuple leftTuple,
InternalFactHandle handle,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
@@ -311,7 +314,11 @@
} else if ( context.getType() == PropagationContext.RETRACTION ) {
((Collection) result.handle.getObject()).remove( handle.getObject() );
} else if ( context.getType() == PropagationContext.MODIFICATION ) {
- // nothing to do
+ if( isAssert ) {
+ ((Collection) result.handle.getObject()).add( handle.getObject() );
+ } else {
+ ((Collection) result.handle.getObject()).remove( handle.getObject() );
+ }
}
// First alpha node filters
More information about the jboss-svn-commits
mailing list