[jboss-svn-commits] JBL Code SVN: r5997 - in labs/jbossrules/branches/3.0.x: drools-compiler/src/test/java/org/drools drools-compiler/src/test/java/org/drools/integrationtests drools-compiler/src/test/resources/org/drools/integrationtests drools-core/src/main/java/org/drools/reteoo drools-core/src/main/java/org/drools/reteoo/beta

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Aug 29 08:26:52 EDT 2006


Author: tirelli
Date: 2006-08-29 08:26:37 -0400 (Tue, 29 Aug 2006)
New Revision: 5997

Added:
   labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Approach.java
   labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Close.java
   labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Target.java
   labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_JoinNodeModifyTuple.drl
Modified:
   labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
   labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
   labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/beta/DefaultRightMemory.java
Log:
JBRULES-455:

  * Fixing JoinNode.modifyTuple bug
  * Adding integration test for it



Added: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Approach.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Approach.java	2006-08-29 00:48:55 UTC (rev 5996)
+++ labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Approach.java	2006-08-29 12:26:37 UTC (rev 5997)
@@ -0,0 +1,65 @@
+package org.drools;
+
+public class Approach {
+
+	public String label;
+	public String label2;
+	public Float time;
+	public Float time2;
+	public Float distance;
+	public Float distance2;
+	public Float bearing;
+	public Float bearing2;
+
+	public Float getDistance2() {
+		return distance2;
+	}
+	public void setDistance2(Float distance2) {
+		this.distance2 = distance2;
+	}
+	public Float getTime2() {
+		return time2;
+	}
+	public void setTime2(Float time2) {
+		this.time2 = time2;
+	}
+	public Float getBearing() {
+		return bearing;
+	}
+	public void setBearing(Float bearing) {
+		this.bearing = bearing;
+	}
+	public Float getDistance() {
+		return distance;
+	}
+	public void setDistance(Float distance) {
+		this.distance = distance;
+	}
+	public String getLabel() {
+		return label;
+	}
+	public void setLabel(String label) {
+		this.label = label;
+	}
+	public String getLabel2() {
+		return label2;
+	}
+	public void setLabel2(String label2) {
+		this.label2 = label2;
+	}
+	public Float getTime() {
+		return time;
+	}
+	public void setTime(Float time) {
+		this.time = time;
+	}
+	public Float getBearing2() {
+		return bearing2;
+	}
+	public void setBearing2(Float bearing2) {
+		this.bearing2 = bearing2;
+	}
+	public String toString(){
+		return "Approach< label: "+label+" label2: "+label2+" time: "+time+" time2: "+time2+" distance: "+distance+" distance2: "+distance2+" bearing: "+bearing+" bearing2: "+bearing2+" >";
+	}
+}


Property changes on: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Approach.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + id author date revision
Name: svn:eol-style
   + native

Added: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Close.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Close.java	2006-08-29 00:48:55 UTC (rev 5996)
+++ labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Close.java	2006-08-29 12:26:37 UTC (rev 5997)
@@ -0,0 +1,44 @@
+package org.drools;
+
+public class Close {
+
+	public String label;
+	public String label2;
+	public Float time;
+	public Float distance;
+	public Float bearing;
+
+	public Float getBearing() {
+		return bearing;
+	}
+	public void setBearing(Float bearing) {
+		this.bearing = bearing;
+	}
+	public Float getDistance() {
+		return distance;
+	}
+	public void setDistance(Float distance) {
+		this.distance = distance;
+	}
+	public String getLabel() {
+		return label;
+	}
+	public void setLabel(String label) {
+		this.label = label;
+	}
+	public String getLabel2() {
+		return label2;
+	}
+	public void setLabel2(String label2) {
+		this.label2 = label2;
+	}
+	public Float getTime() {
+		return time;
+	}
+	public void setTime(Float time) {
+		this.time = time;
+	}
+	public String toString(){
+		return "Close< label: "+label+" label2: "+label2+" time: "+time+" distance: "+distance+" bearing: "+bearing+">";
+	}
+}


Property changes on: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Close.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + id author date revision
Name: svn:eol-style
   + native

