@Test public void testSplitTwoBeforeCreatedSegment() throws Exception { KnowledgeBase kbase1 = buildKnowledgeBase( "r1", " A(1;) A(2;) B(1;) B(2;) C(1;) C(2;) D(1;) D(2;) E(1;) E(2;)\n"); kbase1.addKnowledgePackages( buildKnowledgePackage( "r2", " A(1;) A(2;) B(1;) B(2;) C(1;) C(2;) D(1;) D(2;) E(1;) E(2;)\n")); kbase1.addKnowledgePackages( buildKnowledgePackage("r3", " A(1;) A(2;) B(1;) B(2;) C(1;) C(2;) D(1;) D(2;)\n")); kbase1.addKnowledgePackages( buildKnowledgePackage("r4", " A(1;) A(2;) B(1;) B(2;) C(1;) C(2;) \n")); InternalWorkingMemory wm = ((InternalWorkingMemory) kbase1.newStatefulKnowledgeSession()); List list = new ArrayList(); wm.setGlobal("list", list); wm.insert(new E(1)); wm.insert(new E(2)); wm.flushPropagations(); RuleTerminalNode rtn1 = getRtn("org.kie.r1", kbase1); RuleTerminalNode rtn2 = getRtn("org.kie.r2", kbase1); RuleTerminalNode rtn3 = getRtn("org.kie.r3", kbase1); RuleTerminalNode rtn4 = getRtn("org.kie.r4", kbase1); PathMemory pm1 = (PathMemory) wm.getNodeMemory(rtn1); SegmentMemory[] smems = pm1.getSegmentMemories(); assertEquals(4, smems.length); assertNull(smems[0]); assertNull(smems[1]); assertNull(smems[3]); SegmentMemory sm = smems[2]; assertEquals(2, sm.getPos()); assertEquals(4, sm.getSegmentPosMaskBit()); assertEquals(4, pm1.getLinkedSegmentMask()); kbase1.addKnowledgePackages(buildKnowledgePackage("r5", " A(1;) A(2;) B(1;) B(2;) \n")); smems = pm1.getSegmentMemories(); assertEquals(5, smems.length); assertNull(smems[0]); assertNull(smems[1]); assertNull(smems[2]); sm = smems[3]; assertEquals(3, sm.getPos()); assertEquals(8, sm.getSegmentPosMaskBit()); assertEquals(8, pm1.getLinkedSegmentMask()); RuleTerminalNode rtn5 = getRtn("org.kie.r5", kbase1); PathMemory pm5 = (PathMemory) wm.getNodeMemory(rtn5); smems = pm5.getSegmentMemories(); assertEquals(2, smems.length); assertNull(smems[0]); assertNull(smems[1]); }
private void doRiaNode( InternalWorkingMemory wm, LeftInputAdapterNode liaNode, PathMemory pmem, TupleSets<LeftTuple> srcTuples, BetaNode betaNode, LeftTupleSinkNode sink, SegmentMemory[] smems, int smemIndex, Memory nodeMem, BetaMemory bm, LinkedList<StackEntry> stack, RuleExecutor executor) { RiaPathMemory pathMem = bm.getRiaRuleMemory(); SegmentMemory[] subnetworkSmems = pathMem.getSegmentMemories(); SegmentMemory subSmem = null; for (int i = 0; subSmem == null; i++) { // segment positions outside of the subnetwork, in the parent chain, are null // so we must iterate to find the first non null segment memory subSmem = subnetworkSmems[i]; } // Resume the node after the riaNode segment has been processed and the right input memory // populated StackEntry stackEntry = new StackEntry( liaNode, betaNode, bm.getNodePosMaskBit(), sink, pmem, nodeMem, smems, smemIndex, srcTuples, false, false); stack.add(stackEntry); if (log.isTraceEnabled()) { int offset = getOffset(betaNode); log.trace( "{} RiaQueue {} {}", indent(offset), betaNode.toString(), srcTuples.toStringSizes()); } TupleSets<LeftTuple> subLts = subSmem.getStagedLeftTuples().takeAll(); // node is first in the segment, so bit is 1 innerEval( liaNode, pathMem, subSmem.getRootNode(), 1, subSmem.getNodeMemories().getFirst(), subnetworkSmems, subSmem.getPos(), subLts, wm, stack, true, executor); }
private void doRiaNode( InternalWorkingMemory wm, LeftInputAdapterNode liaNode, PathMemory rmem, LeftTupleSets srcTuples, BetaNode betaNode, LeftTupleSinkNode sink, SegmentMemory[] smems, int smemIndex, Memory nodeMem, BetaMemory bm, LinkedList<StackEntry> stack, Set<String> visitedRules, RuleExecutor executor) { RiaPathMemory pathMem = bm.getRiaRuleMemory(); SegmentMemory[] subnetworkSmems = pathMem.getSegmentMemories(); SegmentMemory subSmem = null; for (int i = 0; subSmem == null; i++) { // segment positions outside of the subnetwork, in the parent chain, are null // so we must iterate to find the first non null segment memory subSmem = subnetworkSmems[i]; } // if (betaNode.getLeftTupleSource().getSinkPropagator().size() == 2) { // // sub network is not part of share split, so need to handle propagation // // this ensures the first LeftTuple is actually the subnetwork node // // and the main outer network now receives the peer, notice the swap at the end // "srcTuples == peerTuples" // LeftTupleSets peerTuples = new LeftTupleSets(); // SegmentPropagator.processPeers(srcTuples, peerTuples, betaNode); // // Make sure subnetwork Segment has tuples to process // LeftTupleSets subnetworkStaged = subSmem.getStagedLeftTuples(); // subnetworkStaged.addAll(srcTuples); // // srcTuples.resetAll(); // // srcTuples = peerTuples; // } // Resume the node after the riaNode segment has been processed and the right input memory // populated StackEntry stackEntry = new StackEntry( liaNode, betaNode, sink, rmem, nodeMem, smems, smemIndex, srcTuples, visitedRules, false); stack.add(stackEntry); if (log.isTraceEnabled()) { int offset = getOffset(betaNode); log.trace( "{} RiaQueue {} {}", indent(offset), betaNode.toString(), srcTuples.toStringSizes()); } // RightInputAdapterNode riaNode = ( RightInputAdapterNode ) betaNode.getRightInput(); // RiaNodeMemory riaNodeMemory = (RiaNodeMemory) wm.getNodeMemory((MemoryFactory) // betaNode.getRightInput()); // LeftTupleSets riaStagedTuples = eval2( liaNode, pathMem, (LeftTupleSink) subSmem.getRootNode(), subSmem.getNodeMemories().getFirst(), subnetworkSmems, subSmem.getPos(), subSmem.getStagedLeftTuples(), wm, stack, visitedRules, true, executor); }