use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class RemoveRuleTest method testPopulatedMultipleSharesRemoveLast.
@Test
public void testPopulatedMultipleSharesRemoveLast() throws Exception {
InternalKnowledgeBase kbase1 = buildKnowledgeBase("r1", " A(1;) A(2;) B(1;) B(2;) C(1;) D() E()\n");
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase1.newKieSession());
List list = new ArrayList();
wm.setGlobal("list", list);
InternalFactHandle fh1 = (InternalFactHandle) wm.insert(new A(1));
InternalFactHandle fh2 = (InternalFactHandle) wm.insert(new A(2));
InternalFactHandle fh3 = (InternalFactHandle) wm.insert(new A(2));
InternalFactHandle fh4 = (InternalFactHandle) wm.insert(new A(3));
InternalFactHandle fh5 = (InternalFactHandle) wm.insert(new B(1));
InternalFactHandle fh6 = (InternalFactHandle) wm.insert(new B(2));
InternalFactHandle fh7 = (InternalFactHandle) wm.insert(new C(1));
InternalFactHandle fh8 = (InternalFactHandle) wm.insert(new C(2));
InternalFactHandle fh9 = (InternalFactHandle) wm.insert(new D(1));
InternalFactHandle fh10 = (InternalFactHandle) wm.insert(new E(1));
wm.fireAllRules();
assertEquals(2, list.size());
kbase1.addPackages(buildKnowledgePackage("r2", " A(1;) A(2;) B(1;) B(2;) C(2;) D() E()\n"));
kbase1.addPackages(buildKnowledgePackage("r3", " A(1;) A(3;) B(1;) B(2;) C(2;) D() E()\n"));
wm.fireAllRules();
assertEquals(5, list.size());
kbase1.removeRule("org.kie", "r3");
list.clear();
wm.update(fh1, fh1.getObject());
wm.update(fh2, fh2.getObject());
wm.update(fh3, fh3.getObject());
wm.update(fh4, fh4.getObject());
wm.update(fh5, fh5.getObject());
wm.update(fh6, fh6.getObject());
wm.update(fh7, fh7.getObject());
wm.update(fh8, fh8.getObject());
wm.update(fh9, fh9.getObject());
wm.update(fh10, fh10.getObject());
wm.fireAllRules();
assertEquals(4, list.size());
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class RightBuilder method update.
public RightBuilder update(Object... objects) {
for (Object object : objects) {
InternalFactHandle fh = (InternalFactHandle) wm.insert(object);
RightTuple rightTuple = fh.getFirstRightTuple();
rightTuple.setPropagationContext(new PhreakPropagationContext());
rightTuples.addUpdate(rightTuple);
}
return this;
}
use of org.drools.core.common.InternalFactHandle 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.core.common.InternalFactHandle 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.core.common.InternalFactHandle in project drools by kiegroup.
the class JTMSBeliefSystem method stage.
public void stage(PropagationContext context, BeliefSet<M> beliefSet) {
InternalFactHandle bfh = beliefSet.getFactHandle();
// Remove the FH from the network
ep.delete(bfh, bfh.getObject(), getObjectTypeConf(beliefSet), context.getRuleOrigin(), null);
}
Aggregations