Search in sources :

Example 6 with DebugList

use of org.drools.mvel.compiler.util.debug.DebugList in project drools by kiegroup.

the class ParallelEvaluationTest method testWithAsyncInsertions.

@Test(timeout = 40000L)
public void testWithAsyncInsertions() {
    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, "insertAsync( $i + 10 );\ninsertAsync( \"\" + ($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());
    StatefulKnowledgeSessionImpl session = (StatefulKnowledgeSessionImpl) ksession;
    List<Integer> list = new DebugList<Integer>();
    ksession.setGlobal("list", list);
    for (int i = 0; i < 10; i++) {
        session.insertAsync(i);
        session.insertAsync("" + i);
    }
    ksession.fireAllRules();
    assertEquals(ruleNr, list.size());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KieBase(org.kie.api.KieBase) StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) KieSession(org.kie.api.runtime.KieSession) DebugList(org.drools.mvel.compiler.util.debug.DebugList) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 7 with DebugList

use of org.drools.mvel.compiler.util.debug.DebugList in project drools by kiegroup.

the class ParallelEvaluationTest method testImmediateEventsExpiration.

@Test(timeout = 40000L)
public void testImmediateEventsExpiration() {
    StringBuilder sb = new StringBuilder(400);
    sb.append("global java.util.List list;\n");
    sb.append("import " + MyEvent.class.getCanonicalName() + ";\n");
    sb.append("declare MyEvent @role( event ) @expires( 1ms ) @timestamp( timestamp ) end\n");
    for (int i = 0; i < 10; i++) {
        sb.append(getRuleWithEvent(i));
    }
    KieSessionConfiguration sessionConfig = RuleBaseFactory.newKnowledgeSessionConfiguration();
    KieBaseTestConfiguration streamConfig = TestParametersUtil.getStreamInstanceOf(kieBaseTestConfiguration);
    final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", streamConfig, sb.toString());
    final KieBase kbase = KieBaseUtil.newKieBaseFromKieModuleWithAdditionalOptions(kieModule, streamConfig, MultithreadEvaluationOption.YES);
    KieSession ksession = kbase.newKieSession(sessionConfig, null);
    assertTrue(((InternalWorkingMemory) ksession).getAgenda().isParallelAgenda());
    List<Integer> list = new DebugList<Integer>();
    ksession.setGlobal("list", list);
    for (int i = 0; i < 10; i++) {
        ksession.insert(new MyEvent(i, i * 2L));
    }
    ksession.fireAllRules();
    assertEquals(10, list.size());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KieBase(org.kie.api.KieBase) KieBaseTestConfiguration(org.drools.testcoverage.common.util.KieBaseTestConfiguration) KieSession(org.kie.api.runtime.KieSession) DebugList(org.drools.mvel.compiler.util.debug.DebugList) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 8 with DebugList

use of org.drools.mvel.compiler.util.debug.DebugList in project drools by kiegroup.

the class ParallelEvaluationTest method getMultipleParallelKieSessionsWithDeletesCallable.

private Callable<Void> getMultipleParallelKieSessionsWithDeletesCallable(KieBase kbase) {
    return new Callable<Void>() {

        @Override
        public Void call() {
            KieSession ksession = kbase.newKieSession();
            assertThat(((InternalWorkingMemory) ksession).getAgenda().isParallelAgenda()).isTrue();
            List<Integer> list = new DebugList<Integer>();
            ksession.setGlobal("list", list);
            insertFacts(ksession, 11);
            ksession.fireAllRules();
            assertThat(ksession.getObjects()).isEmpty();
            assertThat(list.size()).isEqualTo(20);
            return null;
        }
    };
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KieSession(org.kie.api.runtime.KieSession) DebugList(org.drools.mvel.compiler.util.debug.DebugList) Callable(java.util.concurrent.Callable)

Example 9 with DebugList

use of org.drools.mvel.compiler.util.debug.DebugList in project drools by kiegroup.

the class ParallelEvaluationTest method test.

@Test(timeout = 40000L)
public void test() {
    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);
    EntryPointNode epn = ((InternalKnowledgeBase) kbase).getRete().getEntryPointNode(EntryPointId.DEFAULT);
    ObjectTypeNode otn = epn.getObjectTypeNodes().get(new ClassObjectType(Integer.class));
    assertTrue(((CompositePartitionAwareObjectSinkAdapter) otn.getObjectSinkPropagator()).isHashed());
    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(10, list.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) EntryPointNode(org.drools.core.reteoo.EntryPointNode) ClassObjectType(org.drools.core.base.ClassObjectType) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) KieSession(org.kie.api.runtime.KieSession) DebugList(org.drools.mvel.compiler.util.debug.DebugList) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 10 with DebugList

use of org.drools.mvel.compiler.util.debug.DebugList in project drools by kiegroup.

the class ParallelEvaluationTest method testEventsExpiration.

@Test(timeout = 40000L)
public void testEventsExpiration() {
    StringBuilder sb = new StringBuilder(400);
    sb.append("global java.util.List list;\n");
    sb.append("import " + MyEvent.class.getCanonicalName() + ";\n");
    sb.append("declare MyEvent @role( event ) @expires( 20ms ) @timestamp( timestamp ) end\n");
    for (int i = 0; i < 10; i++) {
        sb.append(getRuleWithEvent(i));
    }
    KieSessionConfiguration sessionConfig = RuleBaseFactory.newKnowledgeSessionConfiguration();
    sessionConfig.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
    KieBaseTestConfiguration streamConfig = TestParametersUtil.getStreamInstanceOf(kieBaseTestConfiguration);
    final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", streamConfig, sb.toString());
    final KieBase kbase = KieBaseUtil.newKieBaseFromKieModuleWithAdditionalOptions(kieModule, streamConfig, MultithreadEvaluationOption.YES);
    KieSession ksession = kbase.newKieSession(sessionConfig, null);
    assertTrue(((InternalWorkingMemory) ksession).getAgenda().isParallelAgenda());
    PseudoClockScheduler sessionClock = ksession.getSessionClock();
    sessionClock.setStartupTime(0);
    List<Integer> list = new DebugList<Integer>();
    ksession.setGlobal("list", list);
    for (int i = 0; i < 10; i++) {
        ksession.insert(new MyEvent(i, i * 2L));
    }
    ksession.fireAllRules();
    assertEquals(10, list.size());
    assertEquals(10L, ksession.getFactCount());
    sessionClock.advanceTime(29, TimeUnit.MILLISECONDS);
    ksession.fireAllRules();
    assertEquals(5L, ksession.getFactCount());
    sessionClock.advanceTime(12, TimeUnit.MILLISECONDS);
    ksession.fireAllRules();
    assertEquals(0L, ksession.getFactCount());
}
Also used : DebugList(org.drools.mvel.compiler.util.debug.DebugList) PseudoClockScheduler(org.drools.core.time.impl.PseudoClockScheduler) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KieBase(org.kie.api.KieBase) KieBaseTestConfiguration(org.drools.testcoverage.common.util.KieBaseTestConfiguration) KieSession(org.kie.api.runtime.KieSession) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 DebugList (org.drools.mvel.compiler.util.debug.DebugList)17 KieSession (org.kie.api.runtime.KieSession)17 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)16 Test (org.junit.Test)13 KieBase (org.kie.api.KieBase)13 KieModule (org.kie.api.builder.KieModule)13 Callable (java.util.concurrent.Callable)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 StatefulKnowledgeSessionImpl (org.drools.kiesession.session.StatefulKnowledgeSessionImpl)5 KieBaseTestConfiguration (org.drools.testcoverage.common.util.KieBaseTestConfiguration)5 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)5 FactHandle (org.kie.api.runtime.rule.FactHandle)5 ClassObjectType (org.drools.core.base.ClassObjectType)4 EntryPointNode (org.drools.core.reteoo.EntryPointNode)4 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)4 PseudoClockScheduler (org.drools.core.time.impl.PseudoClockScheduler)4 Ignore (org.junit.Ignore)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3