use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class ParallelEvaluationTest method testImmediateEventsExpiration.
@Test(timeout = 10000L)
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 = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
KieSession ksession = new KieHelper().addContent(sb.toString(), ResourceType.DRL).build(EventProcessingOption.STREAM, MultithreadEvaluationOption.YES).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.kie.internal.utils.KieHelper in project drools by kiegroup.
the class ParallelEvaluationTest method testFireUntilHalt.
@Test(timeout = 10000L)
public void testFireUntilHalt() {
StringBuilder sb = new StringBuilder(400);
sb.append("global java.util.List list;\n");
for (int i = 0; i < 10; i++) {
sb.append(getRule(i, ""));
}
KieSession ksession = new KieHelper().addContent(sb.toString(), ResourceType.DRL).build(MultithreadEvaluationOption.YES).newKieSession();
assertTrue(((InternalWorkingMemory) ksession).getAgenda().isParallelAgenda());
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();
for (int i = 0; i < 10; i++) {
ksession.insert(i);
ksession.insert("" + i);
}
try {
done.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
assertEquals(10, list.size());
}
use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class ParallelEvaluationTest method testWithDeletes.
@Test(timeout = 10000L)
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));
}
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 = 1; i < 11; i++) {
ksession.insert(i);
ksession.insert("" + i);
}
ksession.fireAllRules();
assertEquals(20, list.size());
}
use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class ParallelEvaluationTest method testWithUpdates.
@Test(timeout = 10000L)
public void testWithUpdates() {
StringBuilder sb = new StringBuilder(400);
sb.append("global java.util.List list;\n");
for (int i = 0; i < 10; i++) {
sb.append(getRule(i, ""));
}
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);
FactHandle[] fhs = new FactHandle[10];
for (int i = 0; i < 10; i++) {
fhs[i] = ksession.insert(i);
ksession.insert("" + i);
}
ksession.fireAllRules();
assertEquals(10, list.size());
list.clear();
for (int i = 0; i < 10; i++) {
ksession.update(fhs[i], i);
}
ksession.fireAllRules();
assertEquals(10, list.size());
}
use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class PassiveQueryTest method testPassiveQueryNoDataDriven.
@Test
public void testPassiveQueryNoDataDriven() throws Exception {
String str = "global java.util.List list\n" + "query Q (Integer i)\n" + " String( this == i.toString() )\n" + "end\n" + "rule R when\n" + " $i : Integer()\n" + " ?Q( $i; )\n" + "then\n" + " list.add( $i );\n" + "end\n";
KieSession ksession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession();
List<Integer> list = new ArrayList<Integer>();
ksession.setGlobal("list", list);
ksession.insert(1);
ksession.insert("1");
ksession.fireAllRules();
assertEquals(1, list.size());
}
Aggregations