use of org.drools.compiler.integrationtests.facts.BasicEvent in project drools by kiegroup.
the class ExpirationTest method testEventsExpiredInThePast.
private void testEventsExpiredInThePast(final String drl) {
final KieSessionConfiguration sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
sessionConfig.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
final KieHelper helper = new KieHelper();
helper.addContent(drl, ResourceType.DRL);
final KieBase kieBase = helper.build(EventProcessingOption.STREAM);
final KieSession kieSession = kieBase.newKieSession(sessionConfig, null);
PseudoClockScheduler clock = kieSession.getSessionClock();
final long currentTime = clock.getCurrentTime();
clock.advanceTime(100, TimeUnit.MILLISECONDS);
kieSession.insert(new BasicEvent(new Date(currentTime + 20), 10L, "20ms-30ms"));
clock.advanceTime(1, TimeUnit.MILLISECONDS);
kieSession.insert(new BasicEvent(new Date(currentTime + 20), 20L, "20ms-40ms"));
clock.advanceTime(100, TimeUnit.MILLISECONDS);
Assertions.assertThat(kieSession.fireAllRules()).isEqualTo(1);
clock.advanceTime(10, TimeUnit.MILLISECONDS);
Assertions.assertThat(kieSession.getObjects()).isEmpty();
}
Aggregations