Search in sources :

Example 1 with PhreakNodeFactory

use of org.drools.core.reteoo.builder.PhreakNodeFactory in project drools by kiegroup.

the class ReteooWorkingMemoryTest method testDifferentEntryPointsOnSameFact.

@Test
public void testDifferentEntryPointsOnSameFact() {
    // JBRULES-2971
    InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
    Rete rete = kBase.getRete();
    NodeFactory nFacotry = new PhreakNodeFactory();
    EntryPointNode epn = nFacotry.buildEntryPointNode(kBase.getReteooBuilder().getNodeIdsGenerator().getNextId(), RuleBasePartitionId.MAIN_PARTITION, kBase.getConfiguration().isMultithreadEvaluation(), rete, new EntryPointId("xxx"));
    kBase.getRete().addObjectSink(epn);
    KieSession ksession = kBase.newKieSession();
    FactHandle f1 = ksession.insert("f1");
    EntryPoint ep = ksession.getEntryPoint("xxx");
    try {
        ep.update(f1, "s1");
        fail("Should throw an exception");
    } catch (IllegalArgumentException e) {
    }
    try {
        ep.retract(f1);
        fail("Should throw an exception");
    } catch (IllegalArgumentException e) {
    }
    ksession.update(f1, "s1");
    assertNotNull(ksession.getObject(f1));
    ksession.retract(f1);
    ksession.retract(f1);
    assertNull(ksession.getObject(f1));
}
Also used : EntryPointNode(org.drools.core.reteoo.EntryPointNode) Rete(org.drools.core.reteoo.Rete) NodeFactory(org.drools.core.reteoo.builder.NodeFactory) PhreakNodeFactory(org.drools.core.reteoo.builder.PhreakNodeFactory) EntryPointId(org.drools.core.rule.EntryPointId) FactHandle(org.kie.api.runtime.rule.FactHandle) EntryPoint(org.kie.api.runtime.rule.EntryPoint) KieSession(org.kie.api.runtime.KieSession) PhreakNodeFactory(org.drools.core.reteoo.builder.PhreakNodeFactory) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Test(org.junit.Test)

Example 2 with PhreakNodeFactory

use of org.drools.core.reteoo.builder.PhreakNodeFactory in project drools by kiegroup.

the class AddRemoveTest method testAdd.

@Test
public void testAdd() {
    /*
         * create a RuleBase with a single ObjectTypeNode we attach a
         * MockObjectSink so we can detect assertions and retractions
         */
    InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
    BuildContext context = new BuildContext(kBase, Collections.emptyList());
    NodeFactory nFacotry = new PhreakNodeFactory();
    EntryPointNode entryPoint = context.getRuleBase().getRete().getEntryPointNodes().values().iterator().next();
    final ObjectTypeNode objectTypeNode = nFacotry.buildObjectTypeNode(0, entryPoint, new ClassObjectType(Object.class), context);
    objectTypeNode.attach(context);
    final MockObjectSink sink = new MockObjectSink();
    objectTypeNode.addObjectSink(sink);
    kBase.newKieSession();
// objectTypeNode.
}
Also used : EntryPointNode(org.drools.core.reteoo.EntryPointNode) BuildContext(org.drools.core.reteoo.builder.BuildContext) NodeFactory(org.drools.core.reteoo.builder.NodeFactory) PhreakNodeFactory(org.drools.core.reteoo.builder.PhreakNodeFactory) ClassObjectType(org.drools.core.base.ClassObjectType) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) MockObjectSink(org.drools.core.reteoo.MockObjectSink) PhreakNodeFactory(org.drools.core.reteoo.builder.PhreakNodeFactory) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Test(org.junit.Test)

Aggregations

EntryPointNode (org.drools.core.reteoo.EntryPointNode)2 NodeFactory (org.drools.core.reteoo.builder.NodeFactory)2 PhreakNodeFactory (org.drools.core.reteoo.builder.PhreakNodeFactory)2 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)2 Test (org.junit.Test)2 ClassObjectType (org.drools.core.base.ClassObjectType)1 MockObjectSink (org.drools.core.reteoo.MockObjectSink)1 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)1 Rete (org.drools.core.reteoo.Rete)1 BuildContext (org.drools.core.reteoo.builder.BuildContext)1 EntryPointId (org.drools.core.rule.EntryPointId)1 KieSession (org.kie.api.runtime.KieSession)1 EntryPoint (org.kie.api.runtime.rule.EntryPoint)1 FactHandle (org.kie.api.runtime.rule.FactHandle)1