Search in sources :

Example 86 with KieHelper

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);
    }
}
Also used : EntryPointNode(org.drools.core.reteoo.EntryPointNode) Rete(org.drools.core.reteoo.Rete) KieHelper(org.kie.internal.utils.KieHelper) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase)

Example 87 with KieHelper

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);
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieHelper(org.kie.internal.utils.KieHelper) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 88 with KieHelper

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());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) DebugList(org.drools.compiler.util.debug.DebugList) Test(org.junit.Test)

Example 89 with KieHelper

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);
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieHelper(org.kie.internal.utils.KieHelper) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 90 with KieHelper

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());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Aggregations

KieHelper (org.kie.internal.utils.KieHelper)467 Test (org.junit.Test)427 KieSession (org.kie.api.runtime.KieSession)355 ArrayList (java.util.ArrayList)194 KieBase (org.kie.api.KieBase)152 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)77 Person (org.drools.compiler.Person)61 FactHandle (org.kie.api.runtime.rule.FactHandle)55 List (java.util.List)44 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)41 RuleUnitExecutor (org.kie.api.runtime.rule.RuleUnitExecutor)38 InternalRuleUnitExecutor (org.drools.core.impl.InternalRuleUnitExecutor)37 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)34 Man (org.drools.compiler.oopath.model.Man)29 Child (org.drools.compiler.oopath.model.Child)24 Woman (org.drools.compiler.oopath.model.Woman)23 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)23 InternalFactHandle (org.drools.core.common.InternalFactHandle)18 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)18 PseudoClockScheduler (org.drools.core.time.impl.PseudoClockScheduler)18