[jboss-svn-commits] JBL Code SVN: r36987 - in labs/jbossrules/soa_branches/BRMS-5.1.x: drools-compiler/src/test/resources/org/drools/integrationtests and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon May 9 13:06:38 EDT 2011


Author: tsurdilovic
Date: 2011-05-09 13:06:37 -0400 (Mon, 09 May 2011)
New Revision: 36987

Added:
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_TemporalOperators2.drl
Modified:
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/common/DefaultAgenda.java
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/bulk-importer-util/guvnor-importer/.classpath
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/bulk-importer-util/sample-model/.classpath
Log:
BRMS-582: When using fusion's 'after' or 'before' operator the ConsequenceException (caused by NPE) is thrown.

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java	2011-05-06 20:55:47 UTC (rev 36986)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java	2011-05-09 17:06:37 UTC (rev 36987)
@@ -68,6 +68,7 @@
 import org.drools.runtime.rule.FactHandle;
 import org.drools.runtime.rule.WorkingMemoryEntryPoint;
 import org.drools.spi.ObjectType;
+import org.drools.time.SessionClock;
 import org.drools.time.SessionPseudoClock;
 import org.drools.time.impl.DurationTimer;
 import org.drools.time.impl.PseudoClockScheduler;
@@ -80,21 +81,21 @@
                                             null );
     }
 
-    protected RuleBase getRuleBase(final RuleBaseConfiguration config) throws Exception {
+    protected RuleBase getRuleBase( final RuleBaseConfiguration config ) throws Exception {
 
         return RuleBaseFactory.newRuleBase( RuleBase.RETEOO,
                                             config );
     }
 
-    private RuleBase loadRuleBase(final Reader reader) throws IOException,
+    private RuleBase loadRuleBase( final Reader reader ) throws IOException,
                                                       DroolsParserException,
                                                       Exception {
         return loadRuleBase( reader,
                              null );
     }
 
-    private RuleBase loadRuleBase(final Reader reader,
-                                  final RuleBaseConfiguration conf) throws IOException,
+    private RuleBase loadRuleBase( final Reader reader,
+                                  final RuleBaseConfiguration conf ) throws IOException,
                                                                    DroolsParserException,
                                                                    Exception {
         final PackageBuilder builder = new PackageBuilder();
@@ -116,8 +117,8 @@
         return ruleBase;
     }
 
-    private KnowledgeBase loadKnowledgeBase(final Reader reader,
-                                            final KnowledgeBaseConfiguration conf) throws IOException,
+    private KnowledgeBase loadKnowledgeBase( final Reader reader,
+                                             final KnowledgeBaseConfiguration conf ) throws IOException,
                                                                                   ClassNotFoundException {
         final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
         kbuilder.add( ResourceFactory.newReaderResource( reader ),
@@ -132,9 +133,9 @@
         return kbase;
     }
 
-    private KnowledgeBase loadKnowledgeBase(final String resource,
-                                            final KnowledgeBaseConfiguration conf,
-                                            final boolean serialize) throws IOException,
+    private KnowledgeBase loadKnowledgeBase( final String resource,
+                                             final KnowledgeBaseConfiguration conf,
+                                             final boolean serialize ) throws IOException,
                                                                     ClassNotFoundException {
         final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
         kbuilder.add( ResourceFactory.newClassPathResource( resource,
@@ -1920,5 +1921,48 @@
         assertTrue( handle3.isEvent() );
         assertTrue( handle4.isEvent() );
     }
+    
+    public void testTemporalOperators2() throws Exception {
+        // read in the source
+        final RuleBaseConfiguration kbconf = new RuleBaseConfiguration();
+        kbconf.setEventProcessingMode( EventProcessingOption.STREAM );
+        KnowledgeBase kbase = loadKnowledgeBase( "test_CEP_TemporalOperators2.drl",
+                                                 kbconf,
+                                                 true );
 
+        KnowledgeSessionConfiguration sconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
+        sconf.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) );
+
+        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession( sconf,
+                                                                               null );
+        SessionPseudoClock clock = ksession.getSessionClock();
+
+        WorkingMemoryEntryPoint ep = ksession.getWorkingMemoryEntryPoint( "X" );
+
+        clock.advanceTime( 1000,
+                           TimeUnit.SECONDS );
+        ep.insert( new StockTick( 1,
+                                  "A",
+                                  10,
+                                  clock.getCurrentTime() ) );
+        clock.advanceTime( 8,
+                           TimeUnit.SECONDS );
+        ep.insert( new StockTick( 2,
+                                  "B",
+                                  10,
+                                  clock.getCurrentTime() ) );
+        clock.advanceTime( 8,
+                           TimeUnit.SECONDS );
+        ep.insert( new StockTick( 3,
+                                  "B",
+                                  10,
+                                  clock.getCurrentTime() ) );
+        clock.advanceTime( 8,
+                           TimeUnit.SECONDS );
+        int rules = ksession.fireAllRules();
+        assertEquals( 2,
+                      rules );
+    }
+
+
 }

Added: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_TemporalOperators2.drl
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_TemporalOperators2.drl	                        (rev 0)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_TemporalOperators2.drl	2011-05-09 17:06:37 UTC (rev 36987)
@@ -0,0 +1,15 @@
+package org.drools;
+
+declare StockTick 
+    @role( event )
+end
+
+rule "2 operators"
+when
+    $a : StockTick( ) from entry-point "X"
+    $b : StockTick( this after[1s,10s] $a ) from entry-point "X"
+then
+    System.out.println( $a );
+    System.out.println( $b );
+end
+

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/common/DefaultAgenda.java
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/common/DefaultAgenda.java	2011-05-06 20:55:47 UTC (rev 36986)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/common/DefaultAgenda.java	2011-05-09 17:06:37 UTC (rev 36987)
@@ -924,33 +924,32 @@
                                                                             this.workingMemory,
                                                                             e );
                 } else if ( this.consequenceExceptionHandler != null ) {
-                    this.consequenceExceptionHandler.handleException( activation,
-                                                                      new StatefulKnowledgeSessionImpl( (ReteooWorkingMemory) this.workingMemory ),
+                    this.consequenceExceptionHandler.handleException( activation, this.workingMemory.getKnowledgeRuntime(),
                                                                       e );
                 } else {
                     throw new RuntimeException( e );
                 }
-            }
-            
-            if( ruleFlowGroup != null ) {
-                ruleFlowGroup.deactivateIfEmpty();
-            }
-
-            // if the tuple contains expired events 
-            for ( LeftTuple tuple = (LeftTuple) activation.getTuple(); tuple != null; tuple = tuple.getParent() ) {
-                if ( tuple.getLastHandle().isEvent() ) {
-                    EventFactHandle handle = (EventFactHandle) tuple.getLastHandle();
-                    // handles "expire" only in stream mode.
-                    if ( handle.isExpired() ) {
+            } finally {
+                // if the tuple contains expired events 
+                for ( LeftTuple tuple = (LeftTuple) activation.getTuple(); tuple != null; tuple = tuple.getParent() ) {
+                    if ( tuple.getLastHandle().isEvent() ) {
+                        EventFactHandle handle = (EventFactHandle) tuple.getLastHandle();
                         // decrease the activation count for the event
                         handle.decreaseActivationsCount();
-                        if ( handle.getActivationsCount() == 0 ) {
-                            // and if no more activations, retract the handle
-                            handle.getEntryPoint().retract( handle );
+                        // handles "expire" only in stream mode.
+                        if ( handle.isExpired() ) {
+                            if ( handle.getActivationsCount() <= 0 ) {
+                                // and if no more activations, retract the handle
+                                handle.getEntryPoint().retract( handle );
+                            }
                         }
                     }
                 }
             }
+            
+            if( ruleFlowGroup != null ) {
+                ruleFlowGroup.deactivateIfEmpty();
+            }
 
             eventsupport.getAgendaEventSupport().fireAfterActivationFired( activation,
                                                                            this.workingMemory );

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java	2011-05-06 20:55:47 UTC (rev 36986)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java	2011-05-09 17:06:37 UTC (rev 36987)
@@ -19,6 +19,7 @@
 import java.util.Arrays;
 
 import org.drools.common.AgendaItem;
+import org.drools.common.EventFactHandle;
 import org.drools.common.InternalFactHandle;
 import org.drools.core.util.Entry;
 import org.drools.core.util.LeftTupleList;
@@ -630,4 +631,21 @@
         return  builder.toString();
     }
     
+    public void increaseActivationCountForEvents() {
+        for ( LeftTuple entry = this; entry != null; entry = entry.getParent() ) {
+            if( entry.getLastHandle().isEvent() ) {
+                ((EventFactHandle)entry.getLastHandle()).increaseActivationsCount();
+            }
+        }
+    }
+    
+    public void decreaseActivationCountForEvents() {
+        for ( LeftTuple entry = this; entry != null; entry = entry.getParent() ) {
+            if( entry.getLastHandle().isEvent() ) {
+                ((EventFactHandle)entry.getLastHandle()).decreaseActivationsCount();
+            }
+        }
+    }
+
+    
 }

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java	2011-05-06 20:55:47 UTC (rev 36986)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java	2011-05-09 17:06:37 UTC (rev 36987)
@@ -187,6 +187,7 @@
             tuple.setObject( item );
 
             item.setActivated( true );
+            tuple.increaseActivationCountForEvents();
             ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
                                                                                           workingMemory );
         } else {
@@ -217,6 +218,7 @@
 
             if ( added ) {
                 item.setActivated( true );
+                tuple.increaseActivationCountForEvents();
                 ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
                                                                                               workingMemory );
             }
@@ -238,8 +240,6 @@
         if ( activation.isActivated() ) {
             // on fact expiration, we don't remove the activation, but let it fire
             if ( context.getType() == PropagationContext.EXPIRATION && context.getFactHandleOrigin() != null ) {
-                EventFactHandle efh = (EventFactHandle) context.getFactHandleOrigin();
-                efh.increaseActivationsCount();
             } else {
                 activation.remove();
 
@@ -251,7 +251,8 @@
                     final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) activation.getActivationNode().getParentContainer();
                     ruleFlowGroup.removeActivation( activation );
                 }
-
+                leftTuple.decreaseActivationCountForEvents();
+                
                 ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCancelled( activation,
                                                                                                 workingMemory,
                                                                                                 ActivationCancelledCause.WME_MODIFY );
@@ -322,6 +323,7 @@
             }
             agenda.scheduleItem( (ScheduledAgendaItem) item,
                                  workingMemory );
+            leftTuple.increaseActivationCountForEvents();
             item.setActivated( true );
             //            workingMemory.removeLogicalDependencies( item,
             //                                                     context,
@@ -363,6 +365,7 @@
             item.setActivated( added );
 
             if ( added ) {
+            	leftTuple.increaseActivationCountForEvents();
                 ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
                                                                                               workingMemory );
             }

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/bulk-importer-util/guvnor-importer/.classpath
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/bulk-importer-util/guvnor-importer/.classpath	2011-05-06 20:55:47 UTC (rev 36986)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/bulk-importer-util/guvnor-importer/.classpath	2011-05-09 17:06:37 UTC (rev 36987)
@@ -1,9 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
-	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
-	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
-	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
 	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
 	<classpathentry kind="output" path="target/classes"/>

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/bulk-importer-util/sample-model/.classpath
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/bulk-importer-util/sample-model/.classpath	2011-05-06 20:55:47 UTC (rev 36986)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/bulk-importer-util/sample-model/.classpath	2011-05-09 17:06:37 UTC (rev 36987)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
 	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
 	<classpathentry kind="output" path="target/classes"/>



More information about the jboss-svn-commits mailing list