[jboss-svn-commits] JBL Code SVN: r5051 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools main/java/org/drools/common main/java/org/drools/leaps main/java/org/drools/reteoo test/java/org/drools test/java/org/drools/leaps test/java/org/drools/reteoo test/java/org/drools/reteoo/beta

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jul 12 15:40:35 EDT 2006


Author: mark.proctor at jboss.com
Date: 2006-07-12 15:40:12 -0400 (Wed, 12 Jul 2006)
New Revision: 5051

Added:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/LeapsRuleBaseTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/LeapsWorkingMemoryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooRuleBaseTest.java
Removed:
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/RuleBaseImplTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleBaseImplTest.java
Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseFactory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemoryActions.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsRuleBase.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseFactoryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeSwitchTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/EvalConditionNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/HashedObjectSinkListTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectSourceTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooWorkingMemoryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaLeftMemoryTestClass.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaRightMemoryTestClass.java
Log:
JBRULES-369 generate RuleBases with a UUID id
JBRULES-370 generate counter ids for working memories

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseFactory.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseFactory.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -45,11 +45,7 @@
             case RuleBase.RETEOO :
                 return new org.drools.reteoo.ReteooRuleBase( UUIDGenerator.getInstance().generateRandomBasedUUID().toString() );
             case RuleBase.LEAPS :
-                try {
-                    return new org.drools.leaps.LeapsRuleBase( UUIDGenerator.getInstance().generateRandomBasedUUID().toString() );
-                } catch ( final PackageIntegrationException e ) {
-                    throw new IllegalStateException( "Unable to create Leaps engine. Error: " + e.getMessage() );
-                }
+                return new org.drools.leaps.LeapsRuleBase( UUIDGenerator.getInstance().generateRandomBasedUUID().toString() );
             default :
                 throw new IllegalArgumentException( "Unknown engine type: " + type );
 

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -60,8 +60,10 @@
     // ------------------------------------------------------------
     // Instance members
     // ------------------------------------------------------------
-    protected String                                id;
+    protected final String                          id;
     
+    protected int                                   workingMemoryCounter;
+    
     protected RuleBaseConfiguration                 config;
 
     protected Map                                   pkgs;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -62,7 +62,6 @@
  */
 public abstract class AbstractWorkingMemory
     implements
-    WorkingMemory,
     InternalWorkingMemoryActions,
     EventSupport,
     PropertyChangeListener {
@@ -74,6 +73,7 @@
     // ------------------------------------------------------------
     // Instance members
     // ------------------------------------------------------------
+    protected final long                      id;
 
     /** The arguments used when adding/removing a property change listener. */
     protected final Object[]                  addRemovePropertyChangeListenerArgs           = new Object[]{this};
@@ -126,8 +126,10 @@
      * @param ruleBase
      *            The backing rule-base.
      */
-    public AbstractWorkingMemory(final InternalRuleBase ruleBase,
+    public AbstractWorkingMemory(final int id,
+                                 final InternalRuleBase ruleBase,
                                  final FactHandleFactory handleFactory) {
+        this.id = id;
         this.ruleBase = ruleBase;
         this.handleFactory = handleFactory;
         this.tms = new TruthMaintenanceSystem( this );
@@ -209,6 +211,10 @@
                               value );
         }
     }
+    
+    public long getId() {
+        return this.id;
+    }
 
     /**
      * @see WorkingMemory

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -0,0 +1,7 @@
+package org.drools.common;
+
+import org.drools.WorkingMemory;
+
+public interface InternalWorkingMemory extends WorkingMemory {
+    public long getId();
+}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemoryActions.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemoryActions.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemoryActions.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -24,7 +24,7 @@
 
 public interface InternalWorkingMemoryActions
     extends
-    WorkingMemory {
+    InternalWorkingMemory {
     public void modifyObject(FactHandle handle,
                              Object object,
                              Rule rule,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsRuleBase.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsRuleBase.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -56,7 +56,7 @@
      *            The rete network.
      * @throws PackageIntegrationException
      */
