use of org.drools.mvel.compiler.oopath.model.Child 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.Child 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.Child in project drools by kiegroup.
the class OOPathTest method testBackReferenceConstraint.
@Test
public void testBackReferenceConstraint() {
final String drl = "import org.drools.mvel.compiler.oopath.model.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + " Man( $toy: /wife/children/toys[ name.length == ../name.length ] )\n" + "then\n" + " list.add( $toy.getName() );\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession ksession = kbase.newKieSession();
final List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
final Woman alice = new Woman("Alice", 38);
final Man bob = new Man("Bob", 40);
bob.setWife(alice);
final Child charlie = new Child("Carl", 12);
final Child debbie = new Child("Debbie", 8);
alice.addChild(charlie);
alice.addChild(debbie);
charlie.addToy(new Toy("car"));
charlie.addToy(new Toy("ball"));
debbie.addToy(new Toy("doll"));
debbie.addToy(new Toy("guitar"));
ksession.insert(bob);
ksession.fireAllRules();
Assertions.assertThat(list).containsExactlyInAnyOrder("ball", "guitar");
}
use of org.drools.mvel.compiler.oopath.model.Child in project drools by kiegroup.
the class OOPathTest method testNotReactivePeer.
@Test
public void testNotReactivePeer() {
// DROOLS-1727
String drl1 = "import org.drools.mvel.compiler.oopath.model.*;\n" + "global java.util.List list\n\n" + "rule R1 when\n" + " not String()\n" + " $a : Man( name == \"Mario\" )\n" + "then\n" + " list.add(\"Found\");\n" + " insert($a.getName());\n" + "end\n\n" + "rule R2 when\n" + " not String()\n" + " $a : Man( $c: /children[age == 6], name == \"Mario\" )\n" + "then\n" + " list.add(\"Found\");\n" + " insert($a.getName());\n" + "end\n\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl1);
KieSession ksession = kbase.newKieSession();
List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
Man mario = new Man("Mario", 40);
mario.addChild(new Child("Sofia", 6));
ksession.insert(mario);
ksession.fireAllRules();
assertEquals(1, list.size());
}
use of org.drools.mvel.compiler.oopath.model.Child in project drools by kiegroup.
the class OOPathTest method testIndexedAccess.
@Test
public void testIndexedAccess() {
final String drl = "import org.drools.mvel.compiler.oopath.model.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + " Man( $toy: /wife/children[0]/toys[1] )\n" + "then\n" + " list.add( $toy.getName() );\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession ksession = kbase.newKieSession();
final List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
final Woman alice = new Woman("Alice", 38);
final Man bob = new Man("Bob", 40);
bob.setWife(alice);
final Child charlie = new Child("Charles", 12);
final Child debbie = new Child("Debbie", 11);
alice.addChild(charlie);
alice.addChild(debbie);
charlie.addToy(new Toy("car"));
charlie.addToy(new Toy("ball"));
debbie.addToy(new Toy("doll"));
ksession.insert(bob);
ksession.fireAllRules();
Assertions.assertThat(list).containsExactlyInAnyOrder("ball");
}
Aggregations