Search in sources :

Example 46 with InternalFactHandle

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());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) InternalFactHandle(org.drools.core.common.InternalFactHandle) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 47 with InternalFactHandle

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;
}
Also used : PhreakPropagationContext(org.drools.core.common.PhreakPropagationContext) InternalFactHandle(org.drools.core.common.InternalFactHandle) RightTuple(org.drools.core.reteoo.RightTuple)

Example 48 with InternalFactHandle

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;
}
Also used : ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Man(org.drools.compiler.oopath.model.Man) InternalFactHandle(org.drools.core.common.InternalFactHandle) Child(org.drools.compiler.oopath.model.Child)

Example 49 with InternalFactHandle

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;
}
Also used : ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Man(org.drools.compiler.oopath.model.Man) InternalFactHandle(org.drools.core.common.InternalFactHandle) Child(org.drools.compiler.oopath.model.Child)

Example 50 with InternalFactHandle

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);
}
Also used : InternalFactHandle(org.drools.core.common.InternalFactHandle)

Aggregations

InternalFactHandle (org.drools.core.common.InternalFactHandle)182 Test (org.junit.Test)89 KieSession (org.kie.api.runtime.KieSession)66 ArrayList (java.util.ArrayList)63 List (java.util.List)41 KieBase (org.kie.api.KieBase)31 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)29 LeftTuple (org.drools.core.reteoo.LeftTuple)27 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)21 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)21 FactHandle (org.kie.api.runtime.rule.FactHandle)21 RightTuple (org.drools.core.reteoo.RightTuple)20 Declaration (org.drools.core.rule.Declaration)20 LeftTupleImpl (org.drools.core.reteoo.LeftTupleImpl)16 StockTickInterface (org.drools.compiler.StockTickInterface)15 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)15 RightTupleImpl (org.drools.core.reteoo.RightTupleImpl)15 StockTick (org.drools.compiler.StockTick)14 Cheese (org.drools.core.test.model.Cheese)14 KieBaseConfiguration (org.kie.api.KieBaseConfiguration)14