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

Davide Sottara (JIRA) jira-events at lists.jboss.org
Sun Apr 28 06:54:54 EDT 2013


    [ https://issues.jboss.org/browse/JBRULES-3288?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12770559#comment-12770559 ] 

Davide Sottara commented on JBRULES-3288:
-----------------------------------------

This is not a bug.. there is a mismatch between the clock and the timestamps.
now() is based on the system clock and starts from "epoch", the pseudo-clock starts at 0.
You are not seeing the final activations because the engine is waiting to expire the
events, i.e. the pseudo-clock to advance to now()+10...
When you use the realtime clock, instead, the times are aligned as you would expect
                
> Sliding time window ignored when using @timestamp and pseudo clock
> ------------------------------------------------------------------
>
>                 Key: JBRULES-3288
>                 URL: https://issues.jboss.org/browse/JBRULES-3288
>             Project: JBRULES
>          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: Edson Tirelli
>              Labels: @timestamp, drools, fusion, pseudoclock
>
> 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
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jboss-jira mailing list