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());
}
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());
}
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;
}
};
}
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());
}
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());
}
Aggregations