Search in sources :

Example 1 with MockObjectSource

use of org.drools.core.reteoo.MockObjectSource in project drools by kiegroup.

the class NodeSegmentUnlinkingTest method testSingleNodeinSegment.

@Test
public void testSingleNodeinSegment() {
    rule1 = new RuleImpl("rule1");
    rule2 = new RuleImpl("rule2");
    rule3 = new RuleImpl("rule3");
    kBase = KnowledgeBaseFactory.newKnowledgeBase();
    BuildContext buildContext = new BuildContext(kBase, Collections.emptyList());
    MockObjectSource mockObjectSource = new MockObjectSource(8);
    MockTupleSource mockTupleSource = new MockTupleSource(9, buildContext);
    // n2 is only node in it's segment
    ObjectTypeNode otn = new ObjectTypeNode(2, null, new ClassObjectType(String.class), buildContext);
    BetaNode n1 = new JoinNode(10, new LeftInputAdapterNode(3, otn, buildContext), mockObjectSource, new EmptyBetaConstraints(), buildContext);
    BetaNode n2 = new JoinNode(11, n1, mockObjectSource, new EmptyBetaConstraints(), buildContext);
    BetaNode n3 = new JoinNode(12, n1, mockObjectSource, new EmptyBetaConstraints(), buildContext);
    BetaNode n4 = new JoinNode(13, n2, mockObjectSource, new EmptyBetaConstraints(), buildContext);
    BetaNode n5 = new JoinNode(14, n2, mockObjectSource, new EmptyBetaConstraints(), buildContext);
    n1.addAssociation(rule1);
    n1.addAssociation(rule2);
    n1.addAssociation(rule3);
    n2.addAssociation(rule2);
    n2.addAssociation(rule3);
    n3.addAssociation(rule1);
    n4.addAssociation(rule2);
    n5.addAssociation(rule3);
    mockObjectSource.attach(buildContext);
    mockTupleSource.attach(buildContext);
    n1.attach(buildContext);
    n2.attach(buildContext);
    n3.attach(buildContext);
    n4.attach(buildContext);
    n5.attach(buildContext);
    StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
    createSegmentMemory(n2, ksession);
    BetaMemory bm = (BetaMemory) ksession.getNodeMemory(n1);
    assertNull(bm.getSegmentMemory());
    bm = (BetaMemory) ksession.getNodeMemory(n3);
    assertNull(bm.getSegmentMemory());
    bm = (BetaMemory) ksession.getNodeMemory(n4);
    assertNull(bm.getSegmentMemory());
    bm = (BetaMemory) ksession.getNodeMemory(n2);
    assertEquals(1, bm.getNodePosMaskBit());
    assertEquals(1, bm.getSegmentMemory().getAllLinkedMaskTest());
}
Also used : BetaNode(org.drools.core.reteoo.BetaNode) ClassObjectType(org.drools.core.base.ClassObjectType) JoinNode(org.drools.core.reteoo.JoinNode) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) BetaMemory(org.drools.core.reteoo.BetaMemory) MockObjectSource(org.drools.core.reteoo.MockObjectSource) MockTupleSource(org.drools.core.reteoo.MockTupleSource) BuildContext(org.drools.core.reteoo.builder.BuildContext) EmptyBetaConstraints(org.drools.core.common.EmptyBetaConstraints) StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) Test(org.junit.Test)

Example 2 with MockObjectSource

use of org.drools.core.reteoo.MockObjectSource in project drools by kiegroup.

the class NodeSegmentUnlinkingTest method createBetaNode.

