[jboss-svn-commits] JBL Code SVN: r8999 - in labs/jbossrules/branches/3.0.x: drools-compiler/src/test/java/org/drools/integrationtests and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Jan 23 18:58:47 EST 2007
Author: tirelli
Date: 2007-01-23 18:58:46 -0500 (Tue, 23 Jan 2007)
New Revision: 8999
Added:
labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactA.java
labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactB.java
labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactC.java
labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_DynamicRules.drl
labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_DynamicRules2.drl
Modified:
labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/Rete.java
labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java
Log:
JBRULES-612:
* Fixed problem with identity removal constraint
* Reseting object type cache when a new node type is added to the network
* Fixing problem when updating more than one working memories attached to the same rulebase
* Integration tests added
Added: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactA.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactA.java (rev 0)
+++ labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactA.java 2007-01-23 23:58:46 UTC (rev 8999)
@@ -0,0 +1,31 @@
+package org.drools;
+
+public class FactA {
+ String field1;
+ Integer field2;
+ Float field3;
+ public FactA(String f1, Integer f2, Float f3) {
+ field1 = f1;
+ field2 = f2;
+ field3 = f3;
+ }
+ public String getField1() {
+ return field1;
+ }
+ public void setField1(String s) {
+ field1 = s;
+ }
+ public Integer getField2() {
+ return field2;
+ }
+ public void setField2(Integer i) {
+ field2 = i;
+ }
+ public Float getField3() {
+ return field3;
+ }
+ public void setField3(Float f) {
+ field3 = f;
+ }
+
+}
Property changes on: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactA.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ id author date revision
Name: svn:eol-style
+ native
Added: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactB.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactB.java (rev 0)
+++ labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactB.java 2007-01-23 23:58:46 UTC (rev 8999)
@@ -0,0 +1,31 @@
+package org.drools;
+
+public class FactB {
+ String f1;
+ Integer f2;
+ Float f3;
+ public FactB(String a, Integer b, Float c) {
+ f1 = a;
+ f2 = b;
+ f3 = c;
+ }
+ public String getF1() {
+ return f1;
+ }
+ public void setF1(String s) {
+ f1 = s;
+ }
+ public Integer getF2() {
+ return f2;
+ }
+ public void setF2(Integer i) {
+ f2 = i;
+ }
+ public Float getF3() {
+ return f3;
+ }
+ public void setF3(Float f) {
+ f3 = f;
+ }
+
+}
Property changes on: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactB.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ id author date revision
Name: svn:eol-style
+ native
Added: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactC.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactC.java (rev 0)
+++ labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactC.java 2007-01-23 23:58:46 UTC (rev 8999)
@@ -0,0 +1,34 @@
+package org.drools;
+
+public class FactC {
+ String f1;
+ Integer f2;
+ Float f3;
+ public FactC(String a, Integer b, Float c) {
+ f1 = a;
+ f2 = b;
+ f3 = c;
+ }
+ public FactC() {
+
+ }
+ public String getF1() {
+ return f1;
+ }
+ public void setF1(String s) {
+ f1 = s;
+ }
+ public Integer getF2() {
+ return f2;
+ }
+ public void setF2(Integer i) {
+ f2 = i;
+ }
+ public Float getF3() {
+ return f3;
+ }
+ public void setF3(Float f) {
+ f3 = f;
+ }
+
+}
Property changes on: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/FactC.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ id author date revision
Name: svn:eol-style
+ native
Modified: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2007-01-23 22:33:18 UTC (rev 8998)
+++ labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2007-01-23 23:58:46 UTC (rev 8999)
@@ -52,6 +52,8 @@
import org.drools.State;
import org.drools.TestParam;
import org.drools.WorkingMemory;
+import org.drools.FactA;
+import org.drools.FactB;
import org.drools.compiler.DrlParser;
import org.drools.compiler.DroolsError;
import org.drools.compiler.DroolsParserException;
@@ -3082,5 +3084,42 @@
}
+ public void testDynamicRules() throws Exception {
+ final RuleBase ruleBase = getRuleBase();
+ final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+ Cheese a = new Cheese( "stilton", 10);
+ Cheese b = new Cheese( "stilton", 15);
+ Cheese c = new Cheese( "stilton", 20);
+ workingMemory.assertObject(a);
+ workingMemory.assertObject(b);
+ workingMemory.assertObject(c);
+
+ final PackageBuilder builder = new PackageBuilder();
+ builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_DynamicRules.drl" ) ) );
+ final Package pkg = builder.getPackage();
+ ruleBase.addPackage( pkg );
+
+ workingMemory.fireAllRules();
+ }
+
+ public void testDynamicRules2() throws Exception {
+ final RuleBase ruleBase = getRuleBase();
+ final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+
+ // Assert some simple facts
+ FactA a = new FactA("hello", new Integer(1), new Float(3.14));
+ FactB b = new FactB("hello", new Integer(2), new Float(6.28));
+ workingMemory.assertObject(a);
+ workingMemory.assertObject(b);
+
+ final PackageBuilder builder = new PackageBuilder();
+ builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_DynamicRules2.drl" ) ) );
+ final Package pkg = builder.getPackage();
+ ruleBase.addPackage( pkg );
+
+ workingMemory.fireAllRules();
+ }
+
+
}
Added: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_DynamicRules.drl
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_DynamicRules.drl (rev 0)
+++ labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_DynamicRules.drl 2007-01-23 23:58:46 UTC (rev 8999)
@@ -0,0 +1,14 @@
+package org.drools;
+
+rule "Cheese"
+no-loop true
+ when
+ a: Cheese( $type : type, price == 10 );
+ b: Cheese( type == $type, price == 15 );
+ c: Cheese( type == $type );
+ then
+ c.setPrice( 30 );
+ retract(a);
+ modify(c);
+end
+
Property changes on: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_DynamicRules.drl
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:eol-style
+ native
Added: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_DynamicRules2.drl
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_DynamicRules2.drl (rev 0)
+++ labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_DynamicRules2.drl 2007-01-23 23:58:46 UTC (rev 8999)
@@ -0,0 +1,22 @@
+package org.drools;
+
+rule "setupFactC"
+no-loop true
+ when
+ a: FactA(s:field1, i:field2, f:field3)
+ not FactC(f1==s)
+ then
+ assert(s != null ? new FactC(s, i, f) :
+ new FactC());
+end
+
+rule "factBWithRetract"
+ when
+ b : FactB(s:f1, i:f2, f:f3)
+ a : FactA(field1==s)
+ c : FactC(f1==s)
+ then
+ c.setF3(f);
+ retract(b);
+ modify(c);
+end
\ No newline at end of file
Property changes on: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_DynamicRules2.drl
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:eol-style
+ native
Modified: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/Rete.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/Rete.java 2007-01-23 22:33:18 UTC (rev 8998)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/Rete.java 2007-01-23 23:58:46 UTC (rev 8999)
@@ -259,6 +259,11 @@
// propagations into the new node
public void updateNewNode(final ReteooWorkingMemory workingMemory,
final PropagationContext context) {
+ // JBRULES-612: the cache MUST be invalidated when a new
+ // node type is added to the network
+ HashMap memory = (HashMap) workingMemory.getNodeMemory( this );
+ memory.clear();
+
if ( this.lastAddedNode != null ) {
final ObjectType objType = this.lastAddedNode.getObjectType();
for ( final Iterator i = workingMemory.getFactHandleMap().entrySet().iterator(); i.hasNext(); ) {
@@ -270,7 +275,6 @@
workingMemory );
}
}
- this.lastAddedNode = null;
}
}
Modified: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java 2007-01-23 22:33:18 UTC (rev 8998)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java 2007-01-23 23:58:46 UTC (rev 8999)
@@ -405,17 +405,25 @@
if ( removeIdentities ) {
// Check if this object type exists before
// If it does we need stop instance equals cross product
+ List otherIndexes = null;
for ( final Iterator it = this.objectType.entrySet().iterator(); it.hasNext(); ) {
final Map.Entry entry = (Map.Entry) it.next();
final Class previousClass = ((ClassObjectType) entry.getKey()).getClassType();
if ( thisClass.isAssignableFrom( previousClass ) ) {
- predicateConstraints.add( new InstanceNotEqualsConstraint( ((Integer) entry.getValue()).intValue() ) );
+ otherIndexes = (List) entry.getValue();
+ for ( Iterator indexes = otherIndexes.iterator(); indexes.hasNext(); ) {
+ predicateConstraints.add( new InstanceNotEqualsConstraint( ((Integer) indexes.next()).intValue() ) );
+ }
}
}
+ if( otherIndexes == null ) {
+ otherIndexes = new ArrayList();
+ }
+ otherIndexes.add( new Integer( column.getFactIndex() ) );
// Must be added after the checking, otherwise it matches against itself
this.objectType.put( column.getObjectType(),
- new Integer( column.getFactIndex() ) );
+ otherIndexes );
}
for ( final Iterator it = constraints.iterator(); it.hasNext(); ) {
More information about the jboss-svn-commits
mailing list