Search in sources :

Example 21 with StockTick

use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.

the class CepTest method testAfterOnFactAndField.

@Test
public void testAfterOnFactAndField() throws Exception {
    String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + "    $a : StockTick( company == \"DROO\" )\n" + "    $b : StockTick( company == \"ACME\", timeFieldAsLong after[5,8] $a )\n" + "then\n" + "  System.out.println(\"fired\");\n" + "end\n";
    KieSession ksession = getKieSession(getCepKieModuleModel(), str);
    SessionPseudoClock clock = ksession.getSessionClock();
    ksession.insert(new StockTick("DROO").setTimeField(0));
    clock.advanceTime(6, TimeUnit.MILLISECONDS);
    ksession.insert(new StockTick("ACME").setTimeField(6));
    assertEquals(1, ksession.fireAllRules());
    clock.advanceTime(4, TimeUnit.MILLISECONDS);
    ksession.insert(new StockTick("ACME").setTimeField(10));
    assertEquals(0, ksession.fireAllRules());
}
Also used : StockTick(org.drools.modelcompiler.domain.StockTick) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 22 with StockTick

use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.

the class CepTest method testAfterOnLongFieldsBindingFirstWithDifferentMethod.

@Test
public void testAfterOnLongFieldsBindingFirstWithDifferentMethod() throws Exception {
    String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "import " + StockTickEx.class.getCanonicalName() + ";\n" + "declare StockTick @timestamp(timeFieldAsLong) end\n" + "declare StockTickEx @timestamp(timeFieldExAsLong) end\n" + "rule R when\n" + "    $a : StockTickEx( company == \"DROO\" )\n" + "    StockTick( company == \"ACME\", $a.timeFieldExAsLong after[5,8] timeFieldAsLong )\n" + "then\n" + "  System.out.println(\"fired\");\n" + "end\n";
    KieSession ksession = getKieSession(getCepKieModuleModel(), str);
    SessionPseudoClock clock = ksession.getSessionClock();
    ksession.insert(new StockTick("ACME").setTimeField(0));
    ksession.insert(new StockTickEx("DROO").setTimeFieldEx(6));
    assertEquals(1, ksession.fireAllRules());
    ksession.insert(new StockTickEx("DROO").setTimeFieldEx(10));
    assertEquals(0, ksession.fireAllRules());
}
Also used : StockTickEx(org.drools.modelcompiler.domain.StockTickEx) StockTick(org.drools.modelcompiler.domain.StockTick) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 23 with StockTick

use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.

the class CepTest method testAfterOnDateFieldsWithBinding.

@Test
public void testAfterOnDateFieldsWithBinding() throws Exception {
    String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + "    $a : StockTick( company == \"DROO\", $aTime : timeFieldAsDate )\n" + "    $b : StockTick( company == \"ACME\", timeFieldAsDate after[5,8] $aTime )\n" + "then\n" + "  System.out.println(\"fired\");\n" + "end\n";
    KieSession ksession = getKieSession(getCepKieModuleModel(), str);
    SessionPseudoClock clock = ksession.getSessionClock();
    clock.advanceTime(100, TimeUnit.MILLISECONDS);
    ksession.insert(new StockTick("DROO").setTimeField(0));
    ksession.insert(new StockTick("ACME").setTimeField(6));
    assertEquals(1, ksession.fireAllRules());
    ksession.insert(new StockTick("ACME").setTimeField(10));
    assertEquals(0, ksession.fireAllRules());
}
Also used : StockTick(org.drools.modelcompiler.domain.StockTick) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 24 with StockTick

use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.

the class CepTest method testAfterOnLongFields.

@Test
public void testAfterOnLongFields() throws Exception {
    String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + "    $a : StockTick( company == \"DROO\" )\n" + "    $b : StockTick( company == \"ACME\", timeFieldAsLong after[5,8] $a.timeFieldAsLong )\n" + "then\n" + "  System.out.println(\"fired\");\n" + "end\n";
    KieSession ksession = getKieSession(getCepKieModuleModel(), str);
    SessionPseudoClock clock = ksession.getSessionClock();
    ksession.insert(new StockTick("DROO").setTimeField(0));
    ksession.insert(new StockTick("ACME").setTimeField(6));
    assertEquals(1, ksession.fireAllRules());
    ksession.insert(new StockTick("ACME").setTimeField(10));
    assertEquals(0, ksession.fireAllRules());
}
Also used : StockTick(org.drools.modelcompiler.domain.StockTick) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 25 with StockTick

use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.

the class CepTest method testAfterOnDateFields.

@Test
public void testAfterOnDateFields() throws Exception {
    String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + "    $a : StockTick( company == \"DROO\" )\n" + "    $b : StockTick( company == \"ACME\", timeFieldAsDate after[5,8] $a.timeFieldAsDate )\n" + "then\n" + "  System.out.println(\"fired\");\n" + "end\n";
    KieSession ksession = getKieSession(getCepKieModuleModel(), str);
    SessionPseudoClock clock = ksession.getSessionClock();
    ksession.insert(new StockTick("DROO").setTimeField(0));
    ksession.insert(new StockTick("ACME").setTimeField(6));
    assertEquals(1, ksession.fireAllRules());
    ksession.insert(new StockTick("ACME").setTimeField(10));
    assertEquals(0, ksession.fireAllRules());
}
Also used : StockTick(org.drools.modelcompiler.domain.StockTick) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Aggregations

StockTick (org.drools.modelcompiler.domain.StockTick)35 Test (org.junit.Test)35 KieSession (org.kie.api.runtime.KieSession)35 SessionPseudoClock (org.kie.api.time.SessionPseudoClock)29 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)4 Arrays (java.util.Arrays)4 Collection (java.util.Collection)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 Assertions (org.assertj.core.api.Assertions)4 ClockType (org.drools.core.ClockType)4 Global (org.drools.model.Global)4 Model (org.drools.model.Model)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Query (org.drools.model.Query)3 Query2Def (org.drools.model.Query2Def)3 Rule (org.drools.model.Rule)3 Variable (org.drools.model.Variable)3 ModelImpl (org.drools.model.impl.ModelImpl)3