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());
}
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();
}
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));
}
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"));
}
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);
}
Aggregations