예제 #1
0
  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();
    betaNode.attach();

    return betaNode;
  }
예제 #2
0
  @Test
  public void testSingleNodeinSegment() {

    rule1 = new Rule("rule1");
    rule2 = new Rule("rule2");
    rule3 = new Rule("rule3");

    KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kconf.setOption(RuleEngineOption.PHREAK);
    ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase((RuleBaseConfiguration) kconf);
    BuildContext buildContext =
        new BuildContext(ruleBase, ruleBase.getReteooBuilder().getIdGenerator());

    MockObjectSource mockObjectSource = new MockObjectSource(8);
    MockTupleSource mockTupleSource = new MockTupleSource(9);

    // 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, null);
    n1.addAssociation(rule2, null);
    n1.addAssociation(rule3, null);

    n2.addAssociation(rule2, null);
    n2.addAssociation(rule3, null);

    n3.addAssociation(rule1, null);
    n4.addAssociation(rule2, null);
    n5.addAssociation(rule3, null);

    mockObjectSource.attach();
    mockTupleSource.attach();
    n1.attach();
    n2.attach();
    n3.attach();
    n4.attach();
    n5.attach();

    AbstractWorkingMemory wm =
        new AbstractWorkingMemory(
            1, (ReteooRuleBase) RuleBaseFactory.newRuleBase((RuleBaseConfiguration) kconf));
    createSegmentMemory(n2, wm);

    BetaMemory bm = (BetaMemory) wm.getNodeMemory(n1);
    assertNull(bm.getSegmentMemory());

    bm = (BetaMemory) wm.getNodeMemory(n3);
    assertNull(bm.getSegmentMemory());

    bm = (BetaMemory) wm.getNodeMemory(n4);
    assertNull(bm.getSegmentMemory());

    bm = (BetaMemory) wm.getNodeMemory(n2);
    assertEquals(1, bm.getNodePosMaskBit());
    assertEquals(1, bm.getSegmentMemory().getAllLinkedMaskTest());
  }