Search in sources :

Example 1 with Event

use of org.drools.testcoverage.common.model.Event in project drools by kiegroup.

the class FusionAfterBeforeTest method testExpireEventsWhenSharingAllRules.

@Test(timeout = 10000)
public void testExpireEventsWhenSharingAllRules() throws InstantiationException, IllegalAccessException {
    final StringBuilder drlBuilder = new StringBuilder();
    for (int i = 0; i < 64; i++) {
        drlBuilder.append(" import " + EventA.class.getCanonicalName() + ";\n");
        drlBuilder.append(" import " + EventB.class.getCanonicalName() + ";\n");
        drlBuilder.append(" declare " + EventA.class.getName() + " @role( event ) @duration(duration) end");
        drlBuilder.append(" declare " + EventB.class.getName() + " @role( event ) @duration(duration) end");
        drlBuilder.append(" rule R" + i + " when \n");
        drlBuilder.append("   $event1: " + EventA.class.getName() + "()\n");
        drlBuilder.append("   $event2: " + EventB.class.getName() + "(this != $event1, this after [1,10] $event1)\n");
        drlBuilder.append("then end\n");
    }
    final SortedSet<Event> events = new TreeSet<Event>();
    events.addAll(getEvents(EventA.class, 64 / 2, 2, 100, 0));
    events.addAll(getEvents(EventB.class, 64 / 2, 5, 100, 0));
    final KieSessionConfiguration sessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    sessionConf.setOption(ClockTypeOption.get("pseudo"));
    final KieSession kieSession = new KieHelper().addContent(drlBuilder.toString(), ResourceType.DRL).build(kieBaseTestConfiguration.getKieBaseConfiguration()).newKieSession(sessionConf, null);
    Assertions.assertThat(insertEventsAndFire(kieSession, events)).isEqualTo(2048);
}
Also used : EventB(org.drools.testcoverage.common.model.EventB) TreeSet(java.util.TreeSet) Event(org.drools.testcoverage.common.model.Event) MessageEvent(org.drools.testcoverage.common.model.MessageEvent) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) EventA(org.drools.testcoverage.common.model.EventA) EntryPoint(org.kie.api.runtime.rule.EntryPoint) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) Test(org.junit.Test)

Example 2 with Event

use of org.drools.testcoverage.common.model.Event in project drools by kiegroup.

the class FusionAfterBeforeTest method insertEventsAndFire.

private int insertEventsAndFire(final KieSession kieSession, final SortedSet<Event> events) {
    final SessionPseudoClock sessionClock = kieSession.getSessionClock();
    final long startTime = sessionClock.getCurrentTime();
    int fireCount = 0;
    for (Event event : events) {
        final long eventTime = startTime + event.getTimeValue();
        sessionClock.advanceTime(eventTime - sessionClock.getCurrentTime(), TimeUnit.MILLISECONDS);
        kieSession.insert(event);
        fireCount += kieSession.fireAllRules();
    }
    return fireCount;
}
Also used : SessionPseudoClock(org.kie.api.time.SessionPseudoClock) Event(org.drools.testcoverage.common.model.Event) MessageEvent(org.drools.testcoverage.common.model.MessageEvent) EntryPoint(org.kie.api.runtime.rule.EntryPoint)

Aggregations

Event (org.drools.testcoverage.common.model.Event)2 MessageEvent (org.drools.testcoverage.common.model.MessageEvent)2 EntryPoint (org.kie.api.runtime.rule.EntryPoint)2 TreeSet (java.util.TreeSet)1 EventA (org.drools.testcoverage.common.model.EventA)1 EventB (org.drools.testcoverage.common.model.EventB)1 Test (org.junit.Test)1 KieSession (org.kie.api.runtime.KieSession)1 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)1 SessionPseudoClock (org.kie.api.time.SessionPseudoClock)1 KieHelper (org.kie.internal.utils.KieHelper)1