Search in sources :

Example 1 with StockTickEvent

use of org.drools.compiler.StockTickEvent in project drools by kiegroup.

the class CepEspTest method testAnnotatedEventAssertion.

@Test(timeout = 10000)
public void testAnnotatedEventAssertion() throws Exception {
    KieBase kbase = loadKnowledgeBase("test_CEP_SimpleAnnotatedEventAssertion.drl");
    KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    conf.setOption(ClockTypeOption.get("pseudo"));
    KieSession session = createKnowledgeSession(kbase, conf);
    SessionPseudoClock clock = (SessionPseudoClock) session.<SessionClock>getSessionClock();
    final List results = new ArrayList();
    session.setGlobal("results", results);
    StockTickInterface tick1 = new StockTickEvent(1, "DROO", 50, 10000);
    StockTickInterface tick2 = new StockTickEvent(2, "ACME", 10, 10010);
    StockTickInterface tick3 = new StockTickEvent(3, "ACME", 10, 10100);
    StockTickInterface tick4 = new StockTickEvent(4, "DROO", 50, 11000);
    InternalFactHandle handle1 = (InternalFactHandle) session.insert(tick1);
    clock.advanceTime(10, TimeUnit.SECONDS);
    InternalFactHandle handle2 = (InternalFactHandle) session.insert(tick2);
    clock.advanceTime(30, TimeUnit.SECONDS);
    InternalFactHandle handle3 = (InternalFactHandle) session.insert(tick3);
    clock.advanceTime(20, TimeUnit.SECONDS);
    InternalFactHandle handle4 = (InternalFactHandle) session.insert(tick4);
    clock.advanceTime(10, TimeUnit.SECONDS);
    assertNotNull(handle1);
    assertNotNull(handle2);
    assertNotNull(handle3);
    assertNotNull(handle4);
    assertTrue(handle1.isEvent());
    assertTrue(handle2.isEvent());
    assertTrue(handle3.isEvent());
    assertTrue(handle4.isEvent());
    session.fireAllRules();
    assertEquals(2, ((List) session.getGlobal("results")).size());
}
Also used : StockTickInterface(org.drools.compiler.StockTickInterface) StockTickEvent(org.drools.compiler.StockTickEvent) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) InternalFactHandle(org.drools.core.common.InternalFactHandle) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 StockTickEvent (org.drools.compiler.StockTickEvent)1 StockTickInterface (org.drools.compiler.StockTickInterface)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 KieSession (org.kie.api.runtime.KieSession)1 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)1 SessionPseudoClock (org.kie.api.time.SessionPseudoClock)1