-    public LeapsRuleBase() throws PackageIntegrationException {
+    public LeapsRuleBase() {
         this( null,
               null,
               new LeapsFactHandleFactory() );
@@ -69,7 +69,7 @@
      *            The rete network.
      * @throws PackageIntegrationException
      */
-    public LeapsRuleBase(final String id) throws PackageIntegrationException {
+    public LeapsRuleBase(final String id) {
         this( id,
               null,
               new LeapsFactHandleFactory() );
@@ -109,7 +109,8 @@
      * @see RuleBase
      */
     public WorkingMemory newWorkingMemory(final boolean keepReference) {
-        final LeapsWorkingMemory workingMemory = new LeapsWorkingMemory( this );
+        final LeapsWorkingMemory workingMemory = new LeapsWorkingMemory( this.workingMemoryCounter++, 
+                                                                         this );
         // add all rules added so far
         for ( final Iterator it = this.leapsRules.values().iterator(); it.hasNext(); ) {
             workingMemory.addLeapsRules( (List) it.next() );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsWorkingMemory.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsWorkingMemory.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -67,15 +67,17 @@
  * @see java.io.Serializable
  * 
  */
-class LeapsWorkingMemory extends AbstractWorkingMemory implements EventSupport,
-        PropertyChangeListener {
+class LeapsWorkingMemory extends AbstractWorkingMemory
+    implements
+    EventSupport,
+    PropertyChangeListener {
     private static final long serialVersionUID       = -2524904474925421759L;
 
     private final Map         queryResults;
 
-    private final IdentityMap leapsRulesToHandlesMap = new IdentityMap( );
+    private final IdentityMap leapsRulesToHandlesMap = new IdentityMap();
 
-    private final IdentityMap rulesActivationsMap    = new IdentityMap( );
+    private final IdentityMap rulesActivationsMap    = new IdentityMap();
 
     /**
      * Construct.
@@ -83,19 +85,24 @@
      * @param ruleBase
      *            The backing rule-base.
      */
-    public LeapsWorkingMemory(final InternalRuleBase ruleBase) {
-        super( ruleBase, ruleBase.newFactHandleFactory( ) );
-        this.queryResults = new HashMap( );
+    public LeapsWorkingMemory(final int id,
+                              final InternalRuleBase ruleBase) {
+        super( id,
+               ruleBase,
+               ruleBase.newFactHandleFactory() );
+        this.queryResults = new HashMap();
         this.agenda = new LeapsAgenda( this );
     }
 
-    public void doAssertObject( final InternalFactHandle factHandle,
-                                final Object object,
-                                final PropagationContext propagationContext )
-            throws FactException {
-        
-        this.pushTokenOnStack( factHandle, new Token( this, factHandle, propagationContext ) );
+    public void doAssertObject(final InternalFactHandle factHandle,
+                               final Object object,
+                               final PropagationContext propagationContext) throws FactException {
 
+        this.pushTokenOnStack( factHandle,
+                               new Token( this,
+                                          factHandle,
+                                          propagationContext ) );
+
         // determine what classes it belongs to put it into the "table" on
         // class name key
         final Class objectClass = object.getClass();
@@ -106,61 +113,58 @@
             // inspect all tuples for exists and not conditions and activate
             // /
             // deactivate agenda items
-            for (final Iterator tuples = factTable.getTuplesIterator( ); tuples.hasNext( );) {
-                final LeapsTuple tuple = (LeapsTuple) tuples.next( );
-                boolean tupleWasReadyForActivation = tuple.isReadyForActivation( );
-                if (!tuple.isActivationNull( )) {
+            for ( final Iterator tuples = factTable.getTuplesIterator(); tuples.hasNext(); ) {
+                final LeapsTuple tuple = (LeapsTuple) tuples.next();
+                boolean tupleWasReadyForActivation = tuple.isReadyForActivation();
+                if ( !tuple.isActivationNull() ) {
                     // check not constraints only on activated tuples to see
                     // if
                     // we need to deactivate
-                    final ColumnConstraints[] not = tuple.getLeapsRule( )
-                                                         .getNotColumnConstraints( );
-                    for (int i = 0, length = not.length; i < length; i++) {
+                    final ColumnConstraints[] not = tuple.getLeapsRule().getNotColumnConstraints();
+                    for ( int i = 0, length = not.length; i < length; i++ ) {
                         final ColumnConstraints constraint = not[i];
-                        if (!tuple.isBlockingNotFactHandle( i )
-                                && constraint.getClassType( )
-                                             .isAssignableFrom( objectClass )
-                                && constraint.isAllowed( factHandle, tuple, this )) {
-                            tuple.setBlockingNotFactHandle( (LeapsFactHandle) factHandle, i );
-                            ( (LeapsFactHandle) factHandle ).addNotTuple( tuple, i );
+                        if ( !tuple.isBlockingNotFactHandle( i ) && constraint.getClassType().isAssignableFrom( objectClass ) && constraint.isAllowed( factHandle,
+                                                                                                                                                       tuple,
+                                                                                                                                                       this ) ) {
+                            tuple.setBlockingNotFactHandle( (LeapsFactHandle) factHandle,
+                                                            i );
+                            ((LeapsFactHandle) factHandle).addNotTuple( tuple,
+                                                                        i );
                         }
                     }
                     // check and see if we need de-activate
-                    if (!tuple.isReadyForActivation( )) {
-                        if (tuple.getLeapsRule( ).getRule( ) instanceof Query) {
+                    if ( !tuple.isReadyForActivation() ) {
+                        if ( tuple.getLeapsRule().getRule() instanceof Query ) {
                             // put query results to the working memory
                             // location
-                            removeFromQueryResults( tuple.getLeapsRule( )
-                                                         .getRule( )
-                                                         .getName( ), tuple );
-                        }
-                        else {
+                            removeFromQueryResults( tuple.getLeapsRule().getRule().getName(),
+                                                    tuple );
+                        } else {
                             // time to pull from agenda
                             invalidateActivation( tuple );
                         }
                     }
-                }
-                else {
+                } else {
                     // check exists constraints and activate constraints
-                    final ColumnConstraints[] exists = tuple.getLeapsRule( )
-                                                            .getExistsColumnConstraints( );
-                    for (int i = 0, length = exists.length; i < length; i++) {
+                    final ColumnConstraints[] exists = tuple.getLeapsRule().getExistsColumnConstraints();
+                    for ( int i = 0, length = exists.length; i < length; i++ ) {
                         final ColumnConstraints constraint = exists[i];
-                        if (!tuple.isExistsFactHandle( i )
-                                && constraint.getClassType( )
-                                             .isAssignableFrom( objectClass )
-                                && constraint.isAllowed( factHandle, tuple, this )) {
-                            tuple.setExistsFactHandle( (LeapsFactHandle) factHandle, i );
-                            ( (LeapsFactHandle) factHandle ).addExistsTuple( tuple, i );
+                        if ( !tuple.isExistsFactHandle( i ) && constraint.getClassType().isAssignableFrom( objectClass ) && constraint.isAllowed( factHandle,
+                                                                                                                                                  tuple,
+                                                                                                                                                  this ) ) {
+                            tuple.setExistsFactHandle( (LeapsFactHandle) factHandle,
+                                                       i );
+                            ((LeapsFactHandle) factHandle).addExistsTuple( tuple,
+                                                                           i );
                         }
                     }
                     // check and see if we need activate
                     // activate only if tuple was not ready for it before
-                    if (!tupleWasReadyForActivation && tuple.isReadyForActivation( )) {
+                    if ( !tupleWasReadyForActivation && tuple.isReadyForActivation() ) {
                         // ready to activate
-                        tuple.setContext( new PropagationContextImpl( nextPropagationIdCounter( ),
+                        tuple.setContext( new PropagationContextImpl( nextPropagationIdCounter(),
                                                                       PropagationContext.ASSERTION,
-                                                                      tuple.getLeapsRule( ).getRule( ),
+                                                                      tuple.getLeapsRule().getRule(),
                                                                       null ) );
 
                         this.assertTuple( tuple );
@@ -177,51 +181,51 @@
      * 
      * @see WorkingMemory
      */
-    public void doRetract( final InternalFactHandle factHandle,
-                           final PropagationContext propagationContext ) {
+    public void doRetract(final InternalFactHandle factHandle,
+                          final PropagationContext propagationContext) {
 
         /*
          * leaps specific actions
          */
         // remove fact from all relevant fact tables container
-        for (final Iterator it = this.getFactTablesList( factHandle.getObject( ).getClass( ) )
-                                     .iterator( ); it.hasNext( );) {
-            ( (FactTable) it.next( ) ).remove( factHandle );
+        for ( final Iterator it = this.getFactTablesList( factHandle.getObject().getClass() ).iterator(); it.hasNext(); ) {
+            ((FactTable) it.next()).remove( factHandle );
         }
 
         // 0. remove activated tuples
-        final Iterator tuples = ( (LeapsFactHandle) factHandle ).getActivatedTuples( );
-        for (; tuples != null && tuples.hasNext( );) {
-            final LeapsTuple tuple = (LeapsTuple) tuples.next( );
-            if (tuple.getLeapsRule( ).getRule( ) instanceof Query) {
+        final Iterator tuples = ((LeapsFactHandle) factHandle).getActivatedTuples();
+        for ( ; tuples != null && tuples.hasNext(); ) {
+            final LeapsTuple tuple = (LeapsTuple) tuples.next();
+            if ( tuple.getLeapsRule().getRule() instanceof Query ) {
                 // put query results to the working memory location
-                removeFromQueryResults( tuple.getLeapsRule( ).getRule( ).getName( ), tuple );
-            }
-            else {
+                removeFromQueryResults( tuple.getLeapsRule().getRule().getName(),
+                                        tuple );
+            } else {
                 // time to pull from agenda
                 invalidateActivation( tuple );
             }
         }
 
         // 1. remove fact for nots and exists tuples
-        final IdentityMap tuplesNotReadyForActivation = new IdentityMap( );
+        final IdentityMap tuplesNotReadyForActivation = new IdentityMap();
         FactHandleTupleAssembly assembly;
         LeapsTuple tuple;
         Iterator it;
-        it = ( (LeapsFactHandle) factHandle ).getNotTupleAssemblies( );
-        if (it != null) {
-            for (; it.hasNext( );) {
-                assembly = (FactHandleTupleAssembly) it.next( );
-                tuple = assembly.getTuple( );
-                if (!tuple.isReadyForActivation( )) {
-                    tuplesNotReadyForActivation.put( tuple, tuple );
+        it = ((LeapsFactHandle) factHandle).getNotTupleAssemblies();
+        if ( it != null ) {
+            for ( ; it.hasNext(); ) {
+                assembly = (FactHandleTupleAssembly) it.next();
+                tuple = assembly.getTuple();
+                if ( !tuple.isReadyForActivation() ) {
+                    tuplesNotReadyForActivation.put( tuple,
+                                                     tuple );
                 }
-                tuple.removeBlockingNotFactHandle( assembly.getIndex( ) );
+                tuple.removeBlockingNotFactHandle( assembly.getIndex() );
 
                 TokenEvaluator.evaluateNotCondition( (LeapsFactHandle) factHandle,
-//                                                                          TokenEvaluator.evaluateNotCondition( new LeapsFactHandle( factHandle.getRecency( ) + 1,
-//                                                                                                                                    new Object( ) ),
-                                                     assembly.getIndex( ),
+                                                     //                                                                          TokenEvaluator.evaluateNotCondition( new LeapsFactHandle( factHandle.getRecency( ) + 1,
+                                                     //                                                                                                                                    new Object( ) ),
+                                                     assembly.getIndex(),
                                                      tuple,
                                                      this );
             }
@@ -235,11 +239,11 @@
                     tuplesNotReadyForActivation.put( tuple,
                                                      tuple );
                 }
-                tuple.removeExistsFactHandle( assembly.getIndex( ) );
-                TokenEvaluator.evaluateExistsCondition( (LeapsFactHandle)factHandle,
-//                                                                             TokenEvaluator.evaluateExistsCondition( new LeapsFactHandle( factHandle.getRecency( ) + 1,
-//                                                                                                                                          null ),
-                                                        assembly.getIndex( ),
+                tuple.removeExistsFactHandle( assembly.getIndex() );
+                TokenEvaluator.evaluateExistsCondition( (LeapsFactHandle) factHandle,
+                                                        //                                                                             TokenEvaluator.evaluateExistsCondition( new LeapsFactHandle( factHandle.getRecency( ) + 1,
+                                                        //                                                                                                                                          null ),
+                                                        assembly.getIndex(),
                                                         tuple,
                                                         this );
             }
@@ -256,26 +260,22 @@
             chain.addIterator( it );
         }
         for ( ; chain.hasNext(); ) {
-            tuple = ( (FactHandleTupleAssembly) chain.next( ) ).getTuple( );
+            tuple = ((FactHandleTupleAssembly) chain.next()).getTuple();
             // can assert only tuples that were not eligible for activation
             // before retraction
-            if (tuple.isReadyForActivation( ) && tuple.isActivationNull( )
-                    && tuplesNotReadyForActivation.containsKey( tuple )) {
+            if ( tuple.isReadyForActivation() && tuple.isActivationNull() && tuplesNotReadyForActivation.containsKey( tuple ) ) {
                 // ready to activate
-                tuple.setContext( new PropagationContextImpl( nextPropagationIdCounter( ),
+                tuple.setContext( new PropagationContextImpl( nextPropagationIdCounter(),
                                                               PropagationContext.ASSERTION,
-                                                              tuple.getLeapsRule( )
-                                                                   .getRule( ),
+                                                              tuple.getLeapsRule().getRule(),
                                                               null ) );
                 this.assertTuple( tuple );
-            }
-            else {
-                if (tuple.getLeapsRule( ).getRule( ) instanceof Query) {
+            } else {
+                if ( tuple.getLeapsRule().getRule() instanceof Query ) {
                     // put query results to the working memory location
-                    removeFromQueryResults( tuple.getLeapsRule( ).getRule( ).getName( ),
+                    removeFromQueryResults( tuple.getLeapsRule().getRule().getName(),
                                             tuple );
-                }
-                else {
+                } else {
                     // time to pull from agenda
                     invalidateActivation( tuple );
                 }
@@ -292,26 +292,26 @@
      * 
      * @param tuple
      */
-    private final void invalidateActivation( final LeapsTuple tuple ) {
-        final Activation activation = tuple.getActivation( );
-        if (!tuple.isReadyForActivation( ) && !tuple.isActivationNull( )) {
+    private final void invalidateActivation(final LeapsTuple tuple) {
+        final Activation activation = tuple.getActivation();
+        if ( !tuple.isReadyForActivation() && !tuple.isActivationNull() ) {
             // invalidate agenda agendaItem
-            if (activation.isActivated( )) {
-                activation.remove( );
-                getAgendaEventSupport( ).fireActivationCancelled( activation );
+            if ( activation.isActivated() ) {
+                activation.remove();
+                getAgendaEventSupport().fireActivationCancelled( activation );
             }
             //
             tuple.setActivation( null );
         }
-        if (activation != null) {
+        if ( activation != null ) {
             // remove logical dependency
             this.tms.removeLogicalDependencies( activation,
-                                                tuple.getContext( ),
-                                                tuple.getLeapsRule( ).getRule( ) );
+                                                tuple.getContext(),
+                                                tuple.getLeapsRule().getRule() );
 
             // remove from rule / activaitons map
-            FastMap activations = (FastMap) this.rulesActivationsMap.get( activation.getRule( ) );
-            if (activations != null) {
+            FastMap activations = (FastMap) this.rulesActivationsMap.get( activation.getRule() );
+            if ( activations != null ) {
                 activations.remove( activation );
             }
         }
@@ -322,45 +322,45 @@
      * 
      * @see WorkingMemory
      */
-    public void modifyObject( final FactHandle factHandle,
-                              final Object object,
-                              final Rule rule,
-                              final Activation activation ) throws FactException {
-        this.getLock( ).lock( );
+    public void modifyObject(final FactHandle factHandle,
+                             final Object object,
+                             final Rule rule,
+                             final Activation activation) throws FactException {
+        this.getLock().lock();
         try {
             final PropagationContext propagationContext = new PropagationContextImpl( this.propagationIdCounter++,
                                                                                       PropagationContext.MODIFICATION,
                                                                                       rule,
                                                                                       activation );
 
-            final int status = ( (InternalFactHandle) factHandle ).getEqualityKey( )
-                                                                  .getStatus( );
+            final int status = ((InternalFactHandle) factHandle).getEqualityKey().getStatus();
 
             final Object originalObject = this.assertMap.remove( factHandle );
-            if (originalObject == null) {
+            if ( originalObject == null ) {
                 throw new NoSuchFactObjectException( factHandle );
             }
             // 
             // do subset of retractObject( )
             //
             final InternalFactHandle handle = (InternalFactHandle) factHandle;
-            if (handle.getId( ) == -1) {
+            if ( handle.getId() == -1 ) {
                 // can't retract an already retracted handle
                 return;
             }
             removePropertyChangeListener( handle );
 
-            doRetract( handle, propagationContext );
+            doRetract( handle,
+                       propagationContext );
 
             // Update the equality key, which maintains a list of stated
             // FactHandles
-            final EqualityKey key = handle.getEqualityKey( );
+            final EqualityKey key = handle.getEqualityKey();
 
             key.removeFactHandle( handle );
             handle.setEqualityKey( null );
 
             // If the equality key is now empty, then remove it
-            if (key.isEmpty( )) {
+            if ( key.isEmpty() ) {
                 this.tms.remove( key );
             }
             // produces NPE otherwise
@@ -370,21 +370,23 @@
             // and now assert
             //
             /* check to see if this is a logically asserted object */
-            this.assertObject( object, false, ( status == EqualityKey.STATED ) ? false
-                    : true, rule, activation );
+            this.assertObject( object,
+                               false,
+                               (status == EqualityKey.STATED) ? false : true,
+                               rule,
+                               activation );
 
             this.workingMemoryEventSupport.fireObjectModified( propagationContext,
                                                                handle,
-                                                               handle.getObject( ),
+                                                               handle.getObject(),
                                                                object );
 
-            if (!this.factQueue.isEmpty( )) {
-                propagateQueuedActions( );
+            if ( !this.factQueue.isEmpty() ) {
+                propagateQueuedActions();
             }
+        } finally {
+            this.getLock().unlock();
         }
-        finally {
-            this.getLock( ).unlock( );
-        }
     }
 
     /**
@@ -395,7 +397,7 @@
     /**
      * algorithm stack.
      */
-    private final TokenStack mainStack       = new TokenStack( );
+    private final TokenStack mainStack       = new TokenStack();
 
     /**
      * generates or just return List of internal factTables that correspond a
@@ -403,20 +405,20 @@
      * 
      * @return
      */
-    protected final List getFactTablesList( final Class c ) {
-        final ArrayList list = new ArrayList( );
+    protected final List getFactTablesList(final Class c) {
+        final ArrayList list = new ArrayList();
         // interfaces
-        final Class[] interfaces = c.getInterfaces( );
-        for (int i = 0; i < interfaces.length; i++) {
+        final Class[] interfaces = c.getInterfaces();
+        for ( int i = 0; i < interfaces.length; i++ ) {
             list.add( this.getFactTable( interfaces[i] ) );
         }
         // classes
         Class bufClass = c;
-        while (bufClass != null) {
+        while ( bufClass != null ) {
             //
             list.add( this.getFactTable( bufClass ) );
             // and get the next class on the list
-            bufClass = bufClass.getSuperclass( );
+            bufClass = bufClass.getSuperclass();
         }
         return list;
     }
@@ -437,8 +439,8 @@
      * 
      * @param fact handle
      */
-    protected final void removeTokenFromStack( final LeapsFactHandle factHandle ) {
-        this.mainStack.remove( factHandle.getId( ) );
+    protected final void removeTokenFromStack(final LeapsFactHandle factHandle) {
+        this.mainStack.remove( factHandle.getId() );
     }
 
     /**
@@ -447,7 +449,7 @@
      * @param fact handle
      */
     protected final Token peekTokenOnTop() {
-        return (Token) this.mainStack.peek( );
+        return (Token) this.mainStack.peek();
     }
 
     /**
@@ -457,24 +459,24 @@
      *            of objects
      * @return fact table of requested class type
      */
-    protected FactTable getFactTable( final Class c ) {
+    protected FactTable getFactTable(final Class c) {
         FactTable table;
-        if (this.factTables.containsKey( c )) {
+        if ( this.factTables.containsKey( c ) ) {
             table = (FactTable) this.factTables.get( c );
-        }
-        else {
-            table = new FactTable( DefaultConflictResolver.getInstance( ) );
-            this.factTables.put( c, table );
+        } else {
+            table = new FactTable( DefaultConflictResolver.getInstance() );
+            this.factTables.put( c,
+                                 table );
             // review existing rules and assign to the fact table if needed
-            for (final Iterator iter = this.leapsRulesToHandlesMap.keySet( ).iterator( ); iter.hasNext( );) {
-                final LeapsRule leapsRule = (LeapsRule) iter.next( );
-                if (leapsRule.getNumberOfColumns( ) > 0) {
+            for ( final Iterator iter = this.leapsRulesToHandlesMap.keySet().iterator(); iter.hasNext(); ) {
+                final LeapsRule leapsRule = (LeapsRule) iter.next();
+                if ( leapsRule.getNumberOfColumns() > 0 ) {
                     final List rulesHandles = (List) this.leapsRulesToHandlesMap.get( leapsRule );
-                    for (final Iterator handles = rulesHandles.iterator( ); handles.hasNext( );) {
-                        final LeapsRuleHandle handle = (LeapsRuleHandle) handles.next( );
-                        if (leapsRule.getColumnClassObjectTypeAtPosition( handle.getDominantPosition( ) )
-                                     .isAssignableFrom( c )) {
-                            table.addRule( this, handle );
+                    for ( final Iterator handles = rulesHandles.iterator(); handles.hasNext(); ) {
+                        final LeapsRuleHandle handle = (LeapsRuleHandle) handles.next();
+                        if ( leapsRule.getColumnClassObjectTypeAtPosition( handle.getDominantPosition() ).isAssignableFrom( c ) ) {
+                            table.addRule( this,
+                                           handle );
                         }
                     }
                 }
@@ -500,22 +502,23 @@
                 // some times rules do not have "normal" constraints and only
                 // not and exists
                 if ( rule.getNumberOfColumns() > 0 ) {
-                    ruleHandlesList = new ArrayList( );
-                    for (int i = 0; i < rule.getNumberOfColumns( ); i++) {
-                        ruleHandle = new LeapsRuleHandle( ( (LeapsFactHandleFactory) this.handleFactory ).getNextId( ),
+                    ruleHandlesList = new ArrayList();
+                    for ( int i = 0; i < rule.getNumberOfColumns(); i++ ) {
+                        ruleHandle = new LeapsRuleHandle( ((LeapsFactHandleFactory) this.handleFactory).getNextId(),
                                                           rule,
                                                           i );
                         // 
-                        this.getFactTable( rule.getColumnClassObjectTypeAtPosition( i ) )
-                            .addRule( this, ruleHandle );
+                        this.getFactTable( rule.getColumnClassObjectTypeAtPosition( i ) ).addRule( this,
+                                                                                                   ruleHandle );
                         //
                         ruleHandlesList.add( ruleHandle );
                     }
-                    this.leapsRulesToHandlesMap.put( rule, ruleHandlesList );
+                    this.leapsRulesToHandlesMap.put( rule,
+                                                     ruleHandlesList );
                 } else {
                     // to pick up rules that do not require columns, only not
                     // and exists
-                    final PropagationContextImpl context = new PropagationContextImpl( nextPropagationIdCounter( ),
+                    final PropagationContextImpl context = new PropagationContextImpl( nextPropagationIdCounter(),
                                                                                        PropagationContext.ASSERTION,
                                                                                        null,
                                                                                        null );
@@ -547,7 +550,8 @@
                     for ( int i = 0; i < ruleHandlesList.size(); i++ ) {
                         ruleHandle = (LeapsRuleHandle) ruleHandlesList.get( i );
                         // 
-                        this.getFactTable( leapsRule.getColumnClassObjectTypeAtPosition( i ) ).removeRule( this, ruleHandle );
+                        this.getFactTable( leapsRule.getColumnClassObjectTypeAtPosition( i ) ).removeRule( this,
+                                                                                                           ruleHandle );
                     }
                 }
                 //
@@ -555,7 +559,7 @@
             final Rule rule = ((LeapsRule) rules.get( 0 )).getRule();
             final FastMap activations = (FastMap) this.rulesActivationsMap.remove( rule );
             if ( activations != null ) {
-                for ( final Iterator activationsIt = activations.keySet( ).iterator(); activationsIt.hasNext(); ) {
+                for ( final Iterator activationsIt = activations.keySet().iterator(); activationsIt.hasNext(); ) {
                     final Activation activation = (Activation) activationsIt.next();
                     ((LeapsTuple) activation.getTuple()).setActivation( null );
                     this.tms.removeLogicalDependencies( activation,
@@ -638,13 +642,12 @@
                     }
                 }
                 // mark when method was called last time
-                this.idLastFireAllAt = ( (LeapsFactHandleFactory) this.handleFactory ).getNextId( );
+                this.idLastFireAllAt = ((LeapsFactHandleFactory) this.handleFactory).getNextId();
                 // set all factTables to be reseeded
-                for (final Iterator it = this.factTables.values( ).iterator( ); it.hasNext( );) {
-                    ( (FactTable) it.next( ) ).setReseededStack( true );
+                for ( final Iterator it = this.factTables.values().iterator(); it.hasNext(); ) {
+                    ((FactTable) it.next()).setReseededStack( true );
                 }
-            }
-            finally {
+            } finally {
                 this.firing = false;
             }
         }
@@ -681,20 +684,20 @@
      * @throws AssertionException
      *             If an error occurs while asserting.
      */
-    public final void assertTuple( final LeapsTuple tuple ) {
-        final PropagationContext context = tuple.getContext( );
-        final Rule rule = tuple.getLeapsRule( ).getRule( );
+    public final void assertTuple(final LeapsTuple tuple) {
+        final PropagationContext context = tuple.getContext();
+        final Rule rule = tuple.getLeapsRule().getRule();
         // if the current Rule is no-loop and the origin rule is the same then
         // return
-        if (rule.getNoLoop( ) && rule.equals( context.getRuleOrigin( ) )) {
+        if ( rule.getNoLoop() && rule.equals( context.getRuleOrigin() ) ) {
             return;
         }
         //
-        final Duration dur = rule.getDuration( );
+        final Duration dur = rule.getDuration();
 
         Activation agendaItem;
-        if (dur != null && dur.getDuration( tuple ) > 0) {
-            agendaItem = new ScheduledAgendaItem( context.getPropagationNumber( ),
+        if ( dur != null && dur.getDuration( tuple ) > 0 ) {
+            agendaItem = new ScheduledAgendaItem( context.getPropagationNumber(),
                                                   tuple,
                                                   this.agenda,
                                                   context,
@@ -749,20 +752,22 @@
         for ( int i = 0; i < factHandles.length; i++ ) {
             factHandles[i].addActivatedTuple( tuple );
         }
-        
+
         // rules remove support
         FastMap activations = (FastMap) this.rulesActivationsMap.get( rule );
-        if (activations == null) {
-            activations = new FastMap( );
-            this.rulesActivationsMap.put( rule, activations );
+        if ( activations == null ) {
+            activations = new FastMap();
+            this.rulesActivationsMap.put( rule,
+                                          activations );
         }
-        activations.put( agendaItem, agendaItem );
+        activations.put( agendaItem,
+                         agendaItem );
     }
 
     List getActivations() {
-        List ret = new ArrayList( );
-        for (final Iterator it = this.rulesActivationsMap.values( ).iterator( ); it.hasNext( );) {
-            ret.addAll( ( (FastMap) it.next( ) ).values( ) );
+        List ret = new ArrayList();
+        for ( final Iterator it = this.rulesActivationsMap.values().iterator(); it.hasNext(); ) {
+            ret.addAll( ((FastMap) it.next()).values() );
         }
 
         return ret;
@@ -772,38 +777,42 @@
         return ++this.propagationIdCounter;
     }
 
-    public QueryResults getQueryResults( final String queryName ) {
+    public QueryResults getQueryResults(final String queryName) {
         final IdentityMap map = (IdentityMap) this.queryResults.get( queryName );
-        if (map == null) {
+        if ( map == null ) {
             return null;
         }
 
-        final LinkedList list = new LinkedList( );
-        for (final Iterator it = map.keySet( ).iterator( ); it.hasNext( );) {
-            list.add( it.next( ) );
+        final LinkedList list = new LinkedList();
+        for ( final Iterator it = map.keySet().iterator(); it.hasNext(); ) {
+            list.add( it.next() );
         }
-        if (!list.isEmpty( )) {
-            final Query queryRule = (Query) ( (LeapsTuple) list.get( 0 ) ).getLeapsRule( )
-                                                                          .getRule( );
-            return new LeapsQueryResults( list, queryRule, this );
-        }
-        else {
+        if ( !list.isEmpty() ) {
+            final Query queryRule = (Query) ((LeapsTuple) list.get( 0 )).getLeapsRule().getRule();
+            return new LeapsQueryResults( list,
+                                          queryRule,
+                                          this );
+        } else {
             return null;
         }
     }
 
-    void addToQueryResults( final String query, final Tuple tuple ) {
+    void addToQueryResults(final String query,
+                           final Tuple tuple) {
         IdentityMap map = (IdentityMap) this.queryResults.get( query );
-        if (map == null) {
-            map = new IdentityMap( );
-            this.queryResults.put( query, map );
+        if ( map == null ) {
+            map = new IdentityMap();
+            this.queryResults.put( query,
+                                   map );
         }
-        map.put( tuple, tuple );
+        map.put( tuple,
+                 tuple );
     }
 
-    void removeFromQueryResults( final String query, final Tuple tuple ) {
+    void removeFromQueryResults(final String query,
+                                final Tuple tuple) {
         final IdentityMap map = (IdentityMap) this.queryResults.get( query );
-        if (map != null) {
+        if ( map != null ) {
             map.remove( tuple );
         }
     }
@@ -811,31 +820,34 @@
     /**
      * to store facts to cursor over it
      */
-    private final Map factTables = new FactTables(); 
-    
-    class FactTables implements Map, Serializable {
-        private LinkedList tables = new LinkedList( );
+    private final Map factTables = new FactTables();
 
-        private HashMap    map    = new HashMap( );
+    class FactTables
+        implements
+        Map,
+        Serializable {
+        private LinkedList tables = new LinkedList();
 
+        private HashMap    map    = new HashMap();
+
         public int size() {
-            return this.tables.size( );
+            return this.tables.size();
         }
 
         public void clear() {
-            this.tables.clear( );
-            this.map.clear( );
+            this.tables.clear();
+            this.map.clear();
         }
 
         public boolean isEmpty() {
-            return this.tables.isEmpty( );
+            return this.tables.isEmpty();
         }
 
-        public boolean containsKey( Object key ) {
+        public boolean containsKey(Object key) {
             return this.map.containsKey( key );
         }
 
-        public boolean containsValue( Object value ) {
+        public boolean containsValue(Object value) {
             return this.map.containsValue( value );
         }
 
@@ -843,34 +855,36 @@
             return this.tables;
         }
 
-        public void putAll( Map t ) {
-            this.tables.addAll( t.values( ) );
+        public void putAll(Map t) {
+            this.tables.addAll( t.values() );
             this.map.putAll( t );
         }
 
         public Set entrySet() {
-            return this.map.entrySet( );
+            return this.map.entrySet();
         }
 
         public Set keySet() {
-            return this.map.keySet( );
+            return this.map.keySet();
         }
 
-        public Object get( Object key ) {
+        public Object get(Object key) {
             return this.map.get( key );
 
         }
 
-        public Object remove( Object key ) {
+        public Object remove(Object key) {
             Object ret = this.map.remove( key );
             this.tables.remove( ret );
             return ret;
         }
 
-        public Object put( Object key, Object value ) {
+        public Object put(Object key,
+                          Object value) {
             this.tables.add( value );
-            this.map.put( key, value );
+            this.map.put( key,
+                          value );
             return value;
-        }        
+        }
     }
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -230,7 +230,8 @@
      * @see RuleBase
      */
     public WorkingMemory newWorkingMemory(final boolean keepReference) {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( this );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( this.workingMemoryCounter++,
+                                                                           this );
 
         super.addWorkingMemory( workingMemory,
                                 keepReference );

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-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -57,8 +57,10 @@
      * @param ruleBase
      *            The backing rule-base.
      */
-    public ReteooWorkingMemory(final InternalRuleBase ruleBase) {
-        super( ruleBase,
+    public ReteooWorkingMemory(final int  id, 
+                               final InternalRuleBase ruleBase) {
+        super( id,
+               ruleBase,
                ruleBase.newFactHandleFactory() );
         this.agenda = new DefaultAgenda( this );
     }

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseFactoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseFactoryTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseFactoryTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -17,6 +17,7 @@
  */
 
 import junit.framework.TestCase;
+import org.drools.common.InternalRuleBase;
 
 public class RuleBaseFactoryTest extends TestCase {
 
@@ -24,20 +25,36 @@
         final RuleBase rb = RuleBaseFactory.newRuleBase();
         assertTrue( rb instanceof org.drools.reteoo.ReteooRuleBase );
 
+        assertTrue( !"default".equals( ( ( InternalRuleBase ) rb).getId() ) );
+        assertTrue( !"".equals( ( ( InternalRuleBase ) rb).getId() ) );
+        assertNotNull( ( ( InternalRuleBase ) rb).getId() );        
+        
         final RuleBase rb2 = RuleBaseFactory.newRuleBase( RuleBase.RETEOO );
 
         assertTrue( rb2 instanceof org.drools.reteoo.ReteooRuleBase );
         assertNotSame( rb2,
                        rb );
+        
+        assertTrue( !"default".equals( ( ( InternalRuleBase ) rb2).getId() ) );
+        assertTrue( !"".equals( ( ( InternalRuleBase ) rb2).getId() ) );
+        assertNotNull( ( ( InternalRuleBase ) rb2).getId() );
     }
 
     public void testLeaps() {
         final RuleBase rb = RuleBaseFactory.newRuleBase( RuleBase.LEAPS );
         assertTrue( rb instanceof org.drools.leaps.LeapsRuleBase );
+        assertTrue( !"default".equals( ( ( InternalRuleBase ) rb).getId() ) );
+        assertTrue( !"".equals( ( ( InternalRuleBase ) rb).getId() ) );
+        assertNotNull( ( ( InternalRuleBase ) rb).getId() );        
+        
         final RuleBase rb2 = RuleBaseFactory.newRuleBase( RuleBase.LEAPS );
         assertTrue( rb2 instanceof org.drools.leaps.LeapsRuleBase );
         assertNotSame( rb2,
                        rb );
+        
+        assertTrue( !"default".equals( ( ( InternalRuleBase ) rb2).getId() ) );
+        assertTrue( !"".equals( ( ( InternalRuleBase ) rb2).getId() ) );
+        assertNotNull( ( ( InternalRuleBase ) rb2).getId() );        
     }
-
+        
 }
\ No newline at end of file

Copied: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/LeapsRuleBaseTest.java (from rev 5035, labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/RuleBaseImplTest.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/RuleBaseImplTest.java	2006-07-12 05:00:52 UTC (rev 5035)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/LeapsRuleBaseTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -0,0 +1,398 @@
+package org.drools.leaps;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+
+import org.drools.DroolsTestCase;
+import org.drools.WorkingMemory;
+import org.drools.base.ClassFieldExtractor;
+import org.drools.base.ClassObjectType;
+import org.drools.base.EvaluatorFactory;
+import org.drools.examples.manners.Context;
+import org.drools.rule.Column;
+import org.drools.rule.Declaration;
+import org.drools.rule.LiteralConstraint;
+import org.drools.rule.Rule;
+import org.drools.spi.Consequence;
+import org.drools.spi.ConsequenceException;
+import org.drools.spi.Evaluator;
+import org.drools.spi.FieldConstraint;
+import org.drools.spi.FieldExtractor;
+import org.drools.spi.FieldValue;
+import org.drools.spi.KnowledgeHelper;
+import org.drools.spi.MockField;
+import org.drools.spi.Tuple;
+
+/**
+ * 
+ * @author Alexander Bagerman
+ *
+ */
+public class LeapsRuleBaseTest extends DroolsTestCase {
+    LeapsRuleBase   ruleBase;
+    LeapsRuleBase   ruleBaseAddRule;
+
+    WorkingMemory   wm1;
+
+    WorkingMemory   wm2;
+
+    WorkingMemory   wm3;
+
+    WorkingMemory   wm4;
+
+    // leaps add rule objects
+    final String    handle1Rule1    = "11";
+
+    final String    handle1Rule2    = "12";
+
+    final String    handle2Rule1    = "21";
+
+    final String    handle2Rule2    = "22";
+
+    final ArrayList handlesForRules = new ArrayList();
+
+    WorkingMemory   workingMemory;
+
+    Rule            rule1;
+
+    Rule            rule2;
+
+    final Context   context1        = new Context( 1 );
+
+    final Context   context2        = new Context( 1 );
+
+    public void setUp() throws Exception {
+        this.ruleBase = new LeapsRuleBase();
+
+        this.wm1 = this.ruleBase.newWorkingMemory();
+        this.wm2 = this.ruleBase.newWorkingMemory();
+        this.wm3 = this.ruleBase.newWorkingMemory();
+        this.wm4 = this.ruleBase.newWorkingMemory();
+        // add rules section
+        this.ruleBaseAddRule = new LeapsRuleBase();
+
+        this.workingMemory = this.ruleBaseAddRule.newWorkingMemory();
+        // rules
+        final ClassObjectType contextType = new ClassObjectType( Context.class );
+        final Evaluator integerEqualEvaluator = EvaluatorFactory.getEvaluator( Evaluator.INTEGER_TYPE,
+                                                                               Evaluator.EQUAL );
+        // rule 1
+        // fires on context.state == integer(1)
+        this.rule1 = new Rule( "rule1" );
+        final Column contextColumnRule1 = new Column( 0,
+                                                      contextType,
+                                                      "context1" );
+        contextColumnRule1.addConstraint( getLiteralConstraint( contextColumnRule1,
+                                                                "state",
+                                                                new Integer( 1 ),
+                                                                integerEqualEvaluator ) );
+        this.rule1.addPattern( contextColumnRule1 );
+        final Declaration contextRule1Declaration = this.rule1.getDeclaration( "context1" );
+        this.rule1.setConsequence( new Consequence() {
+            /**
+             * 
+             */
+            private static final long serialVersionUID = -143645020218500159L;
+
+            public void evaluate(final KnowledgeHelper drools,
+                                 final WorkingMemory workingMemory) throws ConsequenceException {
+                try {
+                    final Rule rule = drools.getRule();
+                    final Tuple tuple = drools.getTuple();
+
+                    final Context dummy = (Context) drools.get( contextRule1Declaration );
+                    if ( dummy == LeapsRuleBaseTest.this.context1 ) {
+                        LeapsRuleBaseTest.this.handlesForRules.add( LeapsRuleBaseTest.this.handle1Rule1 );
+                    } else if ( dummy == LeapsRuleBaseTest.this.context2 ) {
+                        LeapsRuleBaseTest.this.handlesForRules.add( LeapsRuleBaseTest.this.handle2Rule1 );
+                    }
+
+                } catch ( final Exception e ) {
+                    throw new ConsequenceException( e );
+                }
+            }
+
+        } );
+        this.rule2 = new Rule( "rule2" );
+        final Column contextColumnRule2 = new Column( 0,
+                                                      contextType,
+                                                      "context2" );
+        contextColumnRule2.addConstraint( getLiteralConstraint( contextColumnRule2,
+                                                                "state",
+                                                                new Integer( 1 ),
+                                                                integerEqualEvaluator ) );
+        this.rule2.addPattern( contextColumnRule2 );
+        final Declaration contextRule2Declaration = this.rule2.getDeclaration( "context2" );
+        this.rule2.setConsequence( new Consequence() {
+            /**
+             * 
+             */
+            private static final long serialVersionUID = 6203944847152159644L;
+
+            public void evaluate(final KnowledgeHelper drools,
+                                 final WorkingMemory workingMemory) throws ConsequenceException {
+                try {
+                    final Rule rule = drools.getRule();
+                    final Tuple tuple = drools.getTuple();
+
+                    final Context dummy = (Context) drools.get( contextRule2Declaration );
+                    if ( dummy == LeapsRuleBaseTest.this.context1 ) {
+                        LeapsRuleBaseTest.this.handlesForRules.add( LeapsRuleBaseTest.this.handle1Rule2 );
+                    } else if ( dummy == LeapsRuleBaseTest.this.context2 ) {
+                        LeapsRuleBaseTest.this.handlesForRules.add( LeapsRuleBaseTest.this.handle2Rule2 );
+                    }
+
+                } catch ( final Exception e ) {
+                    throw new ConsequenceException( e );
+                }
+            }
+
+        } );
+    }
+
+    public void testKeepReference() throws Exception {
+        /* Make sure the RuleBase is referencing all 4 Working Memories */
+        assertLength( 4,
+                      this.ruleBase.getWorkingMemories() );
+        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm1 ) );
+        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm2 ) );
+        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
+        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm4 ) );
+    }
+
+    public void testWeakReference() throws Exception {
+        /* nulling these two so the keys should get garbage collected */
+        this.wm2 = null;
+        this.wm4 = null;
+
+        /* Run GC */
+        System.gc();
+        Thread.sleep( 200 ); // Shouldn't need to sleep, but put it in anyway
+
+        /* Check we now only have two keys */
+        assertLength( 2,
+                      this.ruleBase.getWorkingMemories() );
+
+        /* Make sure the correct keys were valid */
+        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm1 ) );
+        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm2 ) );
+        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
+        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm4 ) );
+
+    }
+
+    public void testDispose() throws Exception {
+        /*
+         * Now lets test the dispose method on the WorkingMemory itself. dispose
+         * doesn't need GC
+         */
+        this.wm3.dispose();
+
+        /* Check only wm3 was valid */
+        assertLength( 3,
+                      this.ruleBase.getWorkingMemories() );
+        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
+    }
+
+    public void testNoKeepReference() throws Exception {
+        final WorkingMemory wm5 = this.ruleBase.newWorkingMemory( false );
+        final WorkingMemory wm6 = this.ruleBase.newWorkingMemory( false );
+        assertLength( 4,
+                      this.ruleBase.getWorkingMemories() );
+        assertFalse( this.ruleBase.getWorkingMemories().contains( wm5 ) );
+        assertFalse( this.ruleBase.getWorkingMemories().contains( wm6 ) );
+    }
+
+    public void testAddRuleBeforeFacts() throws Exception {
+
+        assertEquals( 0,
+                      this.handlesForRules.size() );
+
+        this.ruleBaseAddRule.addRule( this.rule1 );
+        this.ruleBaseAddRule.addRule( this.rule2 );
+        this.workingMemory.assertObject( this.context1 );
+        this.workingMemory.assertObject( this.context2 );
+        // firing
+        this.workingMemory.fireAllRules();
+        // finally everything should be filled
+        assertEquals( 4,
+                      this.handlesForRules.size() );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
+    }
+
+    public void testAddRuleMixedWithFacts() throws Exception {
+
+        assertEquals( 0,
+                      this.handlesForRules.size() );
+
+        this.ruleBaseAddRule.addRule( this.rule1 );
+        this.workingMemory.assertObject( this.context1 );
+        this.ruleBaseAddRule.addRule( this.rule2 );
+        this.workingMemory.assertObject( this.context2 );
+        // firing
+        this.workingMemory.fireAllRules();
+        // finally everything should be filled
+        assertEquals( 4,
+                      this.handlesForRules.size() );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
+    }
+
+    public void testAddRuleAfterFacts() throws Exception {
+
+        assertEquals( 0,
+                      this.handlesForRules.size() );
+        this.workingMemory.assertObject( this.context1 );
+        this.workingMemory.assertObject( this.context2 );
+        this.ruleBaseAddRule.addRule( this.rule1 );
+        this.ruleBaseAddRule.addRule( this.rule2 );
+        // firing
+        this.workingMemory.fireAllRules();
+        // finally everything should be filled
+        assertEquals( 4,
+                      this.handlesForRules.size() );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
+    }
+
+    public void testAddRuleBeforeFactsFiring() throws Exception {
+
+        assertEquals( 0,
+                      this.handlesForRules.size() );
+
+        this.ruleBaseAddRule.addRule( this.rule1 );
+        // firing
+        this.workingMemory.fireAllRules();
+        this.ruleBaseAddRule.addRule( this.rule2 );
+        // firing
+        this.workingMemory.fireAllRules();
+        this.workingMemory.assertObject( this.context1 );
+        // firing
+        this.workingMemory.fireAllRules();
+        this.workingMemory.assertObject( this.context2 );
+        // firing
+        this.workingMemory.fireAllRules();
+        // finally everything should be filled
+        assertEquals( 4,
+                      this.handlesForRules.size() );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
+    }
+
+    public void testAddRuleMixedWithFactsFiring1() throws Exception {
+
+        assertEquals( 0,
+                      this.handlesForRules.size() );
+
+        this.ruleBaseAddRule.addRule( this.rule1 );
+        // firing
+        this.workingMemory.fireAllRules();
+        this.workingMemory.assertObject( this.context1 );
+        // firing
+        this.workingMemory.fireAllRules();
+        this.ruleBaseAddRule.addRule( this.rule2 );
+        // firing
+        this.workingMemory.fireAllRules();
+        this.workingMemory.assertObject( this.context2 );
+        // firing
+        this.workingMemory.fireAllRules();
+        // finally everything should be filled
+        assertEquals( 4,
+                      this.handlesForRules.size() );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
+    }
+
+    public void testAddRuleMixedWithFactsFiring2() throws Exception {
+
+        assertEquals( 0,
+                      this.handlesForRules.size() );
+
+        this.ruleBaseAddRule.addRule( this.rule2 );
+        // firing
+        this.workingMemory.fireAllRules();
+        this.workingMemory.assertObject( this.context1 );
+        // firing
+        this.workingMemory.fireAllRules();
+        // firing
+        this.workingMemory.fireAllRules();
+        this.workingMemory.assertObject( this.context2 );
+        this.ruleBaseAddRule.addRule( this.rule1 );
+        // firing
+        this.workingMemory.fireAllRules();
+        // finally everything should be filled
+        assertEquals( 4,
+                      this.handlesForRules.size() );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
+    }
+
+    public void testAddRuleAfterFactsFiring() throws Exception {
+
+        assertEquals( 0,
+                      this.handlesForRules.size() );
+        this.workingMemory.assertObject( this.context1 );
+        // firing
+        this.workingMemory.fireAllRules();
+        this.workingMemory.assertObject( this.context2 );
+        // firing
+        this.workingMemory.fireAllRules();
+        this.ruleBaseAddRule.addRule( this.rule1 );
+        // firing
+        this.workingMemory.fireAllRules();
+        this.ruleBaseAddRule.addRule( this.rule2 );
+        // firing
+        this.workingMemory.fireAllRules();
+        // finally everything should be filled
+        assertEquals( 4,
+                      this.handlesForRules.size() );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
+        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
+        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
+    }
+
+    private FieldConstraint getLiteralConstraint(final Column column,
+                                                 final String fieldName,
+                                                 final Object fieldValue,
+                                                 final Evaluator evaluator) {
+        final Class clazz = ((ClassObjectType) column.getObjectType()).getClassType();
+
+        final FieldExtractor extractor = new ClassFieldExtractor( clazz,
+                                                                  fieldName );
+
+        final FieldValue field = new MockField( fieldValue );
+
+        return new LiteralConstraint( field,
+                                      extractor,
+                                      evaluator );
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/LeapsWorkingMemoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/LeapsWorkingMemoryTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/LeapsWorkingMemoryTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -0,0 +1,62 @@
+package org.drools.leaps;
+
+import junit.framework.TestCase;
+
+import org.drools.FactHandle;
+import org.drools.common.EqualityKey;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.common.TruthMaintenanceSystem;
+
+public class LeapsWorkingMemoryTest extends TestCase {
+    /*
+     * @see JBRULES-356
+     */
+    public void testBasicWorkingMemoryActions() {
+        LeapsWorkingMemory workingMemory = (LeapsWorkingMemory) new LeapsRuleBase().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 );
+        assertNotSame( fd, key.getFactHandle() );
+        assertNull( key.getOtherFactHandle() );
+        
+        workingMemory.retractObject( key.getFactHandle() );
+        
+        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() );
+    }
+    
+    public void testId() {
+        LeapsRuleBase ruleBase =  new LeapsRuleBase();
+        InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        assertEquals( 0,
+                      workingMemory.getId() );
+        workingMemory = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        assertEquals( 1,
+                      workingMemory.getId() );        
+    }
+}

Deleted: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/RuleBaseImplTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/RuleBaseImplTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/RuleBaseImplTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -1,398 +0,0 @@
-package org.drools.leaps;
-
-/*
- * Copyright 2005 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.ArrayList;
-
-import org.drools.DroolsTestCase;
-import org.drools.WorkingMemory;
-import org.drools.base.ClassFieldExtractor;
-import org.drools.base.ClassObjectType;
-import org.drools.base.EvaluatorFactory;
-import org.drools.examples.manners.Context;
-import org.drools.rule.Column;
-import org.drools.rule.Declaration;
-import org.drools.rule.LiteralConstraint;
-import org.drools.rule.Rule;
-import org.drools.spi.Consequence;
-import org.drools.spi.ConsequenceException;
-import org.drools.spi.Evaluator;
-import org.drools.spi.FieldConstraint;
-import org.drools.spi.FieldExtractor;
-import org.drools.spi.FieldValue;
-import org.drools.spi.KnowledgeHelper;
-import org.drools.spi.MockField;
-import org.drools.spi.Tuple;
-
-/**
- * 
- * @author Alexander Bagerman
- *
- */
-public class RuleBaseImplTest extends DroolsTestCase {
-    LeapsRuleBase   ruleBase;
-    LeapsRuleBase   ruleBaseAddRule;
-
-    WorkingMemory   wm1;
-
-    WorkingMemory   wm2;
-
-    WorkingMemory   wm3;
-
-    WorkingMemory   wm4;
-
-    // leaps add rule objects
-    final String    handle1Rule1    = "11";
-
-    final String    handle1Rule2    = "12";
-
-    final String    handle2Rule1    = "21";
-
-    final String    handle2Rule2    = "22";
-
-    final ArrayList handlesForRules = new ArrayList();
-
-    WorkingMemory   workingMemory;
-
-    Rule            rule1;
-
-    Rule            rule2;
-
-    final Context   context1        = new Context( 1 );
-
-    final Context   context2        = new Context( 1 );
-
-    public void setUp() throws Exception {
-        this.ruleBase = new LeapsRuleBase();
-
-        this.wm1 = this.ruleBase.newWorkingMemory();
-        this.wm2 = this.ruleBase.newWorkingMemory();
-        this.wm3 = this.ruleBase.newWorkingMemory();
-        this.wm4 = this.ruleBase.newWorkingMemory();
-        // add rules section
-        this.ruleBaseAddRule = new LeapsRuleBase();
-
-        this.workingMemory = this.ruleBaseAddRule.newWorkingMemory();
-        // rules
-        final ClassObjectType contextType = new ClassObjectType( Context.class );
-        final Evaluator integerEqualEvaluator = EvaluatorFactory.getEvaluator( Evaluator.INTEGER_TYPE,
-                                                                               Evaluator.EQUAL );
-        // rule 1
-        // fires on context.state == integer(1)
-        this.rule1 = new Rule( "rule1" );
-        final Column contextColumnRule1 = new Column( 0,
-                                                      contextType,
-                                                      "context1" );
-        contextColumnRule1.addConstraint( getLiteralConstraint( contextColumnRule1,
-                                                                "state",
-                                                                new Integer( 1 ),
-                                                                integerEqualEvaluator ) );
-        this.rule1.addPattern( contextColumnRule1 );
-        final Declaration contextRule1Declaration = this.rule1.getDeclaration( "context1" );
-        this.rule1.setConsequence( new Consequence() {
-            /**
-             * 
-             */
-            private static final long serialVersionUID = -143645020218500159L;
-
-            public void evaluate(final KnowledgeHelper drools,
-                                 final WorkingMemory workingMemory) throws ConsequenceException {
-                try {
-                    final Rule rule = drools.getRule();
-                    final Tuple tuple = drools.getTuple();
-
-                    final Context dummy = (Context) drools.get( contextRule1Declaration );
-                    if ( dummy == RuleBaseImplTest.this.context1 ) {
-                        RuleBaseImplTest.this.handlesForRules.add( RuleBaseImplTest.this.handle1Rule1 );
-                    } else if ( dummy == RuleBaseImplTest.this.context2 ) {
-                        RuleBaseImplTest.this.handlesForRules.add( RuleBaseImplTest.this.handle2Rule1 );
-                    }
-
-                } catch ( final Exception e ) {
-                    throw new ConsequenceException( e );
-                }
-            }
-
-        } );
-        this.rule2 = new Rule( "rule2" );
-        final Column contextColumnRule2 = new Column( 0,
-                                                      contextType,
-                                                      "context2" );
-        contextColumnRule2.addConstraint( getLiteralConstraint( contextColumnRule2,
-                                                                "state",
-                                                                new Integer( 1 ),
-                                                                integerEqualEvaluator ) );
-        this.rule2.addPattern( contextColumnRule2 );
-        final Declaration contextRule2Declaration = this.rule2.getDeclaration( "context2" );
-        this.rule2.setConsequence( new Consequence() {
-            /**
-             * 
-             */
-            private static final long serialVersionUID = 6203944847152159644L;
-
-            public void evaluate(final KnowledgeHelper drools,
-                                 final WorkingMemory workingMemory) throws ConsequenceException {
-                try {
-                    final Rule rule = drools.getRule();
-                    final Tuple tuple = drools.getTuple();
-
-                    final Context dummy = (Context) drools.get( contextRule2Declaration );
-                    if ( dummy == RuleBaseImplTest.this.context1 ) {
-                        RuleBaseImplTest.this.handlesForRules.add( RuleBaseImplTest.this.handle1Rule2 );
-                    } else if ( dummy == RuleBaseImplTest.this.context2 ) {
-                        RuleBaseImplTest.this.handlesForRules.add( RuleBaseImplTest.this.handle2Rule2 );
-                    }
-
-                } catch ( final Exception e ) {
-                    throw new ConsequenceException( e );
-                }
-            }
-
-        } );
-    }
-
-    public void testKeepReference() throws Exception {
-        /* Make sure the RuleBase is referencing all 4 Working Memories */
-        assertLength( 4,
-                      this.ruleBase.getWorkingMemories() );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm1 ) );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm2 ) );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm4 ) );
-    }
-
-    public void testWeakReference() throws Exception {
-        /* nulling these two so the keys should get garbage collected */
-        this.wm2 = null;
-        this.wm4 = null;
-
-        /* Run GC */
-        System.gc();
-        Thread.sleep( 200 ); // Shouldn't need to sleep, but put it in anyway
-
-        /* Check we now only have two keys */
-        assertLength( 2,
-                      this.ruleBase.getWorkingMemories() );
-
-        /* Make sure the correct keys were valid */
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm1 ) );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm2 ) );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm4 ) );
-
-    }
-
-    public void testDispose() throws Exception {
-        /*
-         * Now lets test the dispose method on the WorkingMemory itself. dispose
-         * doesn't need GC
-         */
-        this.wm3.dispose();
-
-        /* Check only wm3 was valid */
-        assertLength( 3,
-                      this.ruleBase.getWorkingMemories() );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
-    }
-
-    public void testNoKeepReference() throws Exception {
-        final WorkingMemory wm5 = this.ruleBase.newWorkingMemory( false );
-        final WorkingMemory wm6 = this.ruleBase.newWorkingMemory( false );
-        assertLength( 4,
-                      this.ruleBase.getWorkingMemories() );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( wm5 ) );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( wm6 ) );
-    }
-
-    public void testAddRuleBeforeFacts() throws Exception {
-
-        assertEquals( 0,
-                      this.handlesForRules.size() );
-
-        this.ruleBaseAddRule.addRule( this.rule1 );
-        this.ruleBaseAddRule.addRule( this.rule2 );
-        this.workingMemory.assertObject( this.context1 );
-        this.workingMemory.assertObject( this.context2 );
-        // firing
-        this.workingMemory.fireAllRules();
-        // finally everything should be filled
-        assertEquals( 4,
-                      this.handlesForRules.size() );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
-    }
-
-    public void testAddRuleMixedWithFacts() throws Exception {
-
-        assertEquals( 0,
-                      this.handlesForRules.size() );
-
-        this.ruleBaseAddRule.addRule( this.rule1 );
-        this.workingMemory.assertObject( this.context1 );
-        this.ruleBaseAddRule.addRule( this.rule2 );
-        this.workingMemory.assertObject( this.context2 );
-        // firing
-        this.workingMemory.fireAllRules();
-        // finally everything should be filled
-        assertEquals( 4,
-                      this.handlesForRules.size() );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
-    }
-
-    public void testAddRuleAfterFacts() throws Exception {
-
-        assertEquals( 0,
-                      this.handlesForRules.size() );
-        this.workingMemory.assertObject( this.context1 );
-        this.workingMemory.assertObject( this.context2 );
-        this.ruleBaseAddRule.addRule( this.rule1 );
-        this.ruleBaseAddRule.addRule( this.rule2 );
-        // firing
-        this.workingMemory.fireAllRules();
-        // finally everything should be filled
-        assertEquals( 4,
-                      this.handlesForRules.size() );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
-    }
-
-    public void testAddRuleBeforeFactsFiring() throws Exception {
-
-        assertEquals( 0,
-                      this.handlesForRules.size() );
-
-        this.ruleBaseAddRule.addRule( this.rule1 );
-        // firing
-        this.workingMemory.fireAllRules();
-        this.ruleBaseAddRule.addRule( this.rule2 );
-        // firing
-        this.workingMemory.fireAllRules();
-        this.workingMemory.assertObject( this.context1 );
-        // firing
-        this.workingMemory.fireAllRules();
-        this.workingMemory.assertObject( this.context2 );
-        // firing
-        this.workingMemory.fireAllRules();
-        // finally everything should be filled
-        assertEquals( 4,
-                      this.handlesForRules.size() );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
-    }
-
-    public void testAddRuleMixedWithFactsFiring1() throws Exception {
-
-        assertEquals( 0,
-                      this.handlesForRules.size() );
-
-        this.ruleBaseAddRule.addRule( this.rule1 );
-        // firing
-        this.workingMemory.fireAllRules();
-        this.workingMemory.assertObject( this.context1 );
-        // firing
-        this.workingMemory.fireAllRules();
-        this.ruleBaseAddRule.addRule( this.rule2 );
-        // firing
-        this.workingMemory.fireAllRules();
-        this.workingMemory.assertObject( this.context2 );
-        // firing
-        this.workingMemory.fireAllRules();
-        // finally everything should be filled
-        assertEquals( 4,
-                      this.handlesForRules.size() );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
-    }
-
-    public void testAddRuleMixedWithFactsFiring2() throws Exception {
-
-        assertEquals( 0,
-                      this.handlesForRules.size() );
-
-        this.ruleBaseAddRule.addRule( this.rule2 );
-        // firing
-        this.workingMemory.fireAllRules();
-        this.workingMemory.assertObject( this.context1 );
-        // firing
-        this.workingMemory.fireAllRules();
-        // firing
-        this.workingMemory.fireAllRules();
-        this.workingMemory.assertObject( this.context2 );
-        this.ruleBaseAddRule.addRule( this.rule1 );
-        // firing
-        this.workingMemory.fireAllRules();
-        // finally everything should be filled
-        assertEquals( 4,
-                      this.handlesForRules.size() );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
-    }
-
-    public void testAddRuleAfterFactsFiring() throws Exception {
-
-        assertEquals( 0,
-                      this.handlesForRules.size() );
-        this.workingMemory.assertObject( this.context1 );
-        // firing
-        this.workingMemory.fireAllRules();
-        this.workingMemory.assertObject( this.context2 );
-        // firing
-        this.workingMemory.fireAllRules();
-        this.ruleBaseAddRule.addRule( this.rule1 );
-        // firing
-        this.workingMemory.fireAllRules();
-        this.ruleBaseAddRule.addRule( this.rule2 );
-        // firing
-        this.workingMemory.fireAllRules();
-        // finally everything should be filled
-        assertEquals( 4,
-                      this.handlesForRules.size() );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule1 ) );
-        assertTrue( this.handlesForRules.contains( this.handle1Rule2 ) );
-        assertTrue( this.handlesForRules.contains( this.handle2Rule2 ) );
-    }
-
-    private FieldConstraint getLiteralConstraint(final Column column,
-                                                 final String fieldName,
-                                                 final Object fieldValue,
-                                                 final Evaluator evaluator) {
-        final Class clazz = ((ClassObjectType) column.getObjectType()).getClassType();
-
-        final FieldExtractor extractor = new ClassFieldExtractor( clazz,
-                                                                  fieldName );
-
-        final FieldValue field = new MockField( fieldValue );
-
-        return new LiteralConstraint( field,
-                                      extractor,
-                                      evaluator );
-    }
-}
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeSwitchTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeSwitchTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeSwitchTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -41,7 +41,8 @@
     protected void setUp() throws Exception {
         super.setUp();
 
-        this.workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        this.workingMemory = new ReteooWorkingMemory( 1,
+                                                      new ReteooRuleBase() );
         final MockObjectSource source = new MockObjectSource( 15 );
         final MockObjectSink sink = new MockObjectSink();
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -55,7 +55,8 @@
     }
 
     public void testMemory() {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final AlphaNode alphaNode = new AlphaNode( 2,
                                                    null,
@@ -67,7 +68,8 @@
     }
 
     public void testLiteralConstraintAssertObjectWithMemory() throws Exception {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
         final Rule rule = new Rule( "test-rule" );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
@@ -151,7 +153,8 @@
      * Constraint type.
      */
     public void testReturnValueConstraintAssertObject() throws Exception {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
         final Rule rule = new Rule( "test-rule" );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
@@ -212,7 +215,8 @@
     }
 
     public void testRetractObject() throws Exception {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
         final Rule rule = new Rule( "test-rule" );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
@@ -293,7 +297,8 @@
         // source
         // Also it should only update the latest tuple sinky
 
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
         final Rule rule = new Rule( "test-rule" );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/EvalConditionNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/EvalConditionNodeTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/EvalConditionNodeTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -37,7 +37,8 @@
                                                    null,
                                                    null );
 
-        this.workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        this.workingMemory = new ReteooWorkingMemory( 1,
+                                                      new ReteooRuleBase() );
     }
 
     public void testAttach() throws Exception {
@@ -63,7 +64,8 @@
     }
 
     public void testMemory() {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final MockTupleSource source = new MockTupleSource( 12 );
 
@@ -553,7 +555,8 @@
         // If no child nodes have children then we need to re-process the left
         // and right memories
         // as a joinnode does not store the resulting tuples
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         // Creat the object source so we can detect the alphaNode telling it to
         // propate its contents

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/HashedObjectSinkListTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/HashedObjectSinkListTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/HashedObjectSinkListTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -152,7 +152,8 @@
      * Test method for 'org.drools.reteoo.HashedObjectSinkList.iterator(WorkingMemory, FactHandleImpl)'
      */
     public void testIterator() {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
         final MockObjectSource source = new MockObjectSource( 15 );
         final MockObjectSink sink = new MockObjectSink();
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -49,7 +49,8 @@
                                                    PropagationContext.ASSERTION,
                                                    null,
                                                    null );
-        this.workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        this.workingMemory = new ReteooWorkingMemory( 1,
+                                                      new ReteooRuleBase() );
 
         this.tupleSource = new MockTupleSource( 4 );
         this.objectSource = new MockObjectSource( 4 );
@@ -98,7 +99,8 @@
     }
 
     public void testMemory() {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final MockObjectSource objectSource = new MockObjectSource( 1 );
         final MockTupleSource tupleSource = new MockTupleSource( 1 );
@@ -343,7 +345,8 @@
     }
 
     public void testUpdateWithMemory() {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final JoinNode joinNode = new JoinNode( 1,
                                                 this.tupleSource,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -78,7 +78,8 @@
                                                                        null,
                                                                        null );
 
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final LeftInputAdapterNode liaNode = new LeftInputAdapterNode( 1,
                                                                        new MockObjectSource( 15 ) );
@@ -141,7 +142,8 @@
                                                                        null,
                                                                        null );
 
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final MockObjectSource source = new MockObjectSource( 15 );
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -52,7 +52,8 @@
                                                    PropagationContext.ASSERTION,
                                                    null,
                                                    null );
-        this.workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        this.workingMemory = new ReteooWorkingMemory( 1,
+                                                      new ReteooRuleBase() );
 
         // string1Declaration is bound to column 3 
         this.node = new NotNode( 15,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectSourceTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectSourceTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectSourceTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -57,7 +57,8 @@
                                                                        PropagationContext.ASSERTION,
                                                                        null,
                                                                        null );
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final MockObjectSource source = new MockObjectSource( 15 );
         final MockObjectSink sink1 = new MockObjectSink();
@@ -122,7 +123,8 @@
                                                                        PropagationContext.RETRACTION,
                                                                        null,
                                                                        null );
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final MockObjectSource source = new MockObjectSource( 15 );
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -59,7 +59,8 @@
                                                                        null,
                                                                        null );
 
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final Rete source = new Rete();
 
@@ -95,7 +96,8 @@
     }
 
     public void testMemory() {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
                                                                   new ClassObjectType( String.class ),
@@ -134,7 +136,8 @@
                                                                        null,
                                                                        null );
 
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final Rete source = new Rete();
 
@@ -184,7 +187,8 @@
                                                                        null,
                                                                        null );
 
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final Rete source = new Rete();
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -73,7 +73,8 @@
      */
     public void testCache() throws FactException {
         final ReteooRuleBase ruleBase = new ReteooRuleBase();
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( ruleBase );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           ruleBase );
 
         // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
         final Rete rete = ruleBase.getRete();
@@ -119,7 +120,8 @@
      */
     public void testAssertObject() throws Exception {
         final ReteooRuleBase ruleBase = new ReteooRuleBase();
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( ruleBase );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           ruleBase );
 
         // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
         final Rete rete = ruleBase.getRete();
@@ -167,7 +169,8 @@
      */
     public void testRetractObject() throws Exception {
         final ReteooRuleBase ruleBase = new ReteooRuleBase();
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( ruleBase );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           ruleBase );
 
         // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
         final Rete rete = ruleBase.getRete();

Copied: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooRuleBaseTest.java (from rev 5035, labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleBaseImplTest.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleBaseImplTest.java	2006-07-12 05:00:52 UTC (rev 5035)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooRuleBaseTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -0,0 +1,190 @@
+package org.drools.reteoo;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.DroolsTestCase;
+import org.drools.WorkingMemory;
+
+public class ReteooRuleBaseTest extends DroolsTestCase {
+    ReteooRuleBase ruleBase;
+
+    WorkingMemory  wm1;
+    WorkingMemory  wm2;
+    WorkingMemory  wm3;
+    WorkingMemory  wm4;
+
+    public void setUp() {
+        this.ruleBase = new ReteooRuleBase();
+
+        this.wm1 = this.ruleBase.newWorkingMemory();
+        this.wm2 = this.ruleBase.newWorkingMemory();
+        this.wm3 = this.ruleBase.newWorkingMemory();
+        this.wm4 = this.ruleBase.newWorkingMemory();
+    }
+
+    public void testKeepReference() throws Exception {
+        /* Make sure the RuleBase is referencing all 4 Working Memories */
+        assertLength( 4,
+                      this.ruleBase.getWorkingMemories() );
+        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm1 ) );
+        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm2 ) );
+        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
+        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm4 ) );
+    }
+
+    public void testWeakReference() throws Exception {
+        /* nulling these two so the keys should get garbage collected */
+        this.wm2 = null;
+        this.wm4 = null;
+
+        /* Run GC */
+        System.gc();
+        Thread.sleep( 200 ); // Shouldn't need to sleep, but put it in anyway
+
+        /* Check we now only have two keys */
+        assertLength( 2,
+                      this.ruleBase.getWorkingMemories() );
+
+        /* Make sure the correct keys were removed */
+        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm1 ) );
+        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm2 ) );
+        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
+        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm4 ) );
+
+    }
+
+    public void testDispose() throws Exception {
+        /*
+         * Now lets test the dispose method on the WorkingMemory itself. dispose
+         * doesn't need GC
+         */
+        this.wm3.dispose();
+
+        /* Check only wm3 was removed */
+        assertLength( 3,
+                      this.ruleBase.getWorkingMemories() );
+        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
+    }
+
+    public void testNoKeepReference() throws Exception {
+        final WorkingMemory wm5 = this.ruleBase.newWorkingMemory( false );
+        final WorkingMemory wm6 = this.ruleBase.newWorkingMemory( false );
+        assertLength( 4,
+                      this.ruleBase.getWorkingMemories() );
+        assertFalse( this.ruleBase.getWorkingMemories().contains( wm5 ) );
+        assertFalse( this.ruleBase.getWorkingMemories().contains( wm6 ) );
+    }
+
+    public void testAddPackage() throws Exception {
+        final org.drools.rule.Package pkg1 = new org.drools.rule.Package( "org.droos.test" );
+        pkg1.addGlobal( "global1",
+                        Object.class );
+        pkg1.addGlobal( "global2",
+                        Object.class );
+
+        final org.drools.rule.Package pkg2 = new org.drools.rule.Package( "org.droos.test" );
+        pkg2.addGlobal( "global1",
+                        Object.class );
+        pkg2.addGlobal( "global3",
+                        Object.class );
+
+        final org.drools.rule.Package pkg3 = new org.drools.rule.Package( "org.droos.test2" );
+        pkg3.addGlobal( "global3",
+                        Object.class );
+        pkg3.addGlobal( "global4",
+                        Object.class );
+
+        this.ruleBase.addPackage( pkg1 );
+        // one package
+        assertLength( 1,
+                      this.ruleBase.getPackages() );
+        // two globals
+        assertLength( 2,
+                      this.ruleBase.getGlobals().values() );
+        // two globals in the package also
+        assertLength( 2,
+                      this.ruleBase.getPackages()[0].getGlobals().values() );
+
+        this.ruleBase.addPackage( pkg2 );
+        // packages merged, so still 1 package
+        assertLength( 1,
+                      this.ruleBase.getPackages() );
+        // globals merged, so 3 globals total
+        assertLength( 3,
+                      this.ruleBase.getGlobals().values() );
+        // three globals in the package also
+        assertLength( 3,
+                      this.ruleBase.getPackages()[0].getGlobals().values() );
+
+        this.ruleBase.addPackage( pkg3 );
+        // new package, so now we have 2 package
+        assertLength( 2,
+                      this.ruleBase.getPackages() );
+        // globals partially merged, so 4 globals total
+        assertLength( 4,
+                      this.ruleBase.getGlobals().values() );
+        // two globals in the package
+        final org.drools.rule.Package[] pkgs = this.ruleBase.getPackages();
+        for ( int i = 0; i < pkgs.length; i++ ) {
+            if ( pkgs[i].getName().equals( pkg3.getName() ) ) {
+                assertLength( 2,
+                              pkgs[i].getGlobals().values() );
+            }
+        }
+    }
+
+    public void testRemovePackage() throws Exception {
+        final org.drools.rule.Package pkg1 = new org.drools.rule.Package( "org.droos.test" );
+        pkg1.addGlobal( "global1",
+                        Object.class );
+        pkg1.addGlobal( "global2",
+                        Object.class );
+
+        final org.drools.rule.Package pkg2 = new org.drools.rule.Package( "org.droos.test" );
+        pkg2.addGlobal( "global1",
+                        Object.class );
+        pkg2.addGlobal( "global3",
+                        Object.class );
+
+        final org.drools.rule.Package pkg3 = new org.drools.rule.Package( "org.droos.test2" );
+        pkg3.addGlobal( "global3",
+                        Object.class );
+        pkg3.addGlobal( "global4",
+                        Object.class );
+
+        this.ruleBase.addPackage( pkg1 );
+        this.ruleBase.addPackage( pkg2 );
+        this.ruleBase.addPackage( pkg3 );
+
+        this.ruleBase.removePackage( pkg1.getName() );
+        // packages were partially merged when adding, so removal 
+        // shall left only package 3 behind
+        assertLength( 1,
+                      this.ruleBase.getPackages() );
+        assertLength( 2,
+                      this.ruleBase.getGlobals().values() );
+
+        this.ruleBase.removePackage( pkg3.getName() );
+        assertLength( 0,
+                      this.ruleBase.getPackages() );
+        assertLength( 0,
+                      this.ruleBase.getGlobals().values() );
+
+    }
+    
+
+}
\ No newline at end of file

Modified: 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-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooWorkingMemoryTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -4,6 +4,7 @@
 
 import org.drools.FactHandle;
 import org.drools.common.EqualityKey;
+import org.drools.common.InternalWorkingMemory;
 import org.drools.common.TruthMaintenanceSystem;
 
 public class ReteooWorkingMemoryTest extends TestCase {
@@ -48,4 +49,14 @@
         assertSame( fd, key.getFactHandle() );
         assertNull( key.getOtherFactHandle() );
     }
+    
+    public void testId() {
+        ReteooRuleBase ruleBase =  new ReteooRuleBase();
+        InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        assertEquals( 0,
+                      workingMemory.getId() );
+        workingMemory = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        assertEquals( 1,
+                      workingMemory.getId() );        
+    }
 }

Deleted: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleBaseImplTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleBaseImplTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleBaseImplTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -1,189 +0,0 @@
-package org.drools.reteoo;
-
-/*
- * Copyright 2005 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.DroolsTestCase;
-import org.drools.WorkingMemory;
-
-public class RuleBaseImplTest extends DroolsTestCase {
-    ReteooRuleBase ruleBase;
-
-    WorkingMemory  wm1;
-    WorkingMemory  wm2;
-    WorkingMemory  wm3;
-    WorkingMemory  wm4;
-
-    public void setUp() {
-        this.ruleBase = new ReteooRuleBase();
-
-        this.wm1 = this.ruleBase.newWorkingMemory();
-        this.wm2 = this.ruleBase.newWorkingMemory();
-        this.wm3 = this.ruleBase.newWorkingMemory();
-        this.wm4 = this.ruleBase.newWorkingMemory();
-    }
-
-    public void testKeepReference() throws Exception {
-        /* Make sure the RuleBase is referencing all 4 Working Memories */
-        assertLength( 4,
-                      this.ruleBase.getWorkingMemories() );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm1 ) );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm2 ) );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm4 ) );
-    }
-
-    public void testWeakReference() throws Exception {
-        /* nulling these two so the keys should get garbage collected */
-        this.wm2 = null;
-        this.wm4 = null;
-
-        /* Run GC */
-        System.gc();
-        Thread.sleep( 200 ); // Shouldn't need to sleep, but put it in anyway
-
-        /* Check we now only have two keys */
-        assertLength( 2,
-                      this.ruleBase.getWorkingMemories() );
-
-        /* Make sure the correct keys were removed */
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm1 ) );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm2 ) );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm4 ) );
-
-    }
-
-    public void testDispose() throws Exception {
-        /*
-         * Now lets test the dispose method on the WorkingMemory itself. dispose
-         * doesn't need GC
-         */
-        this.wm3.dispose();
-
-        /* Check only wm3 was removed */
-        assertLength( 3,
-                      this.ruleBase.getWorkingMemories() );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
-    }
-
-    public void testNoKeepReference() throws Exception {
-        final WorkingMemory wm5 = this.ruleBase.newWorkingMemory( false );
-        final WorkingMemory wm6 = this.ruleBase.newWorkingMemory( false );
-        assertLength( 4,
-                      this.ruleBase.getWorkingMemories() );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( wm5 ) );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( wm6 ) );
-    }
-
-    public void testAddPackage() throws Exception {
-        final org.drools.rule.Package pkg1 = new org.drools.rule.Package( "org.droos.test" );
-        pkg1.addGlobal( "global1",
-                        Object.class );
-        pkg1.addGlobal( "global2",
-                        Object.class );
-
-        final org.drools.rule.Package pkg2 = new org.drools.rule.Package( "org.droos.test" );
-        pkg2.addGlobal( "global1",
-                        Object.class );
-        pkg2.addGlobal( "global3",
-                        Object.class );
-
-        final org.drools.rule.Package pkg3 = new org.drools.rule.Package( "org.droos.test2" );
-        pkg3.addGlobal( "global3",
-                        Object.class );
-        pkg3.addGlobal( "global4",
-                        Object.class );
-
-        this.ruleBase.addPackage( pkg1 );
-        // one package
-        assertLength( 1,
-                      this.ruleBase.getPackages() );
-        // two globals
-        assertLength( 2,
-                      this.ruleBase.getGlobals().values() );
-        // two globals in the package also
-        assertLength( 2,
-                      this.ruleBase.getPackages()[0].getGlobals().values() );
-
-        this.ruleBase.addPackage( pkg2 );
-        // packages merged, so still 1 package
-        assertLength( 1,
-                      this.ruleBase.getPackages() );
-        // globals merged, so 3 globals total
-        assertLength( 3,
-                      this.ruleBase.getGlobals().values() );
-        // three globals in the package also
-        assertLength( 3,
-                      this.ruleBase.getPackages()[0].getGlobals().values() );
-
-        this.ruleBase.addPackage( pkg3 );
-        // new package, so now we have 2 package
-        assertLength( 2,
-                      this.ruleBase.getPackages() );
-        // globals partially merged, so 4 globals total
-        assertLength( 4,
-                      this.ruleBase.getGlobals().values() );
-        // two globals in the package
-        final org.drools.rule.Package[] pkgs = this.ruleBase.getPackages();
-        for ( int i = 0; i < pkgs.length; i++ ) {
-            if ( pkgs[i].getName().equals( pkg3.getName() ) ) {
-                assertLength( 2,
-                              pkgs[i].getGlobals().values() );
-            }
-        }
-    }
-
-    public void testRemovePackage() throws Exception {
-        final org.drools.rule.Package pkg1 = new org.drools.rule.Package( "org.droos.test" );
-        pkg1.addGlobal( "global1",
-                        Object.class );
-        pkg1.addGlobal( "global2",
-                        Object.class );
-
-        final org.drools.rule.Package pkg2 = new org.drools.rule.Package( "org.droos.test" );
-        pkg2.addGlobal( "global1",
-                        Object.class );
-        pkg2.addGlobal( "global3",
-                        Object.class );
-
-        final org.drools.rule.Package pkg3 = new org.drools.rule.Package( "org.droos.test2" );
-        pkg3.addGlobal( "global3",
-                        Object.class );
-        pkg3.addGlobal( "global4",
-                        Object.class );
-
-        this.ruleBase.addPackage( pkg1 );
-        this.ruleBase.addPackage( pkg2 );
-        this.ruleBase.addPackage( pkg3 );
-
-        this.ruleBase.removePackage( pkg1.getName() );
-        // packages were partially merged when adding, so removal 
-        // shall left only package 3 behind
-        assertLength( 1,
-                      this.ruleBase.getPackages() );
-        assertLength( 2,
-                      this.ruleBase.getGlobals().values() );
-
-        this.ruleBase.removePackage( pkg3.getName() );
-        assertLength( 0,
-                      this.ruleBase.getPackages() );
-        assertLength( 0,
-                      this.ruleBase.getGlobals().values() );
-
-    }
-
-}
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -56,7 +56,8 @@
                                                                        PropagationContext.RETRACTION,
                                                                        null,
                                                                        null );
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
+                                                                           new ReteooRuleBase() );
 
         final MockTupleSource source = new MockTupleSource( 15 );
         final MockTupleSink sink1 = new MockTupleSink();

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaLeftMemoryTestClass.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaLeftMemoryTestClass.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaLeftMemoryTestClass.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -62,7 +62,8 @@
 
     protected void setUp() throws Exception {
         super.setUp();
-        this.workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        this.workingMemory = new ReteooWorkingMemory( 0, 
+                                                      new ReteooRuleBase() );
         this.obj0 = new DummyValueObject( true,
                                           "string1",
                                           10,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaRightMemoryTestClass.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaRightMemoryTestClass.java	2006-07-12 19:00:57 UTC (rev 5050)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaRightMemoryTestClass.java	2006-07-12 19:40:12 UTC (rev 5051)
@@ -67,7 +67,8 @@
 
     protected void setUp() throws Exception {
         super.setUp();
-        this.workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
+        this.workingMemory = new ReteooWorkingMemory( 0, 
+                                                      new ReteooRuleBase() );
         this.obj0 = new DummyValueObject( true,
                                           "string1",
                                           10,




More information about the jboss-svn-commits mailing list