[jboss-svn-commits] JBL Code SVN: r31980 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/marshalling/impl and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Mar 7 11:20:06 EST 2010


Author: tirelli
Date: 2010-03-07 11:20:06 -0500 (Sun, 07 Mar 2010)
New Revision: 31980

Added:
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/EvalNodeStep.java
   labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/EvalNodeTest.nodeTestCase
Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/core/util/debug/EvalConditionNodeVisitor.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.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/test/ReteDslTestEngine.java
Log:
JBRULES-2339: JBRULES-2340: fixing Eval node and adding test case

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/core/util/debug/EvalConditionNodeVisitor.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/core/util/debug/EvalConditionNodeVisitor.java	2010-03-07 14:48:45 UTC (rev 31979)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/core/util/debug/EvalConditionNodeVisitor.java	2010-03-07 16:20:06 UTC (rev 31980)
@@ -3,8 +3,6 @@
 import java.util.Stack;
 
 import org.drools.common.NetworkNode;
-import org.drools.reteoo.EvalConditionNode;
-import org.drools.reteoo.EvalConditionNode.EvalMemory;
 
 public class EvalConditionNodeVisitor extends AbstractNetworkNodeVisitor {
     
@@ -17,16 +15,8 @@
     protected void doVisit(NetworkNode node,
                            Stack<NetworkNode> nodeStack,
                            StatefulKnowledgeSessionInfo info) {
-        EvalConditionNode ecn = (EvalConditionNode) node;
         DefaultNodeInfo ni = (DefaultNodeInfo) info.getNodeInfo( node );
-        final EvalMemory memory = (EvalMemory) info.getSession().getNodeMemory( ecn );
-        
-        ni.setMemoryEnabled( ecn.isLeftTupleMemoryEnabled() );
-        
-        if( ecn.isLeftTupleMemoryEnabled() ) {
-            ni.setTupleMemorySize( memory.getLeftTupleMemory().size() );
-        }
-
+        ni.setMemoryEnabled( false );
     }
 
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java	2010-03-07 14:48:45 UTC (rev 31979)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java	2010-03-07 16:20:06 UTC (rev 31980)
@@ -463,8 +463,6 @@
 
             }
             case NodeTypeEnums.EvalConditionNode : {
-                final EvalMemory memory = (EvalMemory) context.wm.getNodeMemory( (EvalConditionNode) sink );
-                memory.tupleMemory.add( parentLeftTuple );
                 while ( stream.readShort() == PersisterEnums.LEFT_TUPLE ) {
                     LeftTupleSink childSink = (LeftTupleSink) sinks.get( stream.readInt() );
                     LeftTuple childLeftTuple = new LeftTuple( parentLeftTuple,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java	2010-03-07 14:48:45 UTC (rev 31979)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java	2010-03-07 16:20:06 UTC (rev 31980)
@@ -27,8 +27,7 @@
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.NodeMemory;
 import org.drools.common.PropagationContextImpl;
-import org.drools.core.util.Iterator;
-import org.drools.core.util.LeftTupleList;
+import org.drools.common.RuleBasePartitionId;
 import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.EvalCondition;
 import org.drools.spi.PropagationContext;
@@ -183,10 +182,6 @@
                                                           memory.context );
 
         if ( allowed ) {
-            if ( this.tupleMemoryEnabled ) {
-                memory.tupleMemory.add( leftTuple );
-            }
-
             this.sink.propagateAssertLeftTuple( leftTuple,
                                                 context,
                                                 workingMemory,
@@ -197,12 +192,11 @@
     public void retractLeftTuple(final LeftTuple leftTuple,
                                  final PropagationContext context,
                                  final InternalWorkingMemory workingMemory) {
-        final EvalMemory memory = (EvalMemory) workingMemory.getNodeMemory( this );
-
-        memory.tupleMemory.remove( leftTuple );
-        this.sink.propagateRetractLeftTuple( leftTuple,
-                                             context,
-                                             workingMemory );
+        if ( leftTuple.firstChild != null ) {
+            this.sink.propagateRetractLeftTuple( leftTuple,
+                                                 context,
+                                                 workingMemory );
+        }
     }
 
     public void modifyLeftTuple(InternalFactHandle factHandle,
@@ -230,19 +224,13 @@
                                 PropagationContext context,
                                 InternalWorkingMemory workingMemory) {
         final EvalMemory memory = (EvalMemory) workingMemory.getNodeMemory( this );
-        boolean wasPropagated = false;
+        boolean wasPropagated = leftTuple.firstChild != null;
 
-        if ( memory.tupleMemory.contains( leftTuple ) ) {
-            memory.tupleMemory.remove( leftTuple );
-            wasPropagated = true;
-        }
         final boolean allowed = this.condition.isAllowed( leftTuple,
                                                           workingMemory,
                                                           memory.context );
 
         if ( allowed ) {
-            // re-add tuple to the end of the list
-            memory.tupleMemory.add( leftTuple );
             if ( wasPropagated ) {
                 // modify
                 this.sink.propagateModifyChildLeftTuple( leftTuple,
@@ -257,7 +245,7 @@
                                                     this.tupleMemoryEnabled );
             }
         } else {
-            if( wasPropagated ) {
+            if ( wasPropagated ) {
                 // retract
                 this.sink.propagateRetractLeftTuple( leftTuple,
                                                      context,
@@ -295,8 +283,7 @@
     }
 
     public Object createMemory(final RuleBaseConfiguration config) {
-        return new EvalMemory( this.tupleMemoryEnabled,
-                               this.condition.createContext() );
+        return new EvalMemory( this.condition.createContext() );
     }
 
     /* (non-Javadoc)
@@ -305,15 +292,12 @@
     public void updateSink(final LeftTupleSink sink,
                            final PropagationContext context,
                            final InternalWorkingMemory workingMemory) {
-
-        final EvalMemory memory = (EvalMemory) workingMemory.getNodeMemory( this );
-
-        final Iterator it = memory.tupleMemory.iterator();
-        for ( LeftTuple tuple = (LeftTuple) it.next(); tuple != null; tuple = (LeftTuple) it.next() ) {
-            sink.assertLeftTuple( tuple,
-                                  context,
-                                  workingMemory );
-        }
+        final LeftTupleSinkUpdateAdapter adapter = new LeftTupleSinkUpdateAdapter( this,
+                                                                                   sink,
+                                                                                   condition );
+        this.tupleSource.updateSink( adapter,
+                                     context,
+                                     workingMemory );
     }
 
     protected void doRemove(final RuleRemovalContext context,
@@ -327,12 +311,6 @@
 
         if ( !this.isInUse() ) {
             for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
-                EvalMemory memory = (EvalMemory) workingMemories[i].getNodeMemory( this );
-                Iterator it = memory.getLeftTupleMemory().iterator();
-                for ( LeftTuple leftTuple = (LeftTuple) it.next(); leftTuple != null; leftTuple = (LeftTuple) it.next() ) {
-                    leftTuple.unlinkFromLeftParent();
-                    leftTuple.unlinkFromRightParent();
-                }
                 workingMemories[i].clearNodeMemory( this );
             }
         }
@@ -399,35 +377,111 @@
 
         private static final long serialVersionUID = -2754669682742843929L;
 
-        public LeftTupleList      tupleMemory;
         public Object             context;
 
         public EvalMemory() {
 
         }
 
-        public LeftTupleList getLeftTupleMemory() {
-            return this.tupleMemory;
-        }
-
-        public EvalMemory(final boolean tupleMemoryEnabled,
-                          final Object context) {
+        public EvalMemory(final Object context) {
             this.context = context;
-            if ( tupleMemoryEnabled ) {
-                this.tupleMemory = new LeftTupleList();
-            }
         }
 
         public void readExternal(ObjectInput in) throws IOException,
                                                 ClassNotFoundException {
-            tupleMemory = (LeftTupleList) in.readObject();
             context = in.readObject();
         }
 
         public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject( tupleMemory );
             out.writeObject( context );
         }
     }
 
+    /**
+     * Used with the updateSink method, so that the parent LeftTupleSource
+     * can  update the  TupleSink
+     */
+    private static class LeftTupleSinkUpdateAdapter
+        implements
+        LeftTupleSink {
+        private final EvalConditionNode node;
+        private final LeftTupleSink     sink;
+        private final EvalCondition     constraint;
+
+        public LeftTupleSinkUpdateAdapter(final EvalConditionNode node,
+                                          final LeftTupleSink sink,
+                                          final EvalCondition constraint) {
+            this.node = node;
+            this.sink = sink;
+            this.constraint = constraint;
+        }
+
+        public void assertLeftTuple(final LeftTuple leftTuple,
+                                    final PropagationContext context,
+                                    final InternalWorkingMemory workingMemory) {
+
+            final EvalMemory memory = (EvalMemory) workingMemory.getNodeMemory( node );
+
+            final boolean allowed = this.constraint.isAllowed( leftTuple,
+                                                               workingMemory,
+                                                               memory.context );
+
+            if ( allowed ) {
+                final LeftTuple tuple = new LeftTuple( leftTuple,
+                                                       this.sink,
+                                                       false );
+                this.sink.assertLeftTuple( tuple,
+                                           context,
+                                           workingMemory );
+            }
+        }
+
+        public short getType() {
+            return 0;
+        }
+
+        public boolean isLeftTupleMemoryEnabled() {
+            return false;
+        }
+
+        public void modifyLeftTuple(InternalFactHandle factHandle,
+                                    ModifyPreviousTuples modifyPreviousTuples,
+                                    PropagationContext context,
+                                    InternalWorkingMemory workingMemory) {
+            throw new UnsupportedOperationException( "LeftTupleSinkUpdateAdapter onlys supports assertLeftTuple method calls" );
+        }
+
+        public void modifyLeftTuple(LeftTuple leftTuple,
+                                    PropagationContext context,
+                                    InternalWorkingMemory workingMemory) {
+            throw new UnsupportedOperationException( "LeftTupleSinkUpdateAdapter onlys supports assertLeftTuple method calls" );
+        }
+
+        public void retractLeftTuple(LeftTuple leftTuple,
+                                     PropagationContext context,
+                                     InternalWorkingMemory workingMemory) {
+            throw new UnsupportedOperationException( "LeftTupleSinkUpdateAdapter onlys supports assertLeftTuple method calls" );
+        }
+
+        public void setLeftTupleMemoryEnabled(boolean tupleMemoryEnabled) {
+            throw new UnsupportedOperationException( "LeftTupleSinkUpdateAdapter onlys supports assertLeftTuple method calls" );
+        }
+
+        public void readExternal(ObjectInput arg0) throws IOException,
+                                                  ClassNotFoundException {
+        }
+
+        public void writeExternal(ObjectOutput arg0) throws IOException {
+        }
+
+        public int getId() {
+            return 0;
+        }
+
+        public RuleBasePartitionId getPartitionId() {
+            return sink.getPartitionId();
+        }
+
+    }
+
 }

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	2010-03-07 14:48:45 UTC (rev 31979)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/EvalConditionNodeTest.java	2010-03-07 16:20:06 UTC (rev 31980)
@@ -84,7 +84,7 @@
 
         final EvalMemory memory = (EvalMemory) workingMemory.getNodeMemory( node );
 
-        assertNotNull( memory.tupleMemory );
+        assertNotNull( memory );
     }
 
     /**
@@ -129,15 +129,6 @@
                               this.context,
                               this.workingMemory );
 
-        // Check memory was populated
-        final EvalMemory memory = (EvalMemory) this.workingMemory.getNodeMemory( node );
-
-        assertEquals( 2,
-                      memory.tupleMemory.size() );
-
-        assertTrue( memory.tupleMemory.contains( tuple0 ) );
-        assertTrue( memory.tupleMemory.contains( tuple1 ) );
-
         // make sure assertions were propagated
         assertEquals( 2,
                       sink.getAsserted().size() );
@@ -180,14 +171,6 @@
                               this.context,
                               this.workingMemory );
 
-        // Check memory was populated
-        final EvalMemory memory = (EvalMemory) this.workingMemory.getNodeMemory( node );
-
-        assertEquals( 2,
-                      memory.tupleMemory.size() );
-        assertTrue( memory.tupleMemory.contains( tuple0 ) );
-        assertTrue( memory.tupleMemory.contains( tuple1 ) );
-
         // make sure assertions were propagated
         assertEquals( 2,
                       sink.getAsserted().size() );
@@ -197,12 +180,6 @@
                                this.context,
                                this.workingMemory );
 
-        // Now test that the fact is retracted correctly
-        assertEquals( 1,
-                      memory.tupleMemory.size() );
-
-        assertTrue( memory.tupleMemory.contains( tuple1 ) );
-
         // make sure retractions were propagated
         assertEquals( 1,
                       sink.getRetracted().size() );
@@ -212,10 +189,6 @@
                                this.context,
                                this.workingMemory );
 
-        // Now test that the fact is retracted correctly
-        assertEquals( 0,
-                      memory.tupleMemory.size() );
-
         // make sure retractions were propagated
         assertEquals( 2,
                       sink.getRetracted().size() );
@@ -260,9 +233,6 @@
         // Check memory was not populated
         final EvalMemory memory = (EvalMemory) this.workingMemory.getNodeMemory( node );
 
-        assertEquals( 0,
-                      memory.tupleMemory.size() );
-
         // test no propagations
         assertEquals( 0,
                       sink.getAsserted().size() );
@@ -270,57 +240,6 @@
                       sink.getRetracted().size() );
     }
 
-    public void testUpdateWithMemory() throws FactException {
-        // 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( 1,
-                                                                           (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
-
-        // Creat the object source so we can detect the alphaNode telling it to
-        // propate its contents
-        //final MockTupleSource source = new MockTupleSource( 1 );
-
-        /* Create a test node that always returns true */
-        final EvalConditionNode node = new EvalConditionNode( 1,
-                                                              new MockTupleSource( 15 ),
-                                                              new MockEvalCondition( true ),
-                                                              buildContext );
-
-        // Add the first tuple sink and assert a tuple and object
-        // The sink has no memory
-        final MockLeftTupleSink sink1 = new MockLeftTupleSink( 2 );
-        node.addTupleSink( sink1 );
-
-        final DefaultFactHandle f0 = new DefaultFactHandle( 0,
-                                                            "string0" );
-
-        final LeftTuple tuple1 = new LeftTuple( f0,
-                                                sink1,
-                                                true );
-
-        node.assertLeftTuple( tuple1,
-                              this.context,
-                              workingMemory );
-
-        assertLength( 1,
-                      sink1.getAsserted() );
-
-        // Add the new sink, this should be updated from the re-processed
-        // joinnode memory
-        final MockLeftTupleSink sink2 = new MockLeftTupleSink( 3 );
-        node.addTupleSink( sink2 );
-        assertLength( 0,
-                      sink2.getAsserted() );
-
-        node.updateSink( sink2,
-                         this.context,
-                         workingMemory );
-
-        assertLength( 1,
-                      sink2.getAsserted() );
-    }
-
     /**
      * If a eval allows an incoming Object, then the Object MUST be
      * propagated. This tests that the memory is updated
@@ -363,14 +282,6 @@
                               this.context,
                               this.workingMemory );
 
-        // Check memory was populated
-        EvalMemory memory = (EvalMemory) this.workingMemory.getNodeMemory( node );
-
-        assertEquals( 1,
-                      memory.tupleMemory.size() );
-
-        assertTrue( memory.tupleMemory.contains( tuple0 ) );
-
         // make sure assertions were propagated
         assertEquals( 1,
                       sink.getAsserted().size() );
@@ -383,12 +294,5 @@
                      this.ruleBase.getReteooBuilder(),
                      sink,
                      workingMemories );
-
-        memory = (EvalMemory) this.workingMemory.getNodeMemory( node );
-
-        assertEquals( 0,
-                      memory.tupleMemory.size() );
-
-        assertFalse( memory.tupleMemory.contains( tuple0 ) );
     }
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java	2010-03-07 14:48:45 UTC (rev 31979)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java	2010-03-07 16:20:06 UTC (rev 31980)
@@ -52,6 +52,7 @@
 import org.drools.reteoo.test.dsl.CollectNodeStep;
 import org.drools.reteoo.test.dsl.DSLMock;
 import org.drools.reteoo.test.dsl.DslStep;
+import org.drools.reteoo.test.dsl.EvalNodeStep;
 import org.drools.reteoo.test.dsl.ExistsNodeStep;
 import org.drools.reteoo.test.dsl.FactsStep;
 import org.drools.reteoo.test.dsl.JoinNodeStep;
@@ -92,6 +93,7 @@
     private static final String COLLECT_NODE             = "CollectNode";
     private static final String ACCUMULATE_NODE          = "AccumulateNode";
     private static final String RULE_TERMINAL_NODE       = "RuleTerminalNode";
+    private static final String EVAL_NODE                = "EvalNode";
     private static final String WITH                     = "With";
     private static final String FACTS                    = "Facts";
     private static final String RIGHT_INPUT_ADAPTER_NODE = "RightInputAdapterNode";
@@ -125,6 +127,8 @@
                         new AccumulateNodeStep( this.reteTesterHelper ) );
         this.steps.put( RULE_TERMINAL_NODE,
                         new RuleTerminalNodeStep( this.reteTesterHelper ) );
+        this.steps.put( EVAL_NODE,
+                        new EvalNodeStep( this.reteTesterHelper ) );
         this.steps.put( RIGHT_INPUT_ADAPTER_NODE,
                         new RIANodeStep( this.reteTesterHelper ) );
         this.steps.put( FACTS,

Added: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/EvalNodeStep.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/EvalNodeStep.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/EvalNodeStep.java	2010-03-07 16:20:06 UTC (rev 31980)
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2008 Red Hat
+ * 
+ * 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.
+ *
+ */
+package org.drools.reteoo.test.dsl;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.WorkingMemory;
+import org.drools.reteoo.EvalConditionNode;
+import org.drools.reteoo.LeftTuple;
+import org.drools.reteoo.LeftTupleSource;
+import org.drools.reteoo.builder.BuildContext;
+import org.drools.rule.Declaration;
+import org.drools.rule.EvalCondition;
+import org.drools.spi.EvalExpression;
+import org.drools.spi.Tuple;
+import org.mockito.Mockito;
+import org.mvel2.MVEL;
+import org.mvel2.ParserContext;
+
+public class EvalNodeStep
+    implements
+    Step {
+
+    public EvalNodeStep(ReteTesterHelper reteTesterHelper) {
+    }
+
+    public void execute(Map<String, Object> context,
+                        List<String[]> args) {
+        BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
+        String name;
+        String source;
+        String expr;
+
+        if ( args.size() == 1 ) {
+            String[] c = args.get( 0 );
+            if ( c.length != 3 ) {
+                throw new IllegalArgumentException( "Cannot execute arguments " + Arrays.toString( c ) );
+            }
+            name = c[0].trim();
+            source = c[1].trim();
+            expr = c[2].trim();
+        } else {
+            throw new IllegalArgumentException( "Cannot execute arguments " + args );
+        }
+        LeftTupleSource pnode = null;
+        if ( source.equals( "mock" ) ) {
+            pnode = Mockito.mock( LeftTupleSource.class );
+        } else {
+            pnode = (LeftTupleSource) context.get( source );
+        }
+
+        EvalCondition eval = new EvalCondition( new InstrumentedEvalExpression( expr,
+                                                                                context ),
+                                                new Declaration[0] );
+        EvalConditionNode evalNode = new EvalConditionNode( buildContext.getNextId(),
+                                                            pnode,
+                                                            eval,
+                                                            buildContext );
+        evalNode.attach();
+        context.put( name,
+                     evalNode );
+    }
+
+    public static class InstrumentedEvalExpression
+        implements
+        EvalExpression {
+        private String              expr;
+        private Map<String, Object> context;
+
+        public InstrumentedEvalExpression(String expr,
+                                          Map<String, Object> context) {
+            super();
+            this.expr = expr.replaceAll( "h(\\d+)",
+                                         "Handles[$1]" );
+            this.context = context;
+        }
+
+        public Object createContext() {
+            return null;
+        }
+
+        public boolean evaluate(Tuple tuple,
+                                Declaration[] requiredDeclarations,
+                                WorkingMemory workingMemory,
+                                Object ctx) throws Exception {
+            // create a map with all captured tuples as variables
+            Map<String, Object> vars = new HashMap<String, Object>();
+            // add all context variables, just in case
+            vars.putAll( this.context );
+            vars.put( "tuple",
+                      ((LeftTuple)tuple).toFactHandles() );
+
+            // compile MVEL expression
+            ParserContext mvelctx = new ParserContext();
+            Serializable compiled = MVEL.compileExpression( this.expr,
+                                                            mvelctx );
+            // execute the expression
+            Boolean result = (Boolean) MVEL.executeExpression( compiled,
+                                                               vars );
+            return result.booleanValue();
+        }
+
+    }
+}
\ No newline at end of file


Property changes on: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/EvalNodeStep.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/EvalNodeTest.nodeTestCase
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/EvalNodeTest.nodeTestCase	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/EvalNodeTest.nodeTestCase	2010-03-07 16:20:06 UTC (rev 31980)
@@ -0,0 +1,88 @@
+TestCase "Eval Node test case"
+
+import org.drools.Cheese;
+import org.drools.Person;
+
+Setup
+	EvalNode:
+	    eval, mock, tuple[0].object.age > 30;
+	LeftTupleSink:
+	    sink, eval;
+	Facts:
+	    new Person('darth', 35, 'brie'),     // h0     
+	    new Person('bobba', 22, 'stilton'),  // h1
+	    new Person('yoda', 832, 'stilton'),  // h2
+	    new Person('luke', 27, 'stilton');   // h3
+	
+/**
+ * check single left assertion and retraction
+ */
+Test "Eval assert/retract"	
+	assert:
+	    eval, [[h1]];
+	sink:
+	    verify, assertLeft, count, 0;
+	assert:
+	    eval, [[h0]];
+	sink:
+	    verify, assertLeft, count, 1;
+	    verify, assertLeft, tuple0[0], is( h0 );
+	retract:
+	    eval, [[h0], [h1]];   
+	sink:
+	    verify, assertLeft, count, 1;   // still 1
+	    verify, retractLeft, count, 1;
+	    
+/**    
+ * check single right assertion and retraction
+ */
+Test "Eval assert, modify, retract"
+	assert:
+	    eval, [[h0], [h1], [h2]];
+	sink:
+	    verify, assertLeft, count, 2;
+	    verify, assertLeft, tuple0[0], is( h0 );  
+	    verify, assertLeft, tuple1[0], is( h2 );
+	modify:
+		eval, [[h0]];
+	sink:
+	    verify, assertLeft, count, 2; // still 2
+	    verify, retractLeft, count, 0; 
+	    verify, modifyLeft, count, 1;
+	    verify, modifyLeft, tuple0[0], is( h0 );
+	With:
+	    h0, age = 25;
+	modify:
+	    eval, [[h0]];
+	sink:
+	    verify, assertLeft, count, 2; // still 2
+	    verify, retractLeft, count, 1; 
+	    verify, retractLeft, tuple0[0], is( h0 );
+	    verify, modifyLeft, count, 1;
+	With:
+	    h1, age = 35;
+	modify:
+	    eval, [[h1]];
+	sink:
+	    verify, assertLeft, count, 3; // still 2
+	    verify, assertLeft, tuple2[0], is( h1 );
+	    verify, retractLeft, count, 1; 
+	    verify, modifyLeft, count, 1;
+	With:
+	    h2, age = 833;
+	modify:
+	    eval, [[h2]];
+	sink:
+	    verify, assertLeft, count, 3; // still 2
+	    verify, retractLeft, count, 1; 
+	    verify, modifyLeft, count, 2;
+	    verify, modifyLeft, tuple1[0], is( h2 );
+	retract:
+		eval, [[h1], [h2], [h0]];
+	sink:
+	    verify, assertLeft, count, 3; // still 2
+	    verify, retractLeft, count, 3; 
+	    verify, modifyLeft, count, 2;
+
+	 
+	    
\ No newline at end of file


Property changes on: labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/EvalNodeTest.nodeTestCase
___________________________________________________________________
Name: svn:executable
   + *



More information about the jboss-svn-commits mailing list