use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class KieContainerTest method testFileSystemResourceBuilding.
@Test
public void testFileSystemResourceBuilding() {
// DROOLS-2339
KieServices kieServices = KieServices.Factory.get();
KieResources kieResources = kieServices.getResources();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
File drlFile = new File("src/test/resources/org/drools/testcoverage/functional/parser/drl/asterisk-imports.drl");
kieFileSystem.write(kieResources.newFileSystemResource(drlFile, "UTF-8"));
KieModuleModel kmodel = kieServices.newKieModuleModel();
kieFileSystem.writeKModuleXML(kmodel.toXML());
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();
KieContainer kieContainer = kieServices.newKieContainer(kieBuilder.getKieModule().getReleaseId());
KieBaseConfiguration kieBaseConfiguration = kieServices.newKieBaseConfiguration();
KieBase kieBase = kieContainer.newKieBase(kieBaseConfiguration);
Assertions.assertThat(kieBase.getKiePackages()).isNotEmpty();
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class WaltzDbBenchmark method main.
public static void main(final String[] args) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("waltzdb.drl", WaltzDbBenchmark.class), ResourceType.DRL);
Collection<KiePackage> pkgs = kbuilder.getKnowledgePackages();
KieBaseConfiguration kbaseConfiguration = RuleBaseFactory.newKnowledgeBaseConfiguration();
kbaseConfiguration.setProperty("drools.removeIdentities", "true");
final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseConfiguration);
// final RuleBase ruleBase = RuleBaseFactory.newRuleBase( RuleBase.RETEOO,
// conf );
kbase.addPackages(pkgs);
KieSession ksession = kbase.newKieSession();
// 12,8,4
List<Line> lines = WaltzDbBenchmark.loadLines("waltzdb16.dat");
// 12,8,4
List<Label> labels = WaltzDbBenchmark.loadLabels("waltzdb16.dat");
long now = System.currentTimeMillis();
for (Line line : lines) {
ksession.insert(line);
System.out.println(line.getP1() + " " + line.getP2());
}
for (Label label : labels) {
ksession.insert(label);
System.out.println(label.getId() + " " + label.getType());
}
Stage stage = new Stage(Stage.DUPLICATE);
ksession.insert(stage);
ksession.fireAllRules();
System.out.println("Time: " + (System.currentTimeMillis() - now));
ksession.dispose();
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class CompositeAgendaTest method testCreateHaltDisposeAgenda.
@Test(timeout = 600_000)
public void testCreateHaltDisposeAgenda() {
final String drl = " import " + A.class.getCanonicalName() + ";\n" + " declare A @role( event ) end\n" + " global java.util.concurrent.atomic.LongAdder firings;\n" + " rule R0 when\n" + " A( value > 0,$Aid: id )\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R1 when\n" + " A(value > 1)\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R2 when\n" + " A(value > 2)\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R3 when\n" + " A(value > 3)\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R4 when\n" + " A(value > 4)\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R5 when\n" + " A(value > 5)\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R6 when\n" + " A(value > 6)\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R7 when\n" + " A(value > 7)\n" + " then\n" + " firings.add(1);\n" + " end";
final KieBaseConfiguration kieBaseConfiguration = KieBaseTestConfiguration.STREAM_IDENTITY.getKieBaseConfiguration();
kieBaseConfiguration.setOption(MultithreadEvaluationOption.YES);
final KieBase kieBase = new KieHelper().addContent(drl, ResourceType.DRL).build(kieBaseConfiguration);
final KieSession kieSession = kieBase.newKieSession();
final LongAdder firingCounter = new LongAdder();
kieSession.setGlobal("firings", firingCounter);
final ExecutorService executor = Executors.newFixedThreadPool(2);
executor.submit((Runnable) kieSession::fireUntilHalt);
try {
final EventInsertThread eventInsertThread = new EventInsertThread(kieSession);
executor.submit(eventInsertThread);
try {
Thread.sleep(5000);
} catch (final InterruptedException e) {
e.printStackTrace();
}
eventInsertThread.setActive(false);
} finally {
try {
// This may hit GC overhead limit exceeded
kieSession.halt();
} catch (Throwable th) {
th.printStackTrace();
throw th;
} finally {
kieSession.dispose();
executor.shutdown();
try {
if (!executor.awaitTermination(10, TimeUnit.MILLISECONDS)) {
executor.shutdownNow();
}
} catch (final InterruptedException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
}
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class MarshallingTest method testMarshallEntryPointsWithNot.
@Test
public void testMarshallEntryPointsWithNot() throws Exception {
String str = "package org.domain.test \n" + "import " + getClass().getCanonicalName() + ".*\n" + "global java.util.List list\n" + "declare A\n" + " @role( event )\n" + " @expires( 10m )\n" + "end\n" + "declare B\n" + "" + " @role( event )\n" + " @expires( 10m )\n" + "end\n" + "" + "rule a1\n" + "when\n" + " $a : A() from entry-point 'a-ep'\n" + " not B( this after[0s, 10s] $a) from entry-point 'a-ep'\n" + "then\n" + "list.add( $a );" + "end\n";
KieBaseConfiguration config = RuleBaseFactory.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM);
KieBase kBase = loadKnowledgeBaseFromString(config, str);
KieSessionConfiguration ksconf = RuleBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.PSEUDO);
ksconf.setOption(TimerJobFactoryOption.get("trackable"));
KieSession ksession = kBase.newKieSession(ksconf, null);
List list = new ArrayList();
ksession.setGlobal("list", list);
EntryPoint aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
PseudoClockScheduler timeService = (PseudoClockScheduler) ksession.<SessionClock>getSessionClock();
timeService.advanceTime(3, TimeUnit.SECONDS);
ksession = marsallStatefulKnowledgeSession(ksession);
ksession.fireAllRules();
ksession = marsallStatefulKnowledgeSession(ksession);
assertEquals(0, list.size());
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class MarshallingTest method testMarshallEntryPointsWithSlidingLengthWindow.
@Test
public void testMarshallEntryPointsWithSlidingLengthWindow() throws Exception {
String str = "package org.domain.test \n" + "import " + getClass().getCanonicalName() + ".*\n" + "import java.util.List\n" + "global java.util.List list\n" + "declare A\n" + " @role( event )\n" + " @expires( 10m )\n" + "end\n" + "declare B\n" + "" + " @role( event )\n" + " @expires( 10m )\n" + "end\n" + "" + "rule a1\n" + "when\n" + " $l : List() from collect( A() over window:length(3) from entry-point 'a-ep') \n" + "then\n" + " list.add( $l );" + "end\n";
KieBaseConfiguration conf = RuleBaseFactory.newKnowledgeBaseConfiguration();
conf.setOption(EventProcessingOption.STREAM);
final KieBase kbase = loadKnowledgeBaseFromString(conf, str);
KieSessionConfiguration ksconf = RuleBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.PSEUDO);
ksconf.setOption(TimerJobFactoryOption.get("trackable"));
KieSession ksession = createKnowledgeSession(kbase, ksconf);
List list = new ArrayList();
ksession.setGlobal("list", list);
EntryPoint aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
list.clear();
ksession.fireAllRules();
ksession = marsallStatefulKnowledgeSession(ksession);
assertEquals(2, ((List) list.get(0)).size());
aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
list.clear();
ksession.fireAllRules();
ksession = marsallStatefulKnowledgeSession(ksession);
assertEquals(3, ((List) list.get(0)).size());
}
Aggregations