Added: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Target.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Target.java	2006-08-29 00:48:55 UTC (rev 5996)
+++ labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Target.java	2006-08-29 12:26:37 UTC (rev 5997)
@@ -0,0 +1,51 @@
+package org.drools;
+
+public class Target {
+
+	public String label;
+	public Float lat;
+	public Float lon;
+	public Float course;
+	public Float speed;
+	public Float time;
+	
+	public Float getCourse() {
+		return course;
+	}
+	public void setCourse(Float course) {
+		this.course = course;
+	}
+	public String getLabel() {
+		return label;
+	}
+	public void setLabel(String label) {
+		this.label = label;
+	}
+	public Float getLat() {
+		return lat;
+	}
+	public void setLat(Float lat) {
+		this.lat = lat;
+	}
+	public Float getLon() {
+		return lon;
+	}
+	public void setLon(Float lon) {
+		this.lon = lon;
+	}
+	public Float getSpeed() {
+		return speed;
+	}
+	public void setSpeed(Float speed) {
+		this.speed = speed;
+	}
+	public Float getTime() {
+		return time;
+	}
+	public void setTime(Float time) {
+		this.time = time;
+	}
+	public String toString(){
+		return "Target< label: "+label+" lat: "+lat+" lon: "+lon+" course: "+course+" speed: "+speed+" time: "+time+">";
+	}
+}


Property changes on: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/Target.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + id author date revision
Name: svn:eol-style
   + native

Modified: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java	2006-08-29 00:48:55 UTC (rev 5996)
+++ labs/jbossrules/branches/3.0.x/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java	2006-08-29 12:26:37 UTC (rev 5997)
@@ -2725,8 +2725,116 @@
         cheeseList = workingMemory.getObjects( String.class );
         assertEquals( 2,
                       cheeseList.size() );
