[jboss-svn-commits] JBL Code SVN: r19238 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/reteoo and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Mar 26 09:02:31 EDT 2008


Author: mark.proctor at jboss.com
Date: 2008-03-26 09:02:31 -0400 (Wed, 26 Mar 2008)
New Revision: 19238

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java
Log:
JBRULES-1520 RightTuple merge for asynchronous Rete propagations
-fixed AlphaNodeTest
-removed alphanode memory configuration

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java	2008-03-26 12:21:50 UTC (rev 19237)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java	2008-03-26 13:02:31 UTC (rev 19238)
@@ -96,7 +96,6 @@
     private boolean                        removeIdentities;
     private boolean                        shareAlphaNodes;
     private boolean                        shareBetaNodes;
-    private boolean                        alphaMemory;
     private int                            alphaNodeHashingThreshold;
     private int                            compositeKeyDepth;
     private boolean                        indexLeftBetaMemory;
@@ -129,7 +128,6 @@
         out.writeBoolean( removeIdentities );
         out.writeBoolean( shareAlphaNodes );
         out.writeBoolean( shareBetaNodes );
-        out.writeBoolean( alphaMemory );
         out.writeInt( alphaNodeHashingThreshold );
         out.writeInt( compositeKeyDepth );
         out.writeBoolean( indexLeftBetaMemory );
@@ -156,7 +154,6 @@
         removeIdentities = in.readBoolean();
         shareAlphaNodes = in.readBoolean();
         shareBetaNodes = in.readBoolean();
-        alphaMemory = in.readBoolean();
         alphaNodeHashingThreshold = in.readInt();
         compositeKeyDepth = in.readInt();
         indexLeftBetaMemory = in.readBoolean();
@@ -256,10 +253,7 @@
 
         setRemoveIdentities( Boolean.valueOf( this.chainedProperties.getProperty( "drools.removeIdentities",
                                                                                   "false" ) ).booleanValue() );
-
-        setAlphaMemory( Boolean.valueOf( this.chainedProperties.getProperty( "drools.alphaMemory",
-                                                                             "false" ) ).booleanValue() );
-
+        
         setShareAlphaNodes( Boolean.valueOf( this.chainedProperties.getProperty( "drools.shareAlphaNodes",
                                                                                  "true" ) ).booleanValue() );
 
@@ -357,15 +351,6 @@
         this.removeIdentities = removeIdentities;
     }
 
-    public boolean isAlphaMemory() {
-        return this.alphaMemory;
-    }
-
-    public void setAlphaMemory(final boolean alphaMemory) {
-        checkCanChange(); // throws an exception if a change isn't possible;
-        this.alphaMemory = alphaMemory;
-    }
-
     public boolean isShareAlphaNodes() {
         return this.shareAlphaNodes;
     }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java	2008-03-26 12:21:50 UTC (rev 19237)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java	2008-03-26 13:02:31 UTC (rev 19238)
@@ -153,10 +153,12 @@
     public void updateSink(final ObjectSink sink,
                            final PropagationContext context,
                            final InternalWorkingMemory workingMemory) {
-        AlphaMemory memory = (AlphaMemory) workingMemory.getNodeMemory( this );
+        final AlphaMemory memory = (AlphaMemory) workingMemory.getNodeMemory( this );
+        
         // get the objects from the parent
         ObjectSinkUpdateAdapter adapter = new ObjectSinkUpdateAdapter( sink,
-                                                                       this.constraint );
+                                                                       this.constraint,
+                                                                       memory.context );
         this.source.updateSink( adapter,
                                 context,
                                 workingMemory );
