Search in sources :

Example 1 with BasicEvent

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();
}
Also used : KieBase(org.kie.api.KieBase) KieHelper(org.kie.internal.utils.KieHelper) BasicEvent(org.drools.compiler.integrationtests.facts.BasicEvent) KieSession(org.kie.api.runtime.KieSession) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) PseudoClockScheduler(org.drools.core.time.impl.PseudoClockScheduler) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 BasicEvent (org.drools.compiler.integrationtests.facts.BasicEvent)1 PseudoClockScheduler (org.drools.core.time.impl.PseudoClockScheduler)1 KieBase (org.kie.api.KieBase)1 KieSession (org.kie.api.runtime.KieSession)1 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)1 KieHelper (org.kie.internal.utils.KieHelper)1