+    }
+    
+    public void testLLR() throws Exception {
+
+        //read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_JoinNodeModifyTuple.drl" ) );
+        final DrlParser parser = new DrlParser();
+        final PackageDescr packageDescr = parser.parse( reader );
+
+        //pre build the package
+        final PackageBuilder builder = new PackageBuilder();
+        builder.addPackage( packageDescr );
+        final Package pkg = builder.getPackage();
+
+        //add the package to a rulebase
+        final RuleBase ruleBase = getRuleBase();
+        ruleBase.addPackage( pkg );
+        //load up the rulebase
+
+        final WorkingMemory wm = ruleBase.newWorkingMemory();
         
+        try {
+            // 1st time           
+            org.drools.Target tgt = new org.drools.Target();
+            tgt.setLabel( "Santa-Anna" );
+            tgt.setLat( new Float( 60.26544f ) );
+            tgt.setLon( new Float( 28.952137f ) );
+            tgt.setCourse( new Float( 145.0f ) );
+            tgt.setSpeed( new Float( 12.0f ) );
+            tgt.setTime( new Float( 1.8666667f ) );
+            wm.assertObject( tgt );
+            
+            tgt = new org.drools.Target();
+            tgt.setLabel( "Santa-Maria" );
+            tgt.setLat( new Float( 60.236874f ) );
+            tgt.setLon( new Float( 28.992579f ) );
+            tgt.setCourse( new Float( 325.0f ) );
+            tgt.setSpeed( new Float( 8.0f ) );
+            tgt.setTime( new Float( 1.8666667f ) );
+            wm.assertObject( tgt );
+            
+            wm.fireAllRules();
+
+            // 2nd time
+            tgt = new org.drools.Target();
+            tgt.setLabel( "Santa-Anna" );
+            tgt.setLat( new Float( 60.265343f ) );
+            tgt.setLon( new Float( 28.952267f ) );
+            tgt.setCourse( new Float( 145.0f ) );
+            tgt.setSpeed( new Float( 12.0f ) );
+            tgt.setTime( new Float( 1.9f ) );
+            wm.assertObject( tgt );
+            
+            tgt = new org.drools.Target();
+            tgt.setLabel( "Santa-Maria" );
+            tgt.setLat( new Float( 60.236935f ) );
+            tgt.setLon( new Float( 28.992493f ) );
+            tgt.setCourse( new Float( 325.0f ) );
+            tgt.setSpeed( new Float( 8.0f ) );
+            tgt.setTime( new Float( 1.9f ) );
+            wm.assertObject( tgt );
+            
+            wm.fireAllRules();
+
+            // 3d time
+            tgt = new org.drools.Target();
+            tgt.setLabel( "Santa-Anna" );
+            tgt.setLat( new Float( 60.26525f ) );
+            tgt.setLon( new Float( 28.952396f ) );
+            tgt.setCourse( new Float( 145.0f ) );
+            tgt.setSpeed( new Float( 12.0f ) );
+            tgt.setTime( new Float( 1.9333333f ) );
+            wm.assertObject( tgt );
+            
+            tgt = new org.drools.Target();
+            tgt.setLabel( "Santa-Maria" );
+            tgt.setLat( new Float( 60.236996f ) );
+            tgt.setLon( new Float( 28.992405f ) );
+            tgt.setCourse( new Float( 325.0f ) );
+            tgt.setSpeed( new Float( 8.0f ) );
+            tgt.setTime( new Float( 1.9333333f ) );
+            wm.assertObject( tgt );
+            
+            wm.fireAllRules();
+
+            // 4th time
+            tgt = new org.drools.Target();
+            tgt.setLabel( "Santa-Anna" );
+            tgt.setLat( new Float( 60.265163f ) );
+            tgt.setLon( new Float( 28.952526f ) );
+            tgt.setCourse( new Float( 145.0f ) );
+            tgt.setSpeed( new Float( 12.0f ) );
+            tgt.setTime( new Float( 1.9666667f ) );
+            wm.assertObject( tgt );
+            
+            tgt = new org.drools.Target();
+            tgt.setLabel( "Santa-Maria" );
+            tgt.setLat( new Float( 60.237057f ) );
+            tgt.setLon( new Float( 28.99232f ) );
+            tgt.setCourse( new Float( 325.0f ) );
+            tgt.setSpeed( new Float( 8.0f ) );
+            tgt.setTime( new Float( 1.9666667f ) );
+            wm.assertObject( tgt );
+            
+            wm.fireAllRules();
+        } catch ( RuntimeException e ) {
+            Assert.fail("Test is not supposed to throw any exception");
+        }
         
     }
+    
 
 }

Added: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_JoinNodeModifyTuple.drl
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_JoinNodeModifyTuple.drl	2006-08-29 00:48:55 UTC (rev 5996)
+++ labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_JoinNodeModifyTuple.drl	2006-08-29 12:26:37 UTC (rev 5997)
@@ -0,0 +1,83 @@
+package TrafficControl
+
+import org.drools.*
+
+rule "Target Retract"
+	salience -100
+	when
+      $tgt1 : Target( $label1 : label, $time : time )
+      Target( label == $label1, time > $time )
+	then
+      retract( $tgt1 );
+end
+
+rule "Close Assert"
+	when
+      Target( $label : label, $time : time, $lat : lat, $lon : lon )
+      Target( $label2 : label, time == $time, $lat2 : lat, $lon2 : lon )
+      eval( $label.compareTo( $label2 ) < 0 )
+	then
+      float s1 =  $lat.floatValue() - $lat2.floatValue();
+      float s2 =  $lon.floatValue() - $lon2.floatValue();
+      double distance = Math.sqrt( s1*s1 + s2*s2 );
+      if ( distance < 8.0 )
+      {
+        Close cl = new Close();
+        cl.label = $label;
+        cl.label2 = $label2;
+        cl.time = $time;
+        cl.distance = new Float( distance );
+        cl.bearing = new Float( 144.9 );
+        assert( cl );
+      }
+end
+
+rule "Close Retract"
+	salience -100
+	when
+      $cls : Close( $label : label, $label2 : label2, $time : time )
+      Close( label == $label, label2 == $label2, time > $time )
+	then
+      retract( $cls );
+end
+
+rule "Approach Begin"
+	when
+      $cls1 : Close( $label : label, $label2 : label2, $time : time, $distance : distance, $bearing : bearing )
+      not Approach( label == $label, label2 == $label2 )
+      $cls2 : Close( label == $label, label2 == $label2, $time2 : time > $time, $distance2 : distance < $distance, $bearing2 : bearing )
+	then
+      Approach a = new Approach();
+      a.label = $label;
+      a.label2 = $label2;
+      a.distance = $distance;
+      a.distance2 = $distance2;
+      a.time = $time;
+      a.time2 = $time2;
+      a.bearing = $bearing;
+      a.bearing2 = $bearing2;
+      assert( a );
+      retract( $cls1 );
+end
+
+rule "Approach Continue"
+	no-loop true
+	when
+      $app : Approach( $label : label, $label2 : label2, $time2 : time2, $distance2 : distance2 )
+      Close( label == $label, label2 == $label2, $time3 : time > $time2, $distance3 : distance <=  $distance2, $bearing3 : bearing )
+	then
+      $app.distance2 = $distance3;
+      $app.bearing2 = $bearing3;
+      $app.time2 = $time3;
+      modify( $app );
+end
+
+rule "Danger Distance Warning"
+	when
+      Approach( $label : label, $label2 : label2, $distance2 : distance2, $time2 : time2, $bearing2 : bearing2 )
+      Target( label == $label, time == $time2, $speed : speed, $course : course )
+      eval( $distance2.floatValue() <= 5.2 )
+	then
+      //System.out.println( "Danger Distance Warning "+$label+" "+$label2+" distance: "+$distance2 );
+end
+


Property changes on: labs/jbossrules/branches/3.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_JoinNodeModifyTuple.drl
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Modified: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/JoinNode.java	2006-08-29 00:48:55 UTC (rev 5996)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/JoinNode.java	2006-08-29 12:26:37 UTC (rev 5997)
@@ -109,7 +109,7 @@
                             final PropagationContext context,
                             final ReteooWorkingMemory workingMemory) {
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
-
+        
         memory.add( workingMemory,
                     leftTuple );
 
@@ -193,7 +193,7 @@
                               final PropagationContext context,
                               final ReteooWorkingMemory workingMemory) {
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
-
+        
         // Remove the FactHandle from memory
         final ObjectMatches objectMatches = memory.remove( workingMemory,
                                                            handle );
@@ -263,6 +263,7 @@
             // indexing is enabled, the loop over right objects may skip some of the
             // previously matched objects
             final Map oldMatches = new HashMap(matches);
+            leftTuple.getTupleMatches().clear();
             
             // ensure the tuple is at the top of the memory
             memory.add( workingMemory,
@@ -282,6 +283,7 @@
                         // ensures tupleMatch will be in the appropriate order
                         objectMatches.remove( tupleMatch );
                         objectMatches.add( tupleMatch );
+                        leftTuple.addTupleMatch( handle, tupleMatch );
                         
                         propagateModifyTuple( tupleMatch,
                                               context,
@@ -316,6 +318,9 @@
                 for(Iterator it = oldMatches.values().iterator(); it.hasNext(); ) {
                     final TupleMatch tupleMatch = (TupleMatch) it.next();
                     tupleMatch.getObjectMatches().remove( tupleMatch );
+                    propagateRetractTuple( tupleMatch,
+                                           context,
+                                           workingMemory );
                 }
             }
         }

Modified: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/beta/DefaultRightMemory.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/beta/DefaultRightMemory.java	2006-08-29 00:48:55 UTC (rev 5996)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/beta/DefaultRightMemory.java	2006-08-29 12:26:37 UTC (rev 5997)
@@ -64,6 +64,7 @@
     public final void remove(final WorkingMemory workingMemory,
                              final ObjectMatches matches) {
         matches.getOuterList().remove( matches );
+        matches.setOuterList( null );
     }
 
     /**
@@ -86,6 +87,7 @@
     public final void remove(final WorkingMemory workingMemory,
                              final MultiLinkedListNodeWrapper wrapper) {
         wrapper.getOuterList().remove( wrapper );
+        wrapper.setOuterList( null );
     }
 
     /**




More information about the jboss-svn-commits mailing list