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());
}
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;
}
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;
}
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;
}
Aggregations