use of org.drools.mvel.compiler.util.debug.DebugList in project drools by kiegroup.
the class ParallelEvaluationTest method testFireUntilHaltWithAsyncInsert.
@Test(timeout = 40000L)
public void testFireUntilHaltWithAsyncInsert() {
StringBuilder sb = new StringBuilder(400);
sb.append("global java.util.List list;\n");
for (int i = 0; i < 10; i++) {
sb.append(getRule(i, ""));
}
final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", kieBaseTestConfiguration, sb.toString());
final KieBase kbase = KieBaseUtil.newKieBaseFromKieModuleWithAdditionalOptions(kieModule, kieBaseTestConfiguration, MultithreadEvaluationOption.YES);
KieSession ksession = kbase.newKieSession();
assertTrue(((InternalWorkingMemory) ksession).getAgenda().isParallelAgenda());
StatefulKnowledgeSessionImpl session = (StatefulKnowledgeSessionImpl) ksession;
CountDownLatch done = new CountDownLatch(1);
DebugList<Integer> list = new DebugList<Integer>();
list.onItemAdded = (l -> {
if (l.size() == 10) {
ksession.halt();
done.countDown();
}
});
ksession.setGlobal("list", list);
new Thread(ksession::fireUntilHalt).start();
try {
for (int i = 0; i < 10; i++) {
session.insertAsync(i);
session.insertAsync("" + i);
}
try {
done.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
assertEquals(10, list.size());
} finally {
ksession.halt();
ksession.dispose();
}
}
use of org.drools.mvel.compiler.util.debug.DebugList in project drools by kiegroup.
the class ParallelEvaluationTest method getMultipleParallelKieSessionsWithUpdatesCallable.
private Callable<Void> getMultipleParallelKieSessionsWithUpdatesCallable(KieBase kBase) {
return new Callable<Void>() {
@Override
public Void call() {
KieSession ksession = kBase.newKieSession();
assertThat(((InternalWorkingMemory) ksession).getAgenda().isParallelAgenda()).as("Parallel agenda has to be enabled").isTrue();
List<Integer> list = new DebugList<Integer>();
ksession.setGlobal("list", list);
FactHandle[] fhs = new FactHandle[10];
fhs = insertFacts(ksession, 10);
ksession.fireAllRules();
assertThat(list.size()).isEqualTo(10);
list.clear();
for (int i = 0; i < 10; i++) {
ksession.update(fhs[i], i);
}
ksession.fireAllRules();
assertThat(list.size()).isEqualTo(10);
return null;
}
};
}
use of org.drools.mvel.compiler.util.debug.DebugList in project drools by kiegroup.
the class ParallelEvaluationTest method testWithDeletes.
@Test(timeout = 40000L)
public void testWithDeletes() {
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));
}
final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", kieBaseTestConfiguration, sb.toString());
final KieBase kbase = KieBaseUtil.newKieBaseFromKieModuleWithAdditionalOptions(kieModule, kieBaseTestConfiguration, MultithreadEvaluationOption.YES);
KieSession ksession = kbase.newKieSession();
assertTrue(((InternalWorkingMemory) ksession).getAgenda().isParallelAgenda());
List<Integer> list = new DebugList<Integer>();
ksession.setGlobal("list", list);
for (int i = 1; i < 11; i++) {
ksession.insert(i);
ksession.insert("" + i);
}
ksession.fireAllRules();
assertEquals(20, list.size());
}
use of org.drools.mvel.compiler.util.debug.DebugList in project drools by kiegroup.
the class ParallelEvaluationTest method testDisableParallelismWithAgendaGroups.
@Test(timeout = 40000L)
public void testDisableParallelismWithAgendaGroups() {
StringBuilder sb = new StringBuilder(400);
sb.append("global java.util.List list;\n");
sb.append("rule first\n" + "when\n" + "then\n" + " drools.getKnowledgeRuntime().getAgenda().getAgendaGroup(\"agenda\").setFocus();\n" + "end\n");
for (int i = 0; i < 10; i++) {
sb.append(getRule(i, "", "agenda-group \"agenda\""));
}
final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", kieBaseTestConfiguration, sb.toString());
final KieBase kbase = KieBaseUtil.newKieBaseFromKieModuleWithAdditionalOptions(kieModule, kieBaseTestConfiguration, MultithreadEvaluationOption.YES);
KieSession ksession = kbase.newKieSession();
// multithread evaluation is not allowed when using agenda-groups
assertFalse(((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(10, list.size());
}
use of org.drools.mvel.compiler.util.debug.DebugList in project drools by kiegroup.
the class ParallelEvaluationTest method testWithInsertions.
@Test(timeout = 40000L)
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"));
}
final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", kieBaseTestConfiguration, sb.toString());
final KieBase kbase = KieBaseUtil.newKieBaseFromKieModuleWithAdditionalOptions(kieModule, kieBaseTestConfiguration, MultithreadEvaluationOption.YES);
KieSession ksession = kbase.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());
}
Aggregations