Search in sources :

Example 96 with InternalKnowledgeBase

use of org.drools.kiesession.rulebase.InternalKnowledgeBase in project drools by kiegroup.

the class NodeSegmentUnlinkingTest method testAllLinkedInWithJoinNodesOnly.

@Test
public void testAllLinkedInWithJoinNodesOnly() {
    setUp(JOIN_NODE);
    // make sure it created JoinNodes
    assertEquals(JoinNode.class, n3.getClass());
    InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
    StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
    DefaultFactHandle f1 = (DefaultFactHandle) ksession.insert("test1");
    n3.assertObject(f1, context, ksession);
    BetaMemory bm = (BetaMemory) ksession.getNodeMemory(n3);
    assertFalse(bm.getSegmentMemory().isSegmentLinked());
    n4.assertObject(f1, context, ksession);
    assertFalse(bm.getSegmentMemory().isSegmentLinked());
    n5.assertObject(f1, context, ksession);
    assertFalse(bm.getSegmentMemory().isSegmentLinked());
    n6.assertObject(f1, context, ksession);
    // only after all 4 nodes are populated, is the segment linked in
    assertTrue(bm.getSegmentMemory().isSegmentLinked());
}
Also used : DefaultFactHandle(org.drools.core.common.DefaultFactHandle) StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) BetaMemory(org.drools.core.reteoo.BetaMemory) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Test(org.junit.Test)

Example 97 with InternalKnowledgeBase

use of org.drools.kiesession.rulebase.InternalKnowledgeBase in project drools by kiegroup.

the class ReteTest method testNotShadowed.

@Test
@Ignore
public void testNotShadowed() {
    Properties properties = new Properties();
    properties.setProperty("drools.shadowProxyExcludes", "org.drools.core.test.model.Cheese");
    RuleBaseConfiguration conf = new RuleBaseConfiguration(properties);
    InternalKnowledgeBase kBase = (InternalKnowledgeBase) RuleBaseFactory.newRuleBase(conf);
    buildContext = new BuildContext(kBase, Collections.emptyList());
    final StatefulKnowledgeSessionImpl ksession = new StatefulKnowledgeSessionImpl(1L, kBase);
    // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
    final Rete rete = kBase.getRete();
    final EntryPointNode entryPoint = new EntryPointNode(0, rete, buildContext);
    entryPoint.attach(buildContext);
    final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1, entryPoint, new ClassObjectType(Cheese.class), buildContext);
    objectTypeNode.attach(buildContext);
    final MockObjectSink sink1 = new MockObjectSink();
    objectTypeNode.addObjectSink(sink1);
    // There are no String ObjectTypeNodes, make sure its not propagated
    final Cheese cheese = new Cheese("brie", 15);
    final DefaultFactHandle h1 = new DefaultFactHandle(1, cheese);
    rete.assertObject(h1, pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null), ksession);
    ksession.fireAllRules();
    final Object[] results = (Object[]) sink1.getAsserted().get(0);
}
Also used : Rete(org.drools.core.reteoo.Rete) ClassObjectType(org.drools.core.base.ClassObjectType) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) Cheese(org.drools.core.test.model.Cheese) MockObjectSink(org.drools.core.reteoo.MockObjectSink) Properties(java.util.Properties) RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) EntryPointNode(org.drools.core.reteoo.EntryPointNode) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) BuildContext(org.drools.core.reteoo.builder.BuildContext) StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 98 with InternalKnowledgeBase

use of org.drools.kiesession.rulebase.InternalKnowledgeBase in project drools by kiegroup.

the class ReteooWorkingMemoryTest method testExecuteQueueActions.

@Test
@Ignore
public void testExecuteQueueActions() {
    InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
    StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
    final ReentrantAction action = new ReentrantAction();
    ksession.addPropagation(action, true);
    ksession.flushPropagations();
    assertEquals(2, action.counter.get());
}
Also used : StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 99 with InternalKnowledgeBase

use of org.drools.kiesession.rulebase.InternalKnowledgeBase in project drools by kiegroup.

the class ReteooWorkingMemoryTest method testBasicWorkingMemoryActions.

/*
     * @see JBRULES-356
     */
@Test
@Ignore
public void testBasicWorkingMemoryActions() {
    InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
    StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
    final TruthMaintenanceSystem tms = TruthMaintenanceSystemFactory.get().getOrCreateTruthMaintenanceSystem(ksession);
    final String string = "test";
    FactHandle fd = ksession.insert(string);
    FactHandle fz = tms.insert(string, null, new MockActivation());
    assertEquals(1, tms.getEqualityKeyMap().size());
    EqualityKey key = tms.get(string);
    assertSame(fz, key.getFactHandle());
    assertEquals(2, key.size());
    ksession.update(fd, string);
    assertEquals(1, tms.getEqualityKeyMap().size());
    key = tms.get(string);
    assertSame(fz, key.getFactHandle());
    assertEquals(2, key.size());
    ksession.retract(fd);
    assertEquals(1, tms.getEqualityKeyMap().size());
    key = tms.get(string);
    fd = ksession.insert(string);
    assertEquals(1, tms.getEqualityKeyMap().size());
    assertEquals(1, tms.getEqualityKeyMap().size());
    key = tms.get(string);
    assertSame(fd, key.getFactHandle());
    assertEquals(1, key.size());
}
Also used : TruthMaintenanceSystem(org.drools.core.common.TruthMaintenanceSystem) FactHandle(org.kie.api.runtime.rule.FactHandle) EqualityKey(org.drools.core.common.EqualityKey) StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 100 with InternalKnowledgeBase

use of org.drools.kiesession.rulebase.InternalKnowledgeBase 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)

Aggregations

InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)268 Test (org.junit.Test)213 KieSession (org.kie.api.runtime.KieSession)136 ArrayList (java.util.ArrayList)99 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)98 KiePackage (org.kie.api.definition.KiePackage)82 List (java.util.List)55 CommonTraitTest (org.drools.traits.compiler.CommonTraitTest)39 StatefulKnowledgeSessionImpl (org.drools.kiesession.session.StatefulKnowledgeSessionImpl)34 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)33 InternalFactHandle (org.drools.core.common.InternalFactHandle)30 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)24 Cheese (org.drools.mvel.compiler.Cheese)24 FactType (org.kie.api.definition.type.FactType)23 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)22 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)21 BetaMemory (org.drools.core.reteoo.BetaMemory)18 PackageDescr (org.drools.drl.ast.descr.PackageDescr)18 Resource (org.kie.api.io.Resource)18 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)17