@Test public void testAllLinkedInWithJoinNodesOnly() { setUp( JOIN_NODE ); assertEquals( JoinNode.class, n3.getClass() ); // make sure it created JoinNodes KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf); 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 ); assertTrue( bm.getSegmentMemory().isSegmentLinked() ); // only after all 4 nodes are populated, is the segment linked in }
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 ); n1.attach(buildContext); n2.attach(buildContext); n3.attach(buildContext); n4.attach(buildContext); n5.attach(buildContext);
public List<LeftTuple> getLeftTuples(Object... objects) { BetaNode node = scenario.getBetaNode(); BetaMemory bm = scenario.getBm(); TupleMemory ltm = bm.getLeftTupleMemory(); InternalWorkingMemory wm = scenario.getWorkingMemory(); if ( objects == null ) { objects = new Object[0]; } List<LeftTuple> list = new ArrayList<LeftTuple>(); for ( Object object : objects ) { InternalFactHandle fh = (InternalFactHandle) wm.insert( object ); LeftTuple expectedLeftTuple = node.createLeftTuple( fh, node, true ); expectedLeftTuple.setPropagationContext( new PhreakPropagationContext() ); list.add( expectedLeftTuple ); } scenario.setTestLeftMemory( true ); return list; }
@Test public void testAllLinkedInWithNotNodesOnly() { setUp( NOT_NODE ); assertEquals( NotNode.class, n3.getClass() ); // make sure it created NotNodes KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf); StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newKieSession(); BetaMemory bm = (BetaMemory) ksession.getNodeMemory( n3 ); createSegmentMemory( n3, ksession ); assertTrue( bm.getSegmentMemory().isSegmentLinked() ); // not nodes start off linked DefaultFactHandle f1 = (DefaultFactHandle) ksession.insert( "test1" ); // unlinked after first assertion n3.assertObject( f1, context, ksession ); // this doesn't unlink on the assertObject, as the node's memory must be processed. So use the helper method the main network evaluator uses. PhreakNotNode.unlinkNotNodeOnRightInsert( (NotNode) n3, bm, ksession ); assertFalse( bm.getSegmentMemory().isSegmentLinked() ); n3.retractRightTuple( f1.getFirstRightTuple(), context, ksession ); assertTrue( bm.getSegmentMemory().isSegmentLinked() ); //assertFalse( bm.getSegmentMemory().isSigmentLinked() ); // check retraction unlinks again }
this.node.assertObject( f0, this.context, this.workingMemory ); .insert( "test1" ); final LeftTupleImpl tuple1 = new LeftTupleImpl( f1, this.node, true ); this.node.assertLeftTuple( tuple1, this.context, this.workingMemory ); .insert( "test2" ); final LeftTupleImpl tuple2 = new LeftTupleImpl( f2, this.node, true ); this.node.assertLeftTuple( tuple2, this.context, this.workingMemory ); this.node.assertObject( f3, this.context, this.workingMemory ); this.node.assertObject( f4, this.context, this.workingMemory ); this.node.retractRightTuple( f0.getFirstRightTuple(), this.context, this.workingMemory ); this.node.retractLeftTuple( tuple2,
@Test public void testConstraintPropagations() throws Exception { when( constraint.isAllowedCachedLeft( any( ContextEntry.class ), any( InternalFactHandle.class ) ) ).thenReturn( false ); when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ), any( ContextEntry.class ) ) ).thenReturn( false ); // assert first right object final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory .insert( "test0" ); this.node.assertObject( f0, this.context, this.workingMemory ); // assert tuple, should add left memory should be 2 final DefaultFactHandle f1 = new DefaultFactHandle( 1, "cheese" ); final LeftTupleImpl tuple1 = new LeftTupleImpl( f1, this.node, true ); this.node.assertLeftTuple( tuple1, this.context, this.workingMemory ); // Should be no assertions assertLength( 0, this.sink.getAsserted() ); this.node.retractRightTuple( f0.getFirstRightTuple(), this.context, this.workingMemory ); assertLength( 0, this.sink.getRetracted() ); }
buildContext ); this.node.addTupleSink( this.sink ); final LeftTupleImpl tuple0 = new LeftTupleImpl( f0, this.node, true ); this.node.assertObject( f0, pctxFactory.createPropagationContext(0, PropagationContext.INSERTION, null, null, f0), this.workingMemory ); this.node.assertLeftTuple( tuple0, pctxFactory.createPropagationContext(0, PropagationContext.INSERTION, null, null, f0), this.workingMemory );
@Test public void testAttach() throws Exception { when(constraint.isAllowedCachedLeft(any(ContextEntry.class), any(InternalFactHandle.class ) ) ).thenReturn( true ); when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ), any( ContextEntry.class ) ) ).thenReturn( true ); final Field objectFfield = ObjectSource.class.getDeclaredField( "sink" ); objectFfield.setAccessible( true ); ObjectSinkPropagator objectSink = (ObjectSinkPropagator) objectFfield.get( this.objectSource ); final Field tupleField = LeftTupleSource.class.getDeclaredField( "sink" ); tupleField.setAccessible( true ); LeftTupleSinkPropagator tupleSink = (LeftTupleSinkPropagator) tupleField.get( this.tupleSource ); assertEquals( 15, this.node.getId() ); assertNotNull( objectSink ); assertNotNull( tupleSink ); InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(); BuildContext context = new BuildContext(kBase, kBase.getReteooBuilder().getIdGenerator() ); this.node.attach(context); objectSink = (ObjectSinkPropagator) objectFfield.get( this.objectSource ); tupleSink = (LeftTupleSinkPropagator) tupleField.get( this.tupleSource ); assertEquals( 1, objectSink.getSinks().length ); assertEquals( 1, tupleSink.getSinks().length ); assertSame( this.node, objectSink.getSinks()[0] ); assertSame( this.node, tupleSink.getSinks()[0] ); }
this.node.assertObject( f0, this.context, this.workingMemory ); this.node.assertLeftTuple( tuple1, this.context, this.workingMemory ); this.node.assertLeftTuple( tuple2, this.context, this.workingMemory ); this.node.assertObject( f3, this.context, this.workingMemory );
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; }
lian.addAssociation( rule2 ); lian.addAssociation( rule3 ); n1.addAssociation( rule1 ); n1.addAssociation( rule2 ); n1.addAssociation( rule3 ); n2.addAssociation( rule1 ); n2.addAssociation( rule2 ); n2.addAssociation( rule3 ); n3.addAssociation( rule1 ); n3.addAssociation( rule2 ); n3.addAssociation( rule3 ); n4.addAssociation( rule2 ); n4.addAssociation( rule3 ); n5.addAssociation( rule2 ); n5.addAssociation( rule3 ); n6.addAssociation( rule3 ); n7.addAssociation( rule3 ); n8.addAssociation( rule3 );
public Memory createMemory(RuleBaseConfiguration config, InternalWorkingMemory wm) { return super.createMemory( config, wm); }
BetaNodeFieldConstraint[] constraint = betaanode.getConstraints(); PredicateConstraint c = ( PredicateConstraint ) constraint[0]; assertTrue( c.getPredicateExpression() instanceof PredicateExpression );
this.node.assertLeftTuple( tuple0, this.context, this.workingMemory ); this.node.assertLeftTuple( tuple1, this.context, this.workingMemory );
buildContext); this.node.addTupleSink(this.sink);
n1.assertObject( f1, context, wm ); n3.assertObject( f1, context, wm ); n4.assertObject( f1, context, wm ); n8.assertObject( f1, context, wm ); n2.assertObject( f2, context, wm ); assertTrue( bm.getSegmentMemory().isSegmentLinked() ); assertFalse( bm.getSegmentMemory().isSegmentLinked() ); n5.assertObject( f1, context, wm ); assertTrue( bm.getSegmentMemory().isSegmentLinked() ); n6.assertObject( f1, context, wm ); n7.assertObject( f1, context, wm ); assertTrue( bm.getSegmentMemory().isSegmentLinked() ); n2.retractRightTuple( f2.getFirstRightTuple(), context, wm ); assertFalse( rtn1Rs.isRuleLinked() ); assertFalse( rtn2Rs.isRuleLinked() );
liaNode.addAssociation( rule2 ); liaNode.addAssociation( rule3 ); n1.addAssociation( rule1 ); n1.addAssociation( rule2 ); n1.addAssociation( rule3 ); n2.addAssociation( rule1 ); n2.addAssociation( rule2 ); n2.addAssociation( rule3 ); n3.addAssociation( rule1 ); n3.addAssociation( rule2 ); n3.addAssociation( rule3 ); n4.addAssociation( rule2 ); n4.addAssociation( rule3 ); n5.addAssociation( rule2 ); n5.addAssociation( rule3 ); n6.addAssociation( rule3 ); n7.addAssociation( rule3 ); n8.addAssociation( rule3 );
n1.assertObject( f1, context, wm ); n3.assertObject( f1, context, wm ); n4.assertObject( f1, context, wm ); n8.assertObject( f1, context, wm ); n2.assertObject( f2, context, wm ); assertTrue( bm.getSegmentMemory().isSegmentLinked() ); assertFalse( bm.getSegmentMemory().isSegmentLinked() ); n5.assertObject( f1, context, wm ); assertTrue( bm.getSegmentMemory().isSegmentLinked() ); n6.assertObject( f1, context, wm ); n7.assertObject( f1, context, wm ); assertTrue( bm.getSegmentMemory().isSegmentLinked() ); n2.retractRightTuple( f2.getFirstRightTuple(), context, wm ); assertFalse( rtn1Rs.isRuleLinked() ); assertFalse( rtn2Rs.isRuleLinked() );
@Test public void testAllLinkedInWithExistsNodesOnly() { setUp( EXISTS_NODE ); assertEquals( ExistsNode.class, n3.getClass() ); // make sure it created ExistsNodes KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf); 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 ); assertTrue( bm.getSegmentMemory().isSegmentLinked() ); // only after all 4 nodes are populated, is the segment linked in }