use of org.drools.mvel.compiler.oopath.model.Man in project drools by kiegroup.
the class OOPathBenchmarkTest method insertFullModel.
private static List<InternalFactHandle> insertFullModel(KieSession ksession, List<Man> model) {
final List<InternalFactHandle> toBeModified = new ArrayList<InternalFactHandle>();
for (Man man : model) {
ksession.insert(man);
ksession.insert(man.getWife());
for (Child child : man.getWife().getChildren()) {
final InternalFactHandle fh = (InternalFactHandle) ksession.insert(child);
if (child.getAge() == 10) {
toBeModified.add(fh);
}
for (Toy toy : child.getToys()) {
ksession.insert(toy);
}
}
}
return toBeModified;
}
use of org.drools.mvel.compiler.oopath.model.Man in project drools by kiegroup.
the class OOPathBenchmarkTest method testRelational.
public static long[] testRelational(KieBase kbase, int n) {
final long[] result = new long[2];
final KieSession ksession = kbase.newKieSession();
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
final List<Man> model = generateModel(n);
final List<Child> toBeModified = getChildToBeModified(model);
long start = System.nanoTime();
final List<InternalFactHandle> fhs = insertFullModel(ksession, model);
ksession.fireAllRules();
result[0] = System.nanoTime() - start;
list.clear();
start = System.nanoTime();
for (Child child : toBeModified) {
child.setAge(11);
}
for (InternalFactHandle fh : fhs) {
ksession.update(fh, fh.getObject());
}
ksession.fireAllRules();
result[1] = System.nanoTime() - start;
Assertions.assertThat(n).isEqualTo(list.size());
ksession.dispose();
return result;
}
use of org.drools.mvel.compiler.oopath.model.Man in project drools by kiegroup.
the class OOPathBenchmarkTest method testFrom.
public static long[] testFrom(KieBase kbase, int n) {
final long[] result = new long[2];
final KieSession ksession = kbase.newKieSession();
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
final List<Man> model = generateModel(n);
final List<Child> toBeModified = getChildToBeModified(model);
long start = System.nanoTime();
final List<InternalFactHandle> fhs = insertModel(ksession, model);
ksession.fireAllRules();
result[0] = System.nanoTime() - start;
list.clear();
start = System.nanoTime();
for (Child child : toBeModified) {
child.setAge(11);
}
for (InternalFactHandle fh : fhs) {
ksession.update(fh, fh.getObject());
}
ksession.fireAllRules();
result[1] = System.nanoTime() - start;
Assertions.assertThat(n * 3).isEqualTo(list.size());
ksession.dispose();
return result;
}
use of org.drools.mvel.compiler.oopath.model.Man in project drools by kiegroup.
the class OOPathBenchmarkTest method testOOPath.
public static long[] testOOPath(KieBase kbase, int n) {
final long[] result = new long[2];
final KieSession ksession = kbase.newKieSession();
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
final List<Man> model = generateModel(n);
final List<Child> toBeModified = getChildToBeModified(model);
long start = System.nanoTime();
insertModel(ksession, model);
ksession.fireAllRules();
result[0] = System.nanoTime() - start;
list.clear();
start = System.nanoTime();
for (Child child : toBeModified) {
child.setAge(11);
}
ksession.fireAllRules();
result[1] = System.nanoTime() - start;
Assertions.assertThat(n).isEqualTo(list.size());
ksession.dispose();
return result;
}
use of org.drools.mvel.compiler.oopath.model.Man in project drools by kiegroup.
the class OOPathTest method testWithExists.
@Test
public void testWithExists() {
String header = "import org.drools.mvel.compiler.oopath.model.*;\n" + "global java.util.List list\n\n";
String drl1 = "rule R1 when\n" + " exists( Man( $m: /wife[age == 25] ) )\n" + "then\n" + " list.add(\"Found\");\n" + "end\n\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, header + drl1);
KieSession ksession = kbase.newKieSession();
final List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
final Man bob = new Man("John", 25);
bob.setWife(new Woman("Jane", 25));
ksession.insert(bob);
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("Found", list.get(0));
list.clear();
}
Aggregations