|
From: <jbo...@li...> - 2006-06-30 01:07:05
|
Author: mar...@jb...
Date: 2006-06-29 21:06:59 -0400 (Thu, 29 Jun 2006)
New Revision: 4880
Added:
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooWorkingMemoryTest.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
Log:
JBRULES-356 When Asserting, Retracting, and Reasserting the same object with the same hashcode, a NullPointerException occurs
-Code was adding handle to the EqualityKey twice
-Added unit test to core
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java 2006-06-29 22:51:30 UTC (rev 4879)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java 2006-06-30 01:06:59 UTC (rev 4880)
@@ -122,8 +122,10 @@
key = new EqualityKey( handle,
status );
this.tms.put( key );
+ } else {
+ key.addFactHandle( handle );
}
- key.addFactHandle( handle );
+
handle.setEqualityKey( key );
this.handleFactory.increaseFactHandleRecency( handle );
Added: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooWorkingMemoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooWorkingMemoryTest.java 2006-06-29 22:51:30 UTC (rev 4879)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooWorkingMemoryTest.java 2006-06-30 01:06:59 UTC (rev 4880)
@@ -0,0 +1,51 @@
+package org.drools.reteoo;
+
+import junit.framework.TestCase;
+
+import org.drools.FactHandle;
+import org.drools.common.EqualityKey;
+import org.drools.common.TruthMaintenanceSystem;
+
+public class ReteooWorkingMemoryTest extends TestCase {
+ /*
+ * @see JBRULES-356
+ */
+ public void testBasicWorkingMemoryActions() {
+ ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) new ReteooRuleBase().newWorkingMemory();
+ TruthMaintenanceSystem tms = workingMemory.getTruthMaintenanceSystem();
+ String string = "test";
+ FactHandle fd = workingMemory.assertObject(string);
+
+ assertEquals(1,
+ tms.getAssertMap().size() );
+ EqualityKey key = tms.get( string );
+ assertSame( fd, key.getFactHandle() );
+ assertNull( key.getOtherFactHandle() );
+
+ workingMemory.modifyObject(fd, string);
+
+ assertEquals(1,
+ tms.getAssertMap().size() );
+ key = tms.get( string );
+ assertSame( fd, key.getFactHandle() );
+ assertNull( key.getOtherFactHandle() );
+
+ workingMemory.retractObject(fd);
+
+ assertEquals(0,
+ tms.getAssertMap().size() );
+ key = tms.get( string );
+ assertNull( key );
+
+ fd = workingMemory.assertObject(string);
+
+ assertEquals(1,
+ tms.getAssertMap().size() );
+
+ assertEquals(1,
+ tms.getAssertMap().size() );
+ key = tms.get( string );
+ assertSame( fd, key.getFactHandle() );
+ assertNull( key.getOtherFactHandle() );
+ }
+}
|