Search in sources :

Example 76 with KieBaseConfiguration

use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.

the class CepEspTest method testEventExpiration3.

@Test(timeout = 10000)
public void testEventExpiration3() throws Exception {
    // read in the source
    KieBaseConfiguration conf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    conf.setOption(EventProcessingOption.STREAM);
    final KieBase kbase = loadKnowledgeBase(conf, "test_CEP_EventExpiration3.drl");
    Map<ObjectType, ObjectTypeNode> objectTypeNodes = ((KnowledgeBaseImpl) kbase).getRete().getObjectTypeNodes(EntryPointId.DEFAULT);
    ObjectTypeNode node = objectTypeNodes.get(new ClassObjectType(StockTick.class));
    assertNotNull(node);
    // the expiration policy @expires(10m) should override the temporal operator usage
    assertEquals(TimeIntervalParser.parse("10m")[0] + 1, node.getExpirationOffset());
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) ObjectType(org.drools.core.spi.ObjectType) ClassObjectType(org.drools.core.base.ClassObjectType) ClassObjectType(org.drools.core.base.ClassObjectType) StockTick(org.drools.compiler.StockTick) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) Test(org.junit.Test)

Example 77 with KieBaseConfiguration

use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.

the class CepEspTest method testEqualityAssertBehaviorOnEntryPoints.

@Test(timeout = 10000)
public void testEqualityAssertBehaviorOnEntryPoints() throws IOException, ClassNotFoundException {
    StockTickInterface st1 = new StockTick(1, "RHT", 10, 10);
    StockTickInterface st2 = new StockTick(1, "RHT", 10, 10);
    StockTickInterface st3 = new StockTick(2, "RHT", 15, 20);
    final KieBaseConfiguration kbconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kbconf.setOption(EventProcessingOption.STREAM);
    kbconf.setOption(EqualityBehaviorOption.EQUALITY);
    final KieBase kbase1 = loadKnowledgeBase(kbconf, "test_CEP_AssertBehaviorOnEntryPoints.drl");
    final KieSession ksession1 = kbase1.newKieSession();
    AgendaEventListener ael1 = mock(AgendaEventListener.class);
    ksession1.addEventListener(ael1);
    EntryPoint ep1 = ksession1.getEntryPoint("stocktick stream");
    FactHandle fh1 = ep1.insert(st1);
    FactHandle fh1_2 = ep1.insert(st1);
    FactHandle fh2 = ep1.insert(st2);
    FactHandle fh3 = ep1.insert(st3);
    assertSame(fh1, fh1_2);
    assertSame(fh1, fh2);
    assertNotSame(fh1, fh3);
    ksession1.fireAllRules();
    // must have fired 2 times, one for each event equality
    verify(ael1, times(2)).afterMatchFired(any(AfterMatchFiredEvent.class));
    ksession1.dispose();
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) StockTickInterface(org.drools.compiler.StockTickInterface) StockTick(org.drools.compiler.StockTick) InternalFactHandle(org.drools.core.common.InternalFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) KieBase(org.kie.api.KieBase) DefaultAgendaEventListener(org.kie.api.event.rule.DefaultAgendaEventListener) AgendaEventListener(org.kie.api.event.rule.AgendaEventListener) DebugAgendaEventListener(org.kie.api.event.rule.DebugAgendaEventListener) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) KieSession(org.kie.api.runtime.KieSession) AfterMatchFiredEvent(org.kie.api.event.rule.AfterMatchFiredEvent) Test(org.junit.Test)

Example 78 with KieBaseConfiguration

use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.

the class CepEspTest method testAfterOnArbitraryDates.

@Test(timeout = 10000)
public void testAfterOnArbitraryDates() throws Exception {
    // read in the source
    KieBaseConfiguration conf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    conf.setOption(EventProcessingOption.STREAM);
    final KieBase kbase = loadKnowledgeBase(conf, "test_CEP_AfterOperatorDates.drl");
    KieSessionConfiguration sconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    sconf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
    KieSession wm = createKnowledgeSession(kbase, sconf);
    final List<?> results = new ArrayList<Object>();
    wm.setGlobal("results", results);
    StockTickInterface tick1 = new StockTick(1, "DROO", 50, // arbitrary timestamp
    100000, 3);
    StockTickInterface tick2 = new StockTick(2, "ACME", 10, // 4 seconds after DROO
    104000, 3);
    InternalFactHandle handle2 = (InternalFactHandle) wm.insert(tick2);
    InternalFactHandle handle1 = (InternalFactHandle) wm.insert(tick1);
    assertNotNull(handle1);
    assertNotNull(handle2);
    assertTrue(handle1.isEvent());
    assertTrue(handle2.isEvent());
    // wm  = SerializationHelper.serializeObject(wm);
    wm.fireAllRules();
    assertEquals(4, results.size());
    assertEquals(tick1, results.get(0));
    assertEquals(tick2, results.get(1));
    assertEquals(tick1, results.get(2));
    assertEquals(tick2, results.get(3));
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) StockTickInterface(org.drools.compiler.StockTickInterface) StockTick(org.drools.compiler.StockTick) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) InternalFactHandle(org.drools.core.common.InternalFactHandle) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) Test(org.junit.Test)

Example 79 with KieBaseConfiguration

use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.

the class AnnotationsTest method testRuleAnnotation.

@Test
public void testRuleAnnotation() {
    String drl = "package org.drools.compiler.integrationtests\n" + "import " + Person.class.getCanonicalName() + "; \n" + "rule X\n" + "    @author(\"John Doe\")\n" + // backward compatibility
    "    @output(Hello World!)\n" + "    @value( 10 + 10 )\n" + "    @alt( \"Hello \"+\"World!\" )\n" + "when\n" + "    Person()\n" + "then\n" + "end";
    KieBaseConfiguration conf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    conf.setOption(EventProcessingOption.STREAM);
    conf.setOption(MBeansOption.ENABLED);
    KieBase kbase = loadKnowledgeBase("kb1", drl, conf);
    Rule rule = kbase.getRule("org.drools.compiler.integrationtests", "X");
    assertEquals("John Doe", rule.getMetaData().get("author"));
    assertEquals("Hello World!", rule.getMetaData().get("output"));
    assertEquals(20, ((Number) rule.getMetaData().get("value")).intValue());
    assertEquals("Hello World!", rule.getMetaData().get("alt"));
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) KieBase(org.kie.api.KieBase) Rule(org.kie.api.definition.rule.Rule) Person(org.drools.compiler.Person) Test(org.junit.Test)

Example 80 with KieBaseConfiguration

use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.

the class FactHandleMarshallingTest method createKnowledgeBase.

private InternalKnowledgeBase createKnowledgeBase() {
    KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    config.setOption(EventProcessingOption.STREAM);
    return (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(config);
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase)

Aggregations

KieBaseConfiguration (org.kie.api.KieBaseConfiguration)124 Test (org.junit.Test)94 KieSession (org.kie.api.runtime.KieSession)77 KieBase (org.kie.api.KieBase)69 ArrayList (java.util.ArrayList)54 List (java.util.List)38 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)25 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)23 FactHandle (org.kie.api.runtime.rule.FactHandle)21 EntryPoint (org.kie.api.runtime.rule.EntryPoint)18 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)16 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)16 InternalFactHandle (org.drools.core.common.InternalFactHandle)15 StockTick (org.drools.compiler.StockTick)11 KieContainer (org.kie.api.runtime.KieContainer)11 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)11 Match (org.kie.api.runtime.rule.Match)10 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)9 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)8 BuildContext (org.drools.core.reteoo.builder.BuildContext)7