Search in sources :

Example 61 with KieBaseConfiguration

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

the class AbstractKieModule method getKnowledgeBaseConfiguration.

private KieBaseConfiguration getKnowledgeBaseConfiguration(KieBaseModelImpl kBaseModel, ClassLoader cl) {
    KieBaseConfiguration kbConf = RuleBaseFactory.newKnowledgeBaseConfiguration(null, cl);
    kbConf.setOption(kBaseModel.getEqualsBehavior());
    kbConf.setOption(kBaseModel.getEventProcessingMode());
    kbConf.setOption(kBaseModel.getDeclarativeAgenda());
    kbConf.setOption(kBaseModel.getSequential());
    kbConf.setOption(kBaseModel.getSessionsPool());
    return kbConf;
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration)

Example 62 with KieBaseConfiguration

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

the class RangeIndexANCTest method createKieBaseWithRangeIndexThresholdValue.

private KieBase createKieBaseWithRangeIndexThresholdValue(String drl, int rangeIndexThresholdValue) {
    final KieContainer kieContainer = getKieContainer(drl);
    final KieBaseConfiguration kieBaseConfiguration = KieServices.get().newKieBaseConfiguration();
    // for test convenience. Default value is AlphaRangeIndexThresholdOption.DEFAULT_VALUE
    kieBaseConfiguration.setOption(AlphaRangeIndexThresholdOption.get(rangeIndexThresholdValue));
    return kieContainer.newKieBase(kieBaseConfiguration);
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) KieContainer(org.kie.api.runtime.KieContainer)

Example 63 with KieBaseConfiguration

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

the class AccumulateTest method testAccumulatesExpireVsCancel.

@Test
public void testAccumulatesExpireVsCancel() throws Exception {
    // JBRULES-3201
    String drl = "package com.sample;\n" + "\n" + "global java.util.List list; \n" + "" + "declare FactTest\n" + " @role( event ) \n" + "end\n" + " \n" + "rule \"A500 test\"\n" + "when\n" + " accumulate (\n" + " $d : FactTest() over window:time(1m), $tot : count($d); $tot > 0 )\n" + "then\n" + " System.out.println( $tot ); \n" + " list.add( $tot.intValue() ); \n " + "end\n" + "\n";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(drl.getBytes()), ResourceType.DRL);
    assertFalse(kbuilder.hasErrors());
    KieBaseConfiguration kbConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kbConf.setOption(EventProcessingOption.STREAM);
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbConf);
    kbase.addPackages(kbuilder.getKnowledgePackages());
    KieSessionConfiguration ksConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    ksConf.setOption(ClockTypeOption.get("pseudo"));
    KieSession ksession = kbase.newKieSession(ksConf, null);
    ArrayList list = new ArrayList();
    ksession.setGlobal("list", list);
    FactType ft = kbase.getFactType("com.sample", "FactTest");
    ksession.insert(ft.newInstance());
    ksession.fireAllRules();
    ksession.insert(ft.newInstance());
    ksession.fireAllRules();
    ksession.insert(ft.newInstance());
    ksession.fireAllRules();
    SessionPseudoClock clock = ksession.getSessionClock();
    clock.advanceTime(1, TimeUnit.MINUTES);
    ksession.fireAllRules();
    assertFalse(list.contains(0));
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) FactType(org.kie.api.definition.type.FactType) Test(org.junit.Test)

Example 64 with KieBaseConfiguration

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

the class FailureOnRemovalTest method createKnowledgeBaseConfiguration.

private KieBaseConfiguration createKnowledgeBaseConfiguration(boolean shareBetaNodes) {
    KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kconf.setOption(SequentialOption.NO);
    kconf.setOption(ShareAlphaNodesOption.YES);
    kconf.setOption(shareBetaNodes ? ShareBetaNodesOption.YES : ShareBetaNodesOption.NO);
    return kconf;
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration)

Example 65 with KieBaseConfiguration

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

the class MVELTest method testMVELTypeCoercion.

@Test
public void testMVELTypeCoercion() {
    final String str = "package org.drools.compiler.test; \n" + "\n" + "global java.util.List list;" + "\n" + "declare Bean\n" + // NOTICE: THIS WORKS WHEN THE FIELD IS "LIST", BUT USED TO WORK WITH ARRAYLIST TOO
    "  field : java.util.ArrayList\n" + "end\n" + "\n" + "\n" + "rule \"Init\"\n" + "when  \n" + "then\n" + "  insert( new Bean( new java.util.ArrayList( java.util.Arrays.asList( \"x\" ) ) ) );\n" + "end\n" + "\n" + "rule \"Check\"\n" + "when\n" + "  $b : Bean( $fld : field == [\"x\"] )\n" + "then\n" + "  System.out.println( $fld );\n" + "  list.add( \"OK\" ); \n" + "end";
    final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
    if (kbuilder.hasErrors()) {
        fail(kbuilder.getErrors().toString());
    }
    final KieBaseConfiguration kbConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kbConf.setOption(EqualityBehaviorOption.EQUALITY);
    final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbConf);
    kbase.addPackages(kbuilder.getKnowledgePackages());
    final KieSession ksession = kbase.newKieSession();
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.fireAllRules();
    assertTrue(list.contains("OK"));
    ksession.dispose();
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) ArrayList(java.util.ArrayList) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

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