private BetaNode createBetaNode(int id, int type, LeftTupleSource leftTupleSource) {
    MockObjectSource mockObjectSource = new MockObjectSource(8);
    BetaNode betaNode = null;
    switch(type) {
        case JOIN_NODE:
            {
                betaNode = new JoinNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case EXISTS_NODE:
            {
                betaNode = new ExistsNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case NOT_NODE:
            {
                betaNode = new NotNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
    }
    mockObjectSource.attach(buildContext);
    betaNode.attach(buildContext);
    return betaNode;
}
Also used : NotNode(org.drools.core.reteoo.NotNode) PhreakNotNode(org.drools.core.phreak.PhreakNotNode) BetaNode(org.drools.core.reteoo.BetaNode) EmptyBetaConstraints(org.drools.core.common.EmptyBetaConstraints) JoinNode(org.drools.core.reteoo.JoinNode) MockObjectSource(org.drools.core.reteoo.MockObjectSource) ExistsNode(org.drools.core.reteoo.ExistsNode)

Example 3 with MockObjectSource

use of org.drools.core.reteoo.MockObjectSource in project drools by kiegroup.

the class RuleUnlinkingTest method createNetworkNode.

private NetworkNode createNetworkNode(int id, int type, LeftTupleSource leftTupleSource, RuleImpl rule) {
    MockObjectSource mockObjectSource = new MockObjectSource(8);
    LeftTupleSink networkNode = null;
    switch(type) {
        case JOIN_NODE:
            {
                networkNode = new JoinNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case EXISTS_NODE:
            {
                networkNode = new ExistsNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case NOT_NODE:
            {
                networkNode = new NotNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case RULE_TERMINAL_NODE:
            {
                networkNode = new RuleTerminalNode(id, leftTupleSource, rule, new GroupElement(Type.AND), 0, buildContext);
                break;
            }
    }
    mockObjectSource.attach();
    if (NodeTypeEnums.isLeftTupleSource(networkNode)) {
        ((LeftTupleSource) networkNode).attach(buildContext);
    } else {
        ((RuleTerminalNode) networkNode).attach(buildContext);
    }
    return networkNode;
}
Also used : LeftTupleSource(org.drools.core.reteoo.LeftTupleSource) NotNode(org.drools.core.reteoo.NotNode) EmptyBetaConstraints(org.drools.core.common.EmptyBetaConstraints) JoinNode(org.drools.core.reteoo.JoinNode) GroupElement(org.drools.core.rule.GroupElement) LeftTupleSink(org.drools.core.reteoo.LeftTupleSink) MockObjectSource(org.drools.core.reteoo.MockObjectSource) ExistsNode(org.drools.core.reteoo.ExistsNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode)

Example 4 with MockObjectSource

use of org.drools.core.reteoo.MockObjectSource in project drools by kiegroup.

the class RuleUnlinkingWithSegmentMemoryTest method createNetworkNode.

private NetworkNode createNetworkNode(int id, int type, LeftTupleSource leftTupleSource, RuleImpl rule) {
    MockObjectSource mockObjectSource = new MockObjectSource(8);
    LeftTupleSink networkNode = null;
    switch(type) {
        case JOIN_NODE:
            {
                networkNode = new JoinNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case EXISTS_NODE:
            {
                networkNode = new ExistsNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case NOT_NODE:
            {
                networkNode = new NotNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
                break;
            }
        case RULE_TERMINAL_NODE:
            {
                networkNode = new RuleTerminalNode(id, leftTupleSource, rule, new GroupElement(Type.AND), 0, buildContext);
                break;
            }
    }
    mockObjectSource.attach();
    if (NodeTypeEnums.isLeftTupleSource(networkNode)) {
        ((LeftTupleSource) networkNode).attach(buildContext);
    } else {
        ((RuleTerminalNode) networkNode).attach(buildContext);
    }
    return networkNode;
}
Also used : LeftTupleSource(org.drools.core.reteoo.LeftTupleSource) NotNode(org.drools.core.reteoo.NotNode) EmptyBetaConstraints(org.drools.core.common.EmptyBetaConstraints) JoinNode(org.drools.core.reteoo.JoinNode) GroupElement(org.drools.core.rule.GroupElement) LeftTupleSink(org.drools.core.reteoo.LeftTupleSink) MockObjectSource(org.drools.core.reteoo.MockObjectSource) ExistsNode(org.drools.core.reteoo.ExistsNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode)

Aggregations

EmptyBetaConstraints (org.drools.core.common.EmptyBetaConstraints)4 JoinNode (org.drools.core.reteoo.JoinNode)4 MockObjectSource (org.drools.core.reteoo.MockObjectSource)4 ExistsNode (org.drools.core.reteoo.ExistsNode)3 NotNode (org.drools.core.reteoo.NotNode)3 BetaNode (org.drools.core.reteoo.BetaNode)2 LeftTupleSink (org.drools.core.reteoo.LeftTupleSink)2 LeftTupleSource (org.drools.core.reteoo.LeftTupleSource)2 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)2 GroupElement (org.drools.core.rule.GroupElement)2 ClassObjectType (org.drools.core.base.ClassObjectType)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 PhreakNotNode (org.drools.core.phreak.PhreakNotNode)1 BetaMemory (org.drools.core.reteoo.BetaMemory)1 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)1 MockTupleSource (org.drools.core.reteoo.MockTupleSource)1 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)1 BuildContext (org.drools.core.reteoo.builder.BuildContext)1 StatefulKnowledgeSessionImpl (org.drools.kiesession.session.StatefulKnowledgeSessionImpl)1 Test (org.junit.Test)1