use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class NodesPartitioningTest method checkDrl.
private void checkDrl(String drl) {
InternalKnowledgeBase kbase = (InternalKnowledgeBase) new KieHelper().addContent(drl, ResourceType.DRL).build(MultithreadEvaluationOption.YES);
Rete rete = kbase.getRete();
for (EntryPointNode entryPointNode : rete.getEntryPointNodes().values()) {
traverse(entryPointNode);
}
}
use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class ParallelEvaluationTest method testMultipleParallelKieSessionsWithUpdates.
@Test(timeout = 10000L)
public void testMultipleParallelKieSessionsWithUpdates() throws InterruptedException, ExecutionException, TimeoutException {
final int NUMBER_OF_PARALLEL_SESSIONS = 5;
/* Create KIE base */
StringBuilder sb = new StringBuilder(400);
sb.append("global java.util.List list;\n");
for (int i = 0; i < 10; i++) {
sb.append(getRule(i, ""));
}
KieBase kBase = new KieHelper().addContent(sb.toString(), ResourceType.DRL).build(MultithreadEvaluationOption.YES);
/* Create parallel tasks */
List<Callable<Void>> tasks = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_PARALLEL_SESSIONS; i++) {
tasks.add(getMultipleParallelKieSessionsWithUpdatesCallable(kBase));
}
/* Run tasks in parallel */
runTasksInParallel(tasks);
}
use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class ParallelEvaluationTest method testWithInsertions.
@Test(timeout = 10000L)
public void testWithInsertions() {
StringBuilder sb = new StringBuilder(4000);
sb.append("global java.util.List list;\n");
int ruleNr = 200;
for (int i = 0; i < ruleNr; i++) {
sb.append(getRule(i, "insert( $i + 10 );\ninsert( \"\" + ($i + 10) );\n"));
}
KieSession ksession = new KieHelper().addContent(sb.toString(), ResourceType.DRL).build(MultithreadEvaluationOption.YES).newKieSession();
assertTrue(((InternalWorkingMemory) ksession).getAgenda().isParallelAgenda());
List<Integer> list = new DebugList<Integer>();
ksession.setGlobal("list", list);
for (int i = 0; i < 10; i++) {
ksession.insert(i);
ksession.insert("" + i);
}
ksession.fireAllRules();
assertEquals(ruleNr, list.size());
}
use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class ParallelEvaluationTest method testMultipleParallelKieSessionsWithDeletes.
@Test(timeout = 10000L)
public void testMultipleParallelKieSessionsWithDeletes() throws InterruptedException, ExecutionException, TimeoutException {
final int NUMBER_OF_PARALLEL_SESSIONS = 5;
/* Create KIE base */
StringBuilder sb = new StringBuilder(400);
sb.append("global java.util.List list;\n");
for (int i = 1; i < 11; i++) {
sb.append(getRule(i, "delete( $i );\n"));
}
for (int i = 1; i < 11; i++) {
sb.append(getNotRule(i));
}
KieBase kbase = new KieHelper().addContent(sb.toString(), ResourceType.DRL).build(MultithreadEvaluationOption.YES);
List<Callable<Void>> tasks = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_PARALLEL_SESSIONS; i++) {
tasks.add(getMultipleParallelKieSessionsWithDeletesCallable(kbase));
}
/* Run tasks in parallel */
runTasksInParallel(tasks);
}
use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class ParallelEvaluationTest method testDisableParallelismOnSinglePartition.
@Test(timeout = 10000L)
public void testDisableParallelismOnSinglePartition() {
String drl = "rule R1 when\n" + " $i : Integer( this == 4 )" + " String( length > $i )\n" + "then end \n" + "rule R2 when\n" + " $i : Integer( this == 4 )" + " String( length == $i )\n" + "then end \n" + "rule R3 when\n" + " $i : Integer( this == 4 )" + " String( length < $i )\n" + "then end \n";
KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build(MultithreadEvaluationOption.YES).newKieSession();
InternalWorkingMemory session = (InternalWorkingMemory) ksession;
// since there is only one partition the multithread evaluation should be disabled and run with the DefaultAgenda
assertFalse(((InternalWorkingMemory) ksession).getAgenda().isParallelAgenda());
}
Aggregations