[jboss-svn-commits] JBL Code SVN: r33965 - in labs/jbossrules/trunk: drools-compiler/src/test/java/org/drools/integrationtests and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jul 16 20:11:57 EDT 2010
Author: tirelli
Date: 2010-07-16 20:11:56 -0400 (Fri, 16 Jul 2010)
New Revision: 33965
Added:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/StockTickInterface.java
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_EventInterfaces.drl
Modified:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/StockTick.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StreamsTest.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
Log:
JBRULES-2580: fixing NPE when declaring interfaces as events
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/StockTick.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/StockTick.java 2010-07-16 21:56:37 UTC (rev 33964)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/StockTick.java 2010-07-17 00:11:56 UTC (rev 33965)
@@ -3,7 +3,7 @@
import java.io.Serializable;
import java.util.Date;
-public class StockTick implements Serializable {
+public class StockTick implements Serializable, StockTickInterface {
private static final long serialVersionUID = -1702366432018395425L;
private long seq;
@@ -39,27 +39,51 @@
this.duration = duration;
}
+ /* (non-Javadoc)
+ * @see org.drools.StockTickInterface#getCompany()
+ */
public String getCompany() {
return company;
}
+ /* (non-Javadoc)
+ * @see org.drools.StockTickInterface#setCompany(java.lang.String)
+ */
public void setCompany(String company) {
this.company = company;
}
+ /* (non-Javadoc)
+ * @see org.drools.StockTickInterface#getPrice()
+ */
public double getPrice() {
return price;
}
+ /* (non-Javadoc)
+ * @see org.drools.StockTickInterface#setPrice(double)
+ */
public void setPrice(double price) {
this.price = price;
}
+ /* (non-Javadoc)
+ * @see org.drools.StockTickInterface#getSeq()
+ */
public long getSeq() {
return seq;
}
+ /* (non-Javadoc)
+ * @see org.drools.StockTickInterface#setSeq(long)
+ */
public void setSeq(long seq) {
this.seq = seq;
}
+ /* (non-Javadoc)
+ * @see org.drools.StockTickInterface#getTime()
+ */
public long getTime() {
return time;
}
+ /* (non-Javadoc)
+ * @see org.drools.StockTickInterface#setTime(long)
+ */
public void setTime(long time) {
this.time = time;
}
@@ -68,20 +92,23 @@
return "StockTick( "+this.seq+" : " +this.company +" : "+ this.price +" )";
}
- /**
- * @return the duration
+ /* (non-Javadoc)
+ * @see org.drools.StockTickInterface#getDuration()
*/
public long getDuration() {
return duration;
}
- /**
- * @param duration the duration to set
+ /* (non-Javadoc)
+ * @see org.drools.StockTickInterface#setDuration(long)
*/
public void setDuration(long duration) {
this.duration = duration;
}
+ /* (non-Javadoc)
+ * @see org.drools.StockTickInterface#getDateTimestamp()
+ */
public Date getDateTimestamp() {
return new Date( this.time );
}
Added: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/StockTickInterface.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/StockTickInterface.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/StockTickInterface.java 2010-07-17 00:11:56 UTC (rev 33965)
@@ -0,0 +1,35 @@
+package org.drools;
+
+import java.util.Date;
+
+public interface StockTickInterface {
+
+ public abstract String getCompany();
+
+ public abstract void setCompany(String company);
+
+ public abstract double getPrice();
+
+ public abstract void setPrice(double price);
+
+ public abstract long getSeq();
+
+ public abstract void setSeq(long seq);
+
+ public abstract long getTime();
+
+ public abstract void setTime(long time);
+
+ /**
+ * @return the duration
+ */
+ public abstract long getDuration();
+
+ /**
+ * @param duration the duration to set
+ */
+ public abstract void setDuration(long duration);
+
+ public abstract Date getDateTimestamp();
+
+}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java 2010-07-16 21:56:37 UTC (rev 33964)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java 2010-07-17 00:11:56 UTC (rev 33965)
@@ -32,6 +32,7 @@
import org.drools.SessionConfiguration;
import org.drools.StatefulSession;
import org.drools.StockTick;
+import org.drools.StockTickInterface;
import org.drools.audit.WorkingMemoryFileLogger;
import org.drools.base.ClassObjectType;
import org.drools.base.evaluators.TimeIntervalParser;
@@ -172,22 +173,22 @@
session.setGlobal( "results",
results );
- StockTick tick1 = new StockTick( 1,
- "DROO",
- 50,
- 10000 );
- StockTick tick2 = new StockTick( 2,
- "ACME",
- 10,
- 10010 );
- StockTick tick3 = new StockTick( 3,
- "ACME",
- 10,
- 10100 );
- StockTick tick4 = new StockTick( 4,
- "DROO",
- 50,
- 11000 );
+ StockTickInterface tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ 10000 );
+ StockTickInterface tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ 10010 );
+ StockTickInterface tick3 = new StockTick( 3,
+ "ACME",
+ 10,
+ 10100 );
+ StockTickInterface tick4 = new StockTick( 4,
+ "DROO",
+ 50,
+ 11000 );
InternalFactHandle handle1 = (InternalFactHandle) session.insert( tick1 );
clock.advanceTime( 10,
@@ -256,14 +257,14 @@
session.setGlobal( "results",
results );
- StockTick tick1 = new StockTick( 1,
- "DROO",
- 50,
- 10000 );
- StockTick tick2 = new StockTick( 2,
- "ACME",
- 10,
- 10010 );
+ StockTickInterface tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ 10000 );
+ StockTickInterface tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ 10010 );
InternalFactHandle handle1 = (InternalFactHandle) session.insert( tick1 );
InternalFactHandle handle2 = (InternalFactHandle) session.insert( tick2 );
@@ -298,26 +299,26 @@
wm.setGlobal( "results",
results );
- StockTick tick1 = new StockTick( 1,
- "DROO",
- 50,
- 10000,
- 5 );
- StockTick tick2 = new StockTick( 2,
- "ACME",
- 10,
- 11000,
- 10 );
- StockTick tick3 = new StockTick( 3,
- "ACME",
- 10,
- 12000,
- 8 );
- StockTick tick4 = new StockTick( 4,
- "DROO",
- 50,
- 13000,
- 7 );
+ StockTickInterface tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ 10000,
+ 5 );
+ StockTickInterface tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ 11000,
+ 10 );
+ StockTickInterface tick3 = new StockTick( 3,
+ "ACME",
+ 10,
+ 12000,
+ 8 );
+ StockTickInterface tick4 = new StockTick( 4,
+ "DROO",
+ 50,
+ 13000,
+ 7 );
InternalFactHandle handle1 = (InternalFactHandle) wm.insert( tick1 );
InternalFactHandle handle2 = (InternalFactHandle) wm.insert( tick2 );
@@ -379,26 +380,26 @@
wm.setGlobal( "results",
results );
- StockTick tick1 = new StockTick( 1,
- "DROO",
- 50,
- 10000,
- 5 );
- StockTick tick2 = new StockTick( 2,
- "ACME",
- 10,
- 11000,
- 10 );
- StockTick tick3 = new StockTick( 3,
- "ACME",
- 10,
- 12000,
- 8 );
- StockTick tick4 = new StockTick( 4,
- "DROO",
- 50,
- 13000,
- 7 );
+ StockTickInterface tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ 10000,
+ 5 );
+ StockTickInterface tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ 11000,
+ 10 );
+ StockTickInterface tick3 = new StockTick( 3,
+ "ACME",
+ 10,
+ 12000,
+ 8 );
+ StockTickInterface tick4 = new StockTick( 4,
+ "DROO",
+ 50,
+ 13000,
+ 7 );
InternalFactHandle handle1 = (InternalFactHandle) wm.insert( tick1 );
InternalFactHandle handle2 = (InternalFactHandle) wm.insert( tick2 );
@@ -453,18 +454,19 @@
final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_CEP_EventExpiration2.drl" ) );
final RuleBaseConfiguration conf = new RuleBaseConfiguration();
conf.setEventProcessingMode( EventProcessingOption.STREAM );
- final RuleBase ruleBase = loadRuleBase( reader, conf );
+ final RuleBase ruleBase = loadRuleBase( reader,
+ conf );
final InternalRuleBase internal = (InternalRuleBase) ruleBase;
final TimeIntervalParser parser = new TimeIntervalParser();
- Map<ObjectType, ObjectTypeNode> objectTypeNodes = internal.getRete().getObjectTypeNodes(EntryPoint.DEFAULT);
+ Map<ObjectType, ObjectTypeNode> objectTypeNodes = internal.getRete().getObjectTypeNodes( EntryPoint.DEFAULT );
ObjectTypeNode node = objectTypeNodes.get( new ClassObjectType( StockTick.class ) );
-
+
assertNotNull( node );
-
+
// the expiration policy @expires(10m) should override the temporal operator usage
- assertEquals( parser.parse( "10m" )[0].longValue()+1,
+ assertEquals( parser.parse( "10m" )[0].longValue() + 1,
node.getExpirationOffset() );
}
@@ -473,18 +475,19 @@
final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_CEP_EventExpiration3.drl" ) );
final RuleBaseConfiguration conf = new RuleBaseConfiguration();
conf.setEventProcessingMode( EventProcessingOption.STREAM );
- final RuleBase ruleBase = loadRuleBase( reader, conf );
+ final RuleBase ruleBase = loadRuleBase( reader,
+ conf );
final InternalRuleBase internal = (InternalRuleBase) ruleBase;
final TimeIntervalParser parser = new TimeIntervalParser();
- Map<ObjectType, ObjectTypeNode> objectTypeNodes = internal.getRete().getObjectTypeNodes(EntryPoint.DEFAULT);
+ Map<ObjectType, ObjectTypeNode> objectTypeNodes = internal.getRete().getObjectTypeNodes( EntryPoint.DEFAULT );
ObjectTypeNode node = objectTypeNodes.get( new ClassObjectType( StockTick.class ) );
-
+
assertNotNull( node );
-
+
// the expiration policy @expires(10m) should override the temporal operator usage
- assertEquals( parser.parse( "10m" )[0].longValue()+1,
+ assertEquals( parser.parse( "10m" )[0].longValue() + 1,
node.getExpirationOffset() );
}
@@ -545,46 +548,46 @@
wm.setGlobal( "results_finished_by",
results_finished_by );
- StockTick tick1 = new StockTick( 1,
- "DROO",
- 50,
- System.currentTimeMillis(),
- 3 );
- StockTick tick2 = new StockTick( 2,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 3 );
- StockTick tick3 = new StockTick( 3,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 3 );
- StockTick tick4 = new StockTick( 4,
- "DROO",
- 50,
- System.currentTimeMillis(),
- 5 );
- StockTick tick5 = new StockTick( 5,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 5 );
- StockTick tick6 = new StockTick( 6,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 3 );
- StockTick tick7 = new StockTick( 7,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 5 );
- StockTick tick8 = new StockTick( 8,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 3 );
+ StockTickInterface tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ System.currentTimeMillis(),
+ 3 );
+ StockTickInterface tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTickInterface tick3 = new StockTick( 3,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTickInterface tick4 = new StockTick( 4,
+ "DROO",
+ 50,
+ System.currentTimeMillis(),
+ 5 );
+ StockTickInterface tick5 = new StockTick( 5,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 5 );
+ StockTickInterface tick6 = new StockTick( 6,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTickInterface tick7 = new StockTick( 7,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 5 );
+ StockTickInterface tick8 = new StockTick( 8,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
InternalFactHandle handle1 = (InternalFactHandle) wm.insert( tick1 );
clock.advanceTime( 4,
@@ -716,46 +719,46 @@
AgendaEventListener ael = mock( AgendaEventListener.class );
ksession.addEventListener( ael );
- StockTick tick1 = new StockTick( 1,
- "DROO",
- 50,
- System.currentTimeMillis(),
- 3 );
- StockTick tick2 = new StockTick( 2,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 3 );
- StockTick tick3 = new StockTick( 3,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 3 );
- StockTick tick4 = new StockTick( 4,
- "DROO",
- 50,
- System.currentTimeMillis(),
- 5 );
- StockTick tick5 = new StockTick( 5,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 5 );
- StockTick tick6 = new StockTick( 6,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 3 );
- StockTick tick7 = new StockTick( 7,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 5 );
- StockTick tick8 = new StockTick( 8,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 3 );
+ StockTickInterface tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ System.currentTimeMillis(),
+ 3 );
+ StockTickInterface tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTickInterface tick3 = new StockTick( 3,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTickInterface tick4 = new StockTick( 4,
+ "DROO",
+ 50,
+ System.currentTimeMillis(),
+ 5 );
+ StockTickInterface tick5 = new StockTick( 5,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 5 );
+ StockTickInterface tick6 = new StockTick( 6,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTickInterface tick7 = new StockTick( 7,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 5 );
+ StockTickInterface tick8 = new StockTick( 8,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
ksession.insert( tick1 );
clock.advanceTime( 4,
@@ -805,46 +808,46 @@
AgendaEventListener ael = mock( AgendaEventListener.class );
ksession.addEventListener( ael );
- StockTick tick1 = new StockTick( 1,
- "DROO",
- 50,
- System.currentTimeMillis(),
- 3 );
- StockTick tick2 = new StockTick( 2,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 3 );
- StockTick tick3 = new StockTick( 3,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 3 );
- StockTick tick4 = new StockTick( 4,
- "DROO",
- 50,
- System.currentTimeMillis(),
- 5 );
- StockTick tick5 = new StockTick( 5,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 5 );
- StockTick tick6 = new StockTick( 6,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 3 );
- StockTick tick7 = new StockTick( 7,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 5 );
- StockTick tick8 = new StockTick( 8,
- "ACME",
- 10,
- System.currentTimeMillis(),
- 3 );
+ StockTickInterface tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ System.currentTimeMillis(),
+ 3 );
+ StockTickInterface tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTickInterface tick3 = new StockTick( 3,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTickInterface tick4 = new StockTick( 4,
+ "DROO",
+ 50,
+ System.currentTimeMillis(),
+ 5 );
+ StockTickInterface tick5 = new StockTick( 5,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 5 );
+ StockTickInterface tick6 = new StockTick( 6,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTickInterface tick7 = new StockTick( 7,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 5 );
+ StockTickInterface tick8 = new StockTick( 8,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
InternalFactHandle fh1 = (InternalFactHandle) ksession.insert( tick1 );
clock.advanceTime( 4,
@@ -896,16 +899,16 @@
wm.setGlobal( "results",
results );
- StockTick tick1 = new StockTick( 1,
- "DROO",
- 50,
- 100000, // arbitrary timestamp
- 3 );
- StockTick tick2 = new StockTick( 2,
- "ACME",
- 10,
- 104000, // 4 seconds after DROO
- 3 );
+ StockTickInterface tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ 100000, // arbitrary timestamp
+ 3 );
+ StockTickInterface tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ 104000, // 4 seconds after DROO
+ 3 );
InternalFactHandle handle1 = (InternalFactHandle) wm.insert( tick1 );
InternalFactHandle handle2 = (InternalFactHandle) wm.insert( tick2 );
@@ -948,16 +951,16 @@
wm.setGlobal( "results",
results );
- StockTick tick1 = new StockTick( 1,
- "DROO",
- 50,
- 104000, // arbitrary timestamp
- 3 );
- StockTick tick2 = new StockTick( 2,
- "ACME",
- 10,
- 100000, // 4 seconds after DROO
- 3 );
+ StockTickInterface tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ 104000, // arbitrary timestamp
+ 3 );
+ StockTickInterface tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ 100000, // 4 seconds after DROO
+ 3 );
InternalFactHandle handle1 = (InternalFactHandle) wm.insert( tick1 );
InternalFactHandle handle2 = (InternalFactHandle) wm.insert( tick2 );
@@ -1000,16 +1003,16 @@
wm.setGlobal( "results",
results );
- StockTick tick1 = new StockTick( 1,
- "DROO",
- 50,
- 100000, // arbitrary timestamp
- 3 );
- StockTick tick2 = new StockTick( 2,
- "ACME",
- 10,
- 100050, // 50 milliseconds after DROO
- 3 );
+ StockTickInterface tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ 100000, // arbitrary timestamp
+ 3 );
+ StockTickInterface tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ 100050, // 50 milliseconds after DROO
+ 3 );
InternalFactHandle handle1 = (InternalFactHandle) wm.insert( tick1 );
InternalFactHandle handle2 = (InternalFactHandle) wm.insert( tick2 );
@@ -1282,10 +1285,10 @@
clock.advanceTime( 10,
TimeUnit.SECONDS );
- StockTick st1O = new StockTick( 1,
- "DROO",
- 100,
- clock.getCurrentTime() );
+ StockTickInterface st1O = new StockTick( 1,
+ "DROO",
+ 100,
+ clock.getCurrentTime() );
EventFactHandle st1 = (EventFactHandle) wm.insert( st1O );
@@ -1360,22 +1363,22 @@
session.setGlobal( "results",
results );
- StockTick tick1 = new StockTick( 1,
- "DROO",
- 50,
- 10000 );
- StockTick tick2 = new StockTick( 2,
- "ACME",
- 10,
- 10010 );
- StockTick tick3 = new StockTick( 3,
- "ACME",
- 10,
- 10100 );
- StockTick tick4 = new StockTick( 4,
- "DROO",
- 50,
- 11000 );
+ StockTickInterface tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ 10000 );
+ StockTickInterface tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ 10010 );
+ StockTickInterface tick3 = new StockTick( 3,
+ "ACME",
+ 10,
+ 10100 );
+ StockTickInterface tick4 = new StockTick( 4,
+ "DROO",
+ 50,
+ 11000 );
assertEquals( 0,
iwm.getIdleTime() );
@@ -1783,18 +1786,18 @@
public void testIdentityAssertBehaviorOnEntryPoints() throws IOException,
ClassNotFoundException {
- StockTick st1 = new StockTick( 1,
- "RHT",
- 10,
- 10 );
- StockTick st2 = new StockTick( 1,
- "RHT",
- 10,
- 10 );
- StockTick st3 = new StockTick( 2,
- "RHT",
- 15,
- 20 );
+ StockTickInterface st1 = new StockTick( 1,
+ "RHT",
+ 10,
+ 10 );
+ StockTickInterface st2 = new StockTick( 1,
+ "RHT",
+ 10,
+ 10 );
+ StockTickInterface st3 = new StockTick( 2,
+ "RHT",
+ 15,
+ 20 );
final KnowledgeBaseConfiguration kbconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbconf.setOption( EventProcessingOption.STREAM );
@@ -1832,18 +1835,18 @@
public void testEqualityAssertBehaviorOnEntryPoints() throws IOException,
ClassNotFoundException {
- StockTick st1 = new StockTick( 1,
- "RHT",
- 10,
- 10 );
- StockTick st2 = new StockTick( 1,
- "RHT",
- 10,
- 10 );
- StockTick st3 = new StockTick( 2,
- "RHT",
- 15,
- 20 );
+ StockTickInterface st1 = new StockTick( 1,
+ "RHT",
+ 10,
+ 10 );
+ StockTickInterface st2 = new StockTick( 1,
+ "RHT",
+ 10,
+ 10 );
+ StockTickInterface st3 = new StockTick( 2,
+ "RHT",
+ 15,
+ 20 );
final KnowledgeBaseConfiguration kbconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbconf.setOption( EventProcessingOption.STREAM );
@@ -1877,4 +1880,40 @@
ksession1.dispose();
}
+ public void testEventDeclarationForInterfaces() throws Exception {
+ // read in the source
+ final KnowledgeBase kbase = loadKnowledgeBase( "test_CEP_EventInterfaces.drl",
+ null,
+ true );
+
+ StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();
+
+ StockTickInterface tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ 10000 );
+ StockTickInterface tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ 10010 );
+ StockTickInterface tick3 = new StockTick( 3,
+ "ACME",
+ 10,
+ 10100 );
+ StockTickInterface tick4 = new StockTick( 4,
+ "DROO",
+ 50,
+ 11000 );
+
+ InternalFactHandle handle1 = (InternalFactHandle) session.insert( tick1 );
+ InternalFactHandle handle2 = (InternalFactHandle) session.insert( tick2 );
+ InternalFactHandle handle3 = (InternalFactHandle) session.insert( tick3 );
+ InternalFactHandle handle4 = (InternalFactHandle) session.insert( tick4 );
+
+ assertTrue( handle1.isEvent() );
+ assertTrue( handle2.isEvent() );
+ assertTrue( handle3.isEvent() );
+ assertTrue( handle4.isEvent() );
+ }
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StreamsTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StreamsTest.java 2010-07-16 21:56:37 UTC (rev 33964)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StreamsTest.java 2010-07-17 00:11:56 UTC (rev 33965)
@@ -39,6 +39,7 @@
import org.drools.KnowledgeBaseFactory;
import org.drools.SessionConfiguration;
import org.drools.StockTick;
+import org.drools.StockTickInterface;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
@@ -119,19 +120,19 @@
session.setGlobal( "results",
results );
- StockTick tick1 = new StockTick( 1,
+ StockTickInterface tick1 = new StockTick( 1,
"DROO",
50,
System.currentTimeMillis() );
- StockTick tick2 = new StockTick( 2,
+ StockTickInterface tick2 = new StockTick( 2,
"ACME",
10,
System.currentTimeMillis() );
- StockTick tick3 = new StockTick( 3,
+ StockTickInterface tick3 = new StockTick( 3,
"ACME",
10,
System.currentTimeMillis() );
- StockTick tick4 = new StockTick( 4,
+ StockTickInterface tick4 = new StockTick( 4,
"DROO",
50,
System.currentTimeMillis() );
@@ -156,19 +157,19 @@
assertEquals( 0,
results.size() );
- StockTick tick5 = new StockTick( 5,
+ StockTickInterface tick5 = new StockTick( 5,
"DROO",
50,
System.currentTimeMillis() );
- StockTick tick6 = new StockTick( 6,
+ StockTickInterface tick6 = new StockTick( 6,
"ACME",
10,
System.currentTimeMillis() );
- StockTick tick7 = new StockTick( 7,
+ StockTickInterface tick7 = new StockTick( 7,
"ACME",
15,
System.currentTimeMillis() );
- StockTick tick8 = new StockTick( 8,
+ StockTickInterface tick8 = new StockTick( 8,
"DROO",
50,
System.currentTimeMillis() );
@@ -208,19 +209,19 @@
session.setGlobal( "results",
results );
- StockTick tick5 = new StockTick( 5,
+ StockTickInterface tick5 = new StockTick( 5,
"DROO",
50,
System.currentTimeMillis() );
- StockTick tick6 = new StockTick( 6,
+ StockTickInterface tick6 = new StockTick( 6,
"ACME",
10,
System.currentTimeMillis() );
- StockTick tick7 = new StockTick( 7,
+ StockTickInterface tick7 = new StockTick( 7,
"ACME",
30,
System.currentTimeMillis() );
- StockTick tick8 = new StockTick( 8,
+ StockTickInterface tick8 = new StockTick( 8,
"DROO",
50,
System.currentTimeMillis() );
@@ -260,19 +261,19 @@
session.setGlobal( "results",
results );
- StockTick tick5 = new StockTick( 5,
+ StockTickInterface tick5 = new StockTick( 5,
"DROO",
50,
System.currentTimeMillis() );
- StockTick tick6 = new StockTick( 6,
+ StockTickInterface tick6 = new StockTick( 6,
"ACME",
10,
System.currentTimeMillis() );
- StockTick tick7 = new StockTick( 7,
+ StockTickInterface tick7 = new StockTick( 7,
"ACME",
30,
System.currentTimeMillis() );
- StockTick tick8 = new StockTick( 8,
+ StockTickInterface tick8 = new StockTick( 8,
"DROO",
50,
System.currentTimeMillis() );
@@ -348,11 +349,11 @@
PseudoClockScheduler clock = ksession.getSessionClock();
- final StockTick st1 = new StockTick( 1,
+ final StockTickInterface st1 = new StockTick( 1,
"RHT",
100,
1000 );
- final StockTick st2 = new StockTick( 2,
+ final StockTickInterface st2 = new StockTick( 2,
"RHT",
100,
1000 );
@@ -396,11 +397,11 @@
PseudoClockScheduler clock = ksession.getSessionClock();
- final StockTick st1 = new StockTick( 1,
+ final StockTickInterface st1 = new StockTick( 1,
"RHT",
100,
1000 );
- final StockTick st2 = new StockTick( 2,
+ final StockTickInterface st2 = new StockTick( 2,
"RHT",
100,
1000 );
Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_EventInterfaces.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_EventInterfaces.drl (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_EventInterfaces.drl 2010-07-17 00:11:56 UTC (rev 33965)
@@ -0,0 +1,13 @@
+package org.drools;
+
+declare StockTickInterface
+ @role( event )
+ @timestamp( dateTimestamp )
+end
+
+rule "Check event"
+when
+ $st : StockTick( company == "ACME" )
+then
+ // no-op
+end
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2010-07-16 21:56:37 UTC (rev 33964)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2010-07-17 00:11:56 UTC (rev 33965)
@@ -200,7 +200,7 @@
// must write this option first in order to properly deserialize later
droolsStream.writeBoolean( this.config.isClassLoaderCacheEnabled() );
-
+
droolsStream.writeObject( this.config );
droolsStream.writeObject( this.pkgs );
@@ -253,7 +253,8 @@
}
boolean classLoaderCacheEnabled = droolsStream.readBoolean();
- this.rootClassLoader = new DroolsCompositeClassLoader( droolsStream.getParentClassLoader(), classLoaderCacheEnabled );
+ this.rootClassLoader = new DroolsCompositeClassLoader( droolsStream.getParentClassLoader(),
+ classLoaderCacheEnabled );
droolsStream.setClassLoader( this.rootClassLoader );
droolsStream.setRuleBase( this );
@@ -619,10 +620,74 @@
// this.reloadPackageCompilationData.addDialectDatas( pkg.getDialectRuntimeRegistry() );
}
+ private static class TypeDeclarationCandidate {
+ public TypeDeclaration candidate = null;
+ public int score = Integer.MAX_VALUE;
+ }
+
public TypeDeclaration getTypeDeclaration(Class< ? > clazz) {
- return this.classTypeDeclaration.get( clazz );
+ TypeDeclaration typeDeclaration = this.classTypeDeclaration.get( clazz );
+ if ( typeDeclaration == null ) {
+ // check super classes and keep a score of how up in the hierarchy is there a declaration
+ TypeDeclarationCandidate candidate = checkSuperClasses( clazz );
+ // now check interfaces
+ candidate = checkInterfaces( clazz,
+ candidate,
+ 1 );
+ if( candidate != null ) {
+ typeDeclaration = candidate.candidate;
+ }
+ }
+ return typeDeclaration;
}
+ private TypeDeclarationCandidate checkSuperClasses(Class< ? > clazz) {
+ TypeDeclarationCandidate candidate = null;
+ TypeDeclaration typeDeclaration = null;
+ Class< ? > current = clazz.getSuperclass();
+ int score = 0;
+ while ( typeDeclaration == null && current != null ) {
+ score++;
+ typeDeclaration = this.classTypeDeclaration.get( current );
+ current = current.getSuperclass();
+ }
+ if ( typeDeclaration == null ) {
+ // no type declaration found for superclasses
+ score = Integer.MAX_VALUE;
+ } else {
+ candidate = new TypeDeclarationCandidate();
+ candidate.candidate = typeDeclaration;
+ candidate.score = score;
+ }
+ return candidate;
+ }
+
+ private TypeDeclarationCandidate checkInterfaces(Class< ? > clazz,
+ TypeDeclarationCandidate baseline,
+ int level) {
+ TypeDeclarationCandidate candidate = null;
+ TypeDeclaration typeDeclaration = null;
+ if ( baseline == null || level < baseline.score ) {
+ // search
+ for ( Class< ? > ifc : clazz.getInterfaces() ) {
+ typeDeclaration = this.classTypeDeclaration.get( ifc );
+ if ( typeDeclaration != null ) {
+ candidate = new TypeDeclarationCandidate();
+ candidate.candidate = typeDeclaration;
+ candidate.score = level;
+ break;
+ } else {
+ candidate = checkInterfaces( ifc,
+ baseline,
+ level + 1 );
+ }
+ }
+ } else {
+ candidate = baseline;
+ }
+ return candidate;
+ }
+
public Collection<TypeDeclaration> getTypeDeclarations() {
return this.classTypeDeclaration.values();
}
More information about the jboss-svn-commits
mailing list