Hello again,
I'm back on my problem and a colleague of mime suggested me the following rule instead :
# declare events
declare Operation
@role(event)
@timestamp(date)
end
rule "overActivity"
dialect "mvel"
when
#condition : 2 operation in less than 1 minute
$operation1 : Operation($ipAddress1 : ipAddress)
from entry-point "OperationStream"
$operation2 : Operation(this != $operation1, ipAddress == $ipAddress1,
this after[ 0s,30s ] $operation1) from entry-point "OperationStream"
then
#actions
System.out.println("over-active user " + $ipAddress1 );
end
It works, and the main difference is the use of after[] instead of window:time()
Is it because the window:time() was used outside of an accumulate() function ?
I'd just like to understand this.
If anyone can take a few minutes to answer, thank you in advance
Best regards,
Xavier
Hello Wolfgang,
sorry, I wasn't available yesterday.
I just followed your instructions:
Here's my test method now :
@SuppressWarnings("unchecked")"activity/activity18h20-18h30-extract.log");
@Test
public void testActivity() throws IOException, ParseException,
InterruptedException {
// parse the log file
Resource logFile = new ClassPathResource(
// converter and inject tracks in the session,
List<String> logLines = FileUtils.readLines(logFile.getFile(),
"UTF-8");
LOGGER.info("loading events");Operation previousOperation = null;
// load events from stream
for (String logLine : logLines) {
Operation operation = LineConverterUtil.getOperation(logLine);
Assert.assertFalse("Current operation equals() previous one",previousOperation = operation;
operation.equals(previousOperation));
Assert.assertFalse("Current operation == previous one",
operation == previousOperation);
LOGGER.debug("Moving clock from "
+ (new Date(clock.getCurrentTime())).toString() + " to "
+ operation.getDate());
clock.advanceTime(operation.getDate().getTime()
- clock.getCurrentTime(), TimeUnit.MILLISECONDS);
// clock.advanceTime(10, TimeUnit.SECONDS);
LOGGER.debug("Inserting " + operation);session.fireAllRules();
FactHandle operationHandle = entryPoint.insert(operation);
LOGGER.debug("Insertion done: " +
operationHandle.toExternalForm());
}
LOGGER.info("done with events");
// check...
Assert.assertTrue("Rule not fired...", listener
.isRuleFired("overActivity"));
}
And the logs in the console :Console> 2010-05-19 09:57:06|INFO ||DroolsRulesTestCase.testActivity|loading
events
Console> 2010-05-19 09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Moving
clock from Thu Jan 01 01:00:00 CET 1970 to Fri Apr 30 18:26:47 CEST 2010Console> 2010-05-19
09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Inserting Operation
[date=Fri Apr 30 18:26:47 CEST 2010, executionTime=1, hostname=server1,Console> 2010-05-19 09:57:06|WARN
ipAddress=1.2.3.4, operation=null, requestSize=0, responseSize=0]
||TrackingWorkingMemoryEventListener.objectInserted|Object inserted: [eventConsole> 2010-05-19
fid:1:1:Operation [date=Fri Apr 30 18:26:47 CEST 2010, executionTime=1,
hostname=server1, ipAddress=1.2.3.4, operation=null, requestSize=0,
responseSize=0]]
09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Insertion done: [event
fid:1:1:Operation [date=Fri Apr 30 18:26:47 CEST 2010, executionTime=1,Console> 2010-05-19 09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Moving
hostname=server1, ipAddress=1.2.3.4, operation=null, requestSize=0,
responseSize=0]]
clock from Fri Apr 30 18:26:47 CEST 2010 to Fri Apr 30 18:27:11 CEST 2010Console> 2010-05-19
09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Inserting Operation
[date=Fri Apr 30 18:27:11 CEST 2010, executionTime=164, hostname=server1,Console> 2010-05-19 09:57:06|WARN
ipAddress=1.2.3.4, operation=CONSULTATION, requestSize=1299,
responseSize=895]
||TrackingWorkingMemoryEventListener.objectRetracted|Object retracted:Console> 2010-05-19 09:57:06|WARN
[event fid:1:1:Operation [date=Fri Apr 30 18:26:47 CEST 2010,
executionTime=1, hostname=server1, ipAddress=1.2.3.4, operation=null,
requestSize=0, responseSize=0]]
||TrackingWorkingMemoryEventListener.objectInserted|Object inserted: [eventConsole> 2010-05-19
fid:2:2:Operation [date=Fri Apr 30 18:27:11 CEST 2010, executionTime=164,
hostname=server1, ipAddress=1.2.3.4, operation=CONSULTATION,
requestSize=1299, responseSize=895]]
09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Insertion done: [event
fid:2:2:Operation [date=Fri Apr 30 18:27:11 CEST 2010, executionTime=164,Console> 2010-05-19 09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Moving
hostname=server1, ipAddress=1.2.3.4, operation=CONSULTATION,
requestSize=1299, responseSize=895]]
clock from Fri Apr 30 18:27:11 CEST 2010 to Fri Apr 30 18:28:47 CEST 2010Console> 2010-05-19
09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Inserting Operation
[date=Fri Apr 30 18:28:47 CEST 2010, executionTime=1, hostname=server1,Console> 2010-05-19 09:57:06|WARN
ipAddress=1.2.3.4, operation=null, requestSize=0, responseSize=0]
||TrackingWorkingMemoryEventListener.objectRetracted|Object retracted:Console> 2010-05-19 09:57:06|WARN
[event fid:2:2:Operation [date=Fri Apr 30 18:27:11 CEST 2010,
executionTime=164, hostname=server1, ipAddress=1.2.3.4,
operation=CONSULTATION, requestSize=1299, responseSize=895]]
||TrackingWorkingMemoryEventListener.objectInserted|Object inserted: [eventConsole> 2010-05-19
fid:3:3:Operation [date=Fri Apr 30 18:28:47 CEST 2010, executionTime=1,
hostname=server1, ipAddress=1.2.3.4, operation=null, requestSize=0,
responseSize=0]]
09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Insertion done: [event
fid:3:3:Operation [date=Fri Apr 30 18:28:47 CEST 2010, executionTime=1,Console> 2010-05-19 09:57:06|INFO ||DroolsRulesTestCase.testActivity|done
hostname=server1, ipAddress=1.2.3.4, operation=null, requestSize=0,
responseSize=0]]
with events
/Xavier
Strangely, the first operation is retracted when the second one is inserted,
yet, they are not equals()...
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Fusion-Can-t-detect-2-occurrences-with-sliding-window-tp823141p828505.html
Sent from the Drools - User mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users