[jboss-jira] [JBoss JIRA] (JBRULES-3288) Sliding time window ignored when using @timestamp and pseudo clock

Colin Webber (Created) (JIRA) jira-events at lists.jboss.org
Fri Nov 11 05:11:45 EST 2011


Sliding time window ignored when using @timestamp and pseudo clock
------------------------------------------------------------------

                 Key: JBRULES-3288
                 URL: https://issues.jboss.org/browse/JBRULES-3288
             Project: Drools
          Issue Type: Bug
      Security Level: Public (Everyone can see)
          Components: drools-core (fusion)
    Affects Versions: 5.3.0.Final
         Environment: Mac OSX 10.6.8
            Reporter: Colin Webber
            Assignee: Mark Proctor


When using a custom @timestamp together with PSEUDO clock, all events are accumulated rather than just those within the window:time period.  I have tried using long (millisecond) and java.util.Date without success.

==================================

declare SimpleObject 
	@role(event)
	@timestamp(customTime)
	@expires(10m)
end;

rule "honour custom timestamp"
when
	$avgVal : Number (longValue > 0) from accumulate ( SimpleObject($valueLng : valueLong ) over window:time (10s) from entry-point "SimpleEP", average ( $valueLng ) )
then
	System.out.println("avg: " + $avgVal);
end

---------------------------------------

import java.util.Date;

public class SimpleObject {
	
	private long customTime;
	public long valueLong;
	
	public SimpleObject(Date customTime, long valueLong) {
		this.customTime = customTime.getTime();
		this.valueLong = valueLong;
	}
	
	public long getCustomTime() {
		return customTime;
	}
	public void setCustomTime(long customTime) {
		this.customTime = customTime;
	}
	public long getValueLong() {
		return valueLong;
	}
	public void setValueLong(long valueLong) {
		this.valueLong = valueLong;
	}
	
}
------------ Trivial Spock/Groovy unit test ----------------
	@IgnoreRest
	def "should honour custom timestamp"() {
		when:
		use (TimeCategory) {
			def now = new Date()
			simpleEp.insert(new SimpleObject(now, 100))
			ksession.fireAllRules()
			clock.advanceTime( 5, TimeUnit.SECONDS );
			ksession.fireAllRules()
			simpleEp.insert(new SimpleObject(5.seconds.from.now, 90))
			ksession.fireAllRules()
			clock.advanceTime( 5, TimeUnit.SECONDS );
			ksession.fireAllRules()
			simpleEp.insert(new SimpleObject(10.seconds.from.now, 80))
			ksession.fireAllRules()
			clock.advanceTime( 5, TimeUnit.SECONDS );
			ksession.fireAllRules()
			simpleEp.insert(new SimpleObject(15.seconds.from.now, 70))
			ksession.fireAllRules()
			clock.advanceTime( 5, TimeUnit.SECONDS );
			ksession.fireAllRules()
			simpleEp.insert(new SimpleObject(20.seconds.from.now, 60))
			ksession.fireAllRules()
			clock.advanceTime( 5, TimeUnit.SECONDS );
			ksession.fireAllRules()
			simpleEp.insert(new SimpleObject(25.seconds.from.now, 50))
			ksession.fireAllRules()
			clock.advanceTime( 5, TimeUnit.SECONDS );
			ksession.fireAllRules()
		}

		then:
		1 == 1 // no assertions - we're examining the stdout.
	}
==================================
OUTPUT (INCORRECT - all values are included for each evalutation):
avg: 100.0
avg: 95.0
avg: 90.0
avg: 85.0
avg: 80.0
avg: 75.0

Note that when commenting out the @timestamp tag the output changes to the following (correct) output:
avg: 100.0
avg: 95.0
avg: 90.0
avg: 85.0
avg: 80.0
avg: 75.0
avg: 70.0
avg: 65.0
avg: 60.0
avg: 55.0
avg: 50.0

Also note that when using the REALTIME clock with Thread.sleep the output is correct.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jboss-jira mailing list