@@ -287,41 +289,31 @@
         ObjectSink {
         private final ObjectSink               sink;
         private final AlphaNodeFieldConstraint constraint;
+        private final ContextEntry contextEntry;
 
         public ObjectSinkUpdateAdapter(final ObjectSink sink,
-                                       final AlphaNodeFieldConstraint constraint) {
+                                       final AlphaNodeFieldConstraint constraint, 
+                                       final ContextEntry contextEntry) {
             this.sink = sink;
             this.constraint = constraint;
+            this.contextEntry = contextEntry;
         }
 
-        public void assertFact(final InternalFactHandle handle,
+        public void assertObject(final InternalFactHandle handle,
                                final PropagationContext propagationContext,
-                               final InternalWorkingMemory workingMemory,
-                               final ContextEntry contextEntry) {
+                               final InternalWorkingMemory workingMemory ) {
 
             if ( this.constraint.isAllowed( handle,
                                             workingMemory,
-                                            contextEntry ) ) {
+                                            this.contextEntry ) ) {
                 this.sink.assertObject( handle,
                                         propagationContext,
                                         workingMemory );
             }
         }
 
-        public void retractRightTuple(final RightTuple rightTuple,
-                                      final PropagationContext context,
-                                      final InternalWorkingMemory workingMemory) {
-            throw new UnsupportedOperationException( "RightTupleSinkUpdateAdapter.retractFact is not supported." );
-        }
-
         public int getId() {
             return 0;
         }
-
-        public void assertObject(InternalFactHandle factHandle,
-                                 PropagationContext context,
-                                 InternalWorkingMemory workingMemory) {
-            throw new UnsupportedOperationException( "RightTupleSinkUpdateAdapter.assertFact is not supported." );
-        }
     }
 }

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	2008-03-26 12:21:50 UTC (rev 19237)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java	2008-03-26 13:02:31 UTC (rev 19238)
@@ -46,190 +46,8 @@
     ClassFieldExtractorCache     cache  = ClassFieldExtractorCache.getInstance();
     EqualityEvaluatorsDefinition equals = new EqualityEvaluatorsDefinition();
 
-    public void testMemory() {
-        RuleBaseConfiguration config = new RuleBaseConfiguration();
-        config.setAlphaMemory( false );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( config );
-        BuildContext buildContext = new BuildContext( ruleBase,
-                                                      ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
-        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
-
-        final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
-                                                                  "type",
-                                                                  getClass().getClassLoader() );
-
-        final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
-
-        final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE,
-                                                         Operator.EQUAL );
-        final LiteralConstraint constraint = new LiteralConstraint( extractor,
-                                                                    evaluator,
-                                                                    field );
-
-        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
-                                                   constraint,
-                                                   null,
-                                                   buildContext );
-
-        final AlphaMemory memory = (AlphaMemory) workingMemory.getNodeMemory( alphaNode );
-
-        assertNotNull( memory );
-    }
-
-    public void testLiteralConstraintAssertObjectWithMemory() throws Exception {
-        RuleBaseConfiguration config = new RuleBaseConfiguration();
-        config.setAlphaMemory( true );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( config );
-        BuildContext buildContext = new BuildContext( ruleBase,
-                                                      ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
-        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
-
-        final Rule rule = new Rule( "test-rule" );
-        final PropagationContext context = new PropagationContextImpl( 0,
-                                                                       PropagationContext.ASSERTION,
-                                                                       null,
-                                                                       null );
-
-        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
-
-        final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
-                                                                  "type",
-                                                                  getClass().getClassLoader() );
-
-        final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
-
-        final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE,
-                                                         Operator.EQUAL );
-        final LiteralConstraint constraint = new LiteralConstraint( extractor,
-                                                                    evaluator,
-                                                                    field );
-
-        // With Memory
-        buildContext.setAlphaNodeMemoryAllowed( true );
-        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
-                                                   constraint,
-                                                   source,
-                                                   buildContext ); // has memory
-
-        final MockObjectSink sink = new MockObjectSink();
-        alphaNode.addObjectSink( sink );
-
-        final Cheese cheddar = new Cheese( "cheddar",
-                                           5 );
-        final DefaultFactHandle f0 = (DefaultFactHandle) workingMemory.insert( cheddar );
-
-        // check sink is empty
-        assertLength( 0,
-                      sink.getAsserted() );
-
-        // check alpha memory is empty 
-        final AlphaMemory memory = (AlphaMemory) workingMemory.getNodeMemory( alphaNode );
-
-        assertEquals( 0,
-                      memory.facts.size() );
-
-        // object should assert as it passes text
-        alphaNode.assertObject( f0,
-                                context,
-                                workingMemory );
-
-        assertEquals( 1,
-                      sink.getAsserted().size() );
-        assertEquals( 1,
-                      memory.facts.size() );
-        Object[] list = (Object[]) sink.getAsserted().get( 0 );
-        assertSame( cheddar,
-                    workingMemory.getObject( (DefaultFactHandle) list[0] ) );
-        assertTrue( "Should contain 'cheddar handle'",
-                    memory.facts.contains( f0 ) );
-
-        final Cheese stilton = new Cheese( "stilton",
-                                           6 );
-        final DefaultFactHandle f1 = new DefaultFactHandle( 1,
-                                                            stilton );
-
-        // object should NOT assert as it does not pass test
-        alphaNode.assertObject( f1,
-                                context,
-                                workingMemory );
-
-        assertLength( 1,
-                      sink.getAsserted() );
-        assertEquals( 1,
-                      memory.facts.size() );
-        list = (Object[]) sink.getAsserted().get( 0 );
-        assertSame( cheddar,
-                    workingMemory.getObject( (DefaultFactHandle) list[0] ) );
-        assertTrue( "Should contain 'cheddar handle'",
-                    memory.facts.contains( f0 ) );
-    }
-
-    public void testIsMemoryAllowedOverride() throws Exception {
-        RuleBaseConfiguration config = new RuleBaseConfiguration();
-        config.setAlphaMemory( true );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( config );
-        BuildContext buildContext = new BuildContext( ruleBase,
-                                                      ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
-        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
-
-        final Rule rule = new Rule( "test-rule" );
-        final PropagationContext context = new PropagationContextImpl( 0,
-                                                                       PropagationContext.ASSERTION,
-                                                                       null,
-                                                                       null );
-
-        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
-
-        final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
-                                                                  "type",
-                                                                  getClass().getClassLoader() );
-
-        final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
-
-        final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE,
-                                                         Operator.EQUAL );
-        final LiteralConstraint constraint = new LiteralConstraint( extractor,
-                                                                    evaluator,
-                                                                    field );
-
-        // With Memory
-        buildContext.setAlphaNodeMemoryAllowed( false );
-        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
-                                                   constraint,
-                                                   source,
-                                                   buildContext ); // has memory
-
-        final MockObjectSink sink = new MockObjectSink();
-        alphaNode.addObjectSink( sink );
-
-        final Cheese cheddar = new Cheese( "cheddar",
-                                           5 );
-        final DefaultFactHandle f0 = (DefaultFactHandle) workingMemory.insert( cheddar );
-
-        // check sink is empty
-        assertLength( 0,
-                      sink.getAsserted() );
-
-        // check alpha memory is empty 
-        final AlphaMemory memory = (AlphaMemory) workingMemory.getNodeMemory( alphaNode );
-
-        assertNull( memory.facts );
-
-        // object should assert as it passes text
-        alphaNode.assertObject( f0,
-                                context,
-                                workingMemory );
-
-        assertEquals( 1,
-                      sink.getAsserted().size() );
-        // memory should be one, as even though isAlphaMemory is on for the configuration, the build never allows memory
-        assertNull( memory.facts );
-    }
-
     public void testLiteralConstraintAssertObjectWithoutMemory() throws Exception {
-        RuleBaseConfiguration config = new RuleBaseConfiguration();
-        config.setAlphaMemory( false );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( config );
+        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( );
         BuildContext buildContext = new BuildContext( ruleBase,
                                                       ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
         ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
@@ -274,7 +92,6 @@
         // check alpha memory is empty 
         final AlphaMemory memory = (AlphaMemory) workingMemory.getNodeMemory( alphaNode );
 
-        assertNull( memory.facts );
 
         // object should assert as it passes text
         alphaNode.assertObject( f0,
@@ -283,7 +100,7 @@
 
         assertEquals( 1,
                       sink.getAsserted().size() );
-        assertNull( memory.facts );
+        
         Object[] list = (Object[]) sink.getAsserted().get( 0 );
         assertSame( cheddar,
                     workingMemory.getObject( (DefaultFactHandle) list[0] ) );
@@ -300,102 +117,17 @@
 
         assertLength( 1,
                       sink.getAsserted() );
-        assertNull( memory.facts );
-        list = (Object[]) sink.getAsserted().get( 0 );
-        assertSame( cheddar,
-                    workingMemory.getObject( (DefaultFactHandle) list[0] ) );
-    }
 
-    public void testLiteralConstraintAssertSequentialMode() throws Exception {
-        RuleBaseConfiguration config = new RuleBaseConfiguration();
-        config.setSequential( true );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( config );
-        BuildContext buildContext = new BuildContext( ruleBase,
-                                                      ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
-        ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( buildContext.getNextId(),
-                                                                     ruleBase );
-
-        final Rule rule = new Rule( "test-rule" );
-        final PropagationContext context = new PropagationContextImpl( 0,
-                                                                       PropagationContext.ASSERTION,
-                                                                       null,
-                                                                       null );
-
-        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
-
-        final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
-                                                                  "type",
-                                                                  getClass().getClassLoader() );
-
-        final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
-
-        final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE,
-                                                         Operator.EQUAL );
-        final LiteralConstraint constraint = new LiteralConstraint( extractor,
-                                                                    evaluator,
-                                                                    field );
-
-        // With Memory
-        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
-                                                   constraint,
-                                                   source,
-                                                   buildContext ); // has memory
-
-        final MockObjectSink sink = new MockObjectSink();
-        alphaNode.addObjectSink( sink );
-
-        final Cheese cheddar = new Cheese( "cheddar",
-                                           5 );
-        final DefaultFactHandle f0 = (DefaultFactHandle) workingMemory.insert( cheddar );
-
-        // check sink is empty
-        assertLength( 0,
-                      sink.getAsserted() );
-
-        // check alpha memory is empty 
-        final AlphaMemory memory = (AlphaMemory) workingMemory.getNodeMemory( alphaNode );
-
-        assertNull( memory.facts );
-
-        // object should assert as it passes text
-        alphaNode.assertObject( f0,
-                                context,
-                                workingMemory );
-
-        assertEquals( 1,
-                      sink.getAsserted().size() );
-        assertNull( memory.facts );
-        Object[] list = (Object[]) sink.getAsserted().get( 0 );
-        assertSame( cheddar,
-                    workingMemory.getObject( (DefaultFactHandle) list[0] ) );
-
-        final Cheese stilton = new Cheese( "stilton",
-                                           6 );
-        final DefaultFactHandle f1 = new DefaultFactHandle( 1,
-                                                            stilton );
-
-        // object should NOT assert as it does not pass test
-        alphaNode.assertObject( f1,
-                                context,
-                                workingMemory );
-
-        assertLength( 1,
-                      sink.getAsserted() );
-        assertNull( memory.facts );
         list = (Object[]) sink.getAsserted().get( 0 );
         assertSame( cheddar,
                     workingMemory.getObject( (DefaultFactHandle) list[0] ) );
     }
 
     /*
-     * dont need to test with and without memory on this, as it was already done
-     * on the previous two tests. This just test AlphaNode With a different
-     * Constraint type.
+     *  This just test AlphaNode With a different Constraint type.
      */
     public void testReturnValueConstraintAssertObject() throws Exception {
-        RuleBaseConfiguration config = new RuleBaseConfiguration();
-        config.setAlphaMemory( false );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( config );
+        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( );
         BuildContext buildContext = new BuildContext( ruleBase,
                                                       ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
         ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
@@ -461,263 +193,10 @@
                       sink.getAsserted() );
     }
 
-    public void testRetractObjectWithMemory() throws Exception {
-        RuleBaseConfiguration config = new RuleBaseConfiguration();
-        config.setAlphaMemory( true );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( config );
-        BuildContext buildContext = new BuildContext( ruleBase,
-                                                      ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
-        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
-
-        final Rule rule = new Rule( "test-rule" );
-        final PropagationContext context = new PropagationContextImpl( 0,
-                                                                       PropagationContext.ASSERTION,
-                                                                       null,
-                                                                       null );
-
-        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
-
-        final FieldExtractor extractor = cache.getExtractor( Cheese.class,
-                                                             "type",
-                                                             getClass().getClassLoader() );
-
-        final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
-
-        final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE,
-                                                         Operator.EQUAL );
-        final LiteralConstraint constraint = new LiteralConstraint( extractor,
-                                                                    evaluator,
-                                                                    field );
-
-        buildContext.setAlphaNodeMemoryAllowed( true );
-        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
-                                                   constraint,
-                                                   source,
-                                                   buildContext ); // has memory
-        final MockObjectSink sink = new MockObjectSink();
-        alphaNode.addObjectSink( sink );
-
-        final Cheese cheddar = new Cheese( "cheddar",
-                                           5 );
-
-        final DefaultFactHandle f0 = new DefaultFactHandle( 0,
-                                                            cheddar );
-
-        // check alpha memory is empty
-        final AlphaMemory memory = (AlphaMemory) workingMemory.getNodeMemory( alphaNode );
-        assertEquals( 0,
-                      memory.facts.size() );
-
-        // object should assert as it passes text
-        alphaNode.assertObject( f0,
-                                context,
-                                workingMemory );
-
-        assertEquals( 1,
-                      memory.facts.size() );
-
-        final DefaultFactHandle f1 = new DefaultFactHandle( 1,
-                                                            "cheese" );
-
-        // object should NOT retract as it doesn't exist
-        alphaNode.retractObject( f1,
-                                 context,
-                                 workingMemory );
-
-        assertLength( 0,
-                      sink.getRetracted() );
-        assertEquals( 1,
-                      memory.facts.size() );
-        assertTrue( "Should contain 'cheddar handle'",
-                    memory.facts.contains( f0 ) );
-
-        // object should retract as it does exist
-        alphaNode.retractObject( f0,
-                                 context,
-                                 workingMemory );
-
-        assertLength( 1,
-                      sink.getRetracted() );
-        assertEquals( 0,
-                      memory.facts.size() );
-        final Object[] list = (Object[]) sink.getRetracted().get( 0 );
-        assertSame( f0,
-                    list[0] );
-
-    }
-
-    public void testRetractObjectWithoutMemory() throws Exception {
-        RuleBaseConfiguration config = new RuleBaseConfiguration();
-        config.setAlphaMemory( false );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( config );
-        BuildContext buildContext = new BuildContext( ruleBase,
-                                                      ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
-        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
-
-        final Rule rule = new Rule( "test-rule" );
-        final PropagationContext context = new PropagationContextImpl( 0,
-                                                                       PropagationContext.ASSERTION,
-                                                                       null,
-                                                                       null );
-
-        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
-
-        final FieldExtractor extractor = cache.getExtractor( Cheese.class,
-                                                             "type",
-                                                             getClass().getClassLoader() );
-
-        final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
-
-        final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE,
-                                                         Operator.EQUAL );
-        final LiteralConstraint constraint = new LiteralConstraint( extractor,
-                                                                    evaluator,
-                                                                    field );
-
-        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
-                                                   constraint,
-                                                   source,
-                                                   buildContext ); // no memory
-        final MockObjectSink sink = new MockObjectSink();
-        alphaNode.addObjectSink( sink );
-
-        final Cheese cheddar = new Cheese( "cheddar",
-                                           5 );
-
-        final DefaultFactHandle f0 = new DefaultFactHandle( 0,
-                                                            cheddar );
-
-        // check alpha memory is empty
-        final AlphaMemory memory = (AlphaMemory) workingMemory.getNodeMemory( alphaNode );
-        assertNull( memory.facts );
-
-        // object should assert as it passes text
-        alphaNode.assertObject( f0,
-                                context,
-                                workingMemory );
-
-        assertNull( memory.facts );
-
-        final DefaultFactHandle f1 = new DefaultFactHandle( 1,
-                                                            new Cheese( "brie",
-                                                                        10 ) );
-
-        // object should NOT retract as it doesn't exist
-        alphaNode.retractObject( f1,
-                                 context,
-                                 workingMemory );
-
-        // without memory, it will always propagate a retract
-        assertLength( 0,
-                      sink.getRetracted() );
-        assertNull( memory.facts );
-
-        // object should retract as it does exist
-        alphaNode.retractObject( f0,
-                                 context,
-                                 workingMemory );
-
-        assertLength( 1,
-                      sink.getRetracted() );
-        assertNull( memory.facts );
-        final Object[] list = (Object[]) sink.getRetracted().get( 0 );
-        assertSame( f0,
-                    list[0] );
-
-    }
-
-    public void testUpdateSinkWithMemory() throws FactException,
-                                          IntrospectionException {
-        // An AlphaNode with memory should not try and repropagate from its source
-        // Also it should only update the latest tuple sinky
-        RuleBaseConfiguration config = new RuleBaseConfiguration();
-        config.setAlphaMemory( true );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( config );
-        BuildContext buildContext = new BuildContext( ruleBase,
-                                                      ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
-        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
-
-        final Rule rule = new Rule( "test-rule" );
-        final PropagationContext context = new PropagationContextImpl( 0,
-                                                                       PropagationContext.ASSERTION,
-                                                                       null,
-                                                                       null );
-
-        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
-
-        final FieldExtractor extractor = cache.getExtractor( Cheese.class,
-                                                             "type",
-                                                             getClass().getClassLoader() );
-
-        final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
-
-        final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE,
-                                                         Operator.EQUAL );
-        final LiteralConstraint constraint = new LiteralConstraint( extractor,
-                                                                    evaluator,
-                                                                    field );
-
-        buildContext.setAlphaNodeMemoryAllowed( true );
-        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
-                                                   constraint,
-                                                   source,
-                                                   buildContext ); // has memory
-
-        alphaNode.attach();
-
-        final MockObjectSink sink1 = new MockObjectSink();
-        alphaNode.addObjectSink( sink1 );
-
-        // Assert a single fact which should be in the AlphaNode memory and also
-        // propagated to the
-        // the tuple sink
-        final Cheese cheese = new Cheese( "cheddar",
-                                          0 );
-        final DefaultFactHandle handle1 = new DefaultFactHandle( 1,
-                                                                 cheese );
-
-        alphaNode.assertObject( handle1,
-                                context,
-                                workingMemory );
-
-        // Create a fact that should not be propagated, since the alpha node restriction will filter it out
-        final Cheese stilton = new Cheese( "stilton",
-                                           10 );
-        final DefaultFactHandle handle2 = new DefaultFactHandle( 2,
-                                                                 stilton );
-        // adding handle to the mock source
-        source.addFact( handle2 );
-
-        alphaNode.assertObject( handle2,
-                                context,
-                                workingMemory );
-        assertLength( 1,
-                      sink1.getAsserted() );
-
-        // Attach a new tuple sink
-        final MockObjectSink sink2 = new MockObjectSink();
-
-        // Tell the alphanode to update the new node. Make sure the first sink1
-        // is not updated
-        // likewise the source should not do anything
-        alphaNode.updateSink( sink2,
-                              context,
-                              workingMemory );
-
-        assertLength( 1,
-                      sink1.getAsserted() );
-        assertLength( 1,
-                      sink2.getAsserted() );
-        assertEquals( 0,
-                      source.getUdated() );
-    }
-
     public void testUpdateSinkWithoutMemory() throws FactException,
                                              IntrospectionException {
-        // An AlphaNode without memory should try and repropagate from its source
-        RuleBaseConfiguration config = new RuleBaseConfiguration();
-        config.setAlphaMemory( false );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( config );
+        // An AlphaNode should try and repropagate from its source
+        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( );
         BuildContext buildContext = new BuildContext( ruleBase,
                                                       ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
         ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();




More information about the jboss-svn-commits mailing list