SegmentUtilities.createSegmentMemory( liaNode, ksession );
InternalFactHandle fh1 = (InternalFactHandle) ksession.insert( "str1" );
n1.assertObject( fh1, context, ksession );
LiaNodeMemory liaMem = (LiaNodeMemory) ksession.getNodeMemory( liaNode );
assertEquals( 1, liaMem.getNodePosMaskBit() );
assertEquals( 3, liaMem.getSegmentMemory().getAllLinkedMaskTest() );
BetaMemory bm1 = (BetaMemory) ksession.getNodeMemory( n1 );
assertEquals( 2, bm1.getNodePosMaskBit() );
assertEquals( 3, bm1.getSegmentMemory().getAllLinkedMaskTest() );
// still unlinked
assertFalse( liaMem.getSegmentMemory().isSegmentLinked() );
// now linked
InternalFactHandle fh2 = (InternalFactHandle) ksession.insert( "str2" );
liaNode.assertObject( fh2, context, ksession );
assertTrue( liaMem.getSegmentMemory().isSegmentLinked() );
// test unlink after one retract
liaNode.retractLeftTuple( fh2.getFirstLeftTuple(), context, ksession );
assertFalse( liaMem.getSegmentMemory().isSegmentLinked() );
// check counter, after multiple asserts
InternalFactHandle fh3 = (InternalFactHandle) ksession.insert( "str3" );
InternalFactHandle fh4 = (InternalFactHandle) ksession.insert( "str4" );
liaNode.assertObject( fh3, context, ksession );
liaNode.assertObject( fh4, context, ksession );
assertTrue( liaMem.getSegmentMemory().isSegmentLinked() );
liaNode.retractLeftTuple( fh3.getFirstLeftTuple(), context, ksession );
assertTrue( liaMem.getSegmentMemory().isSegmentLinked() );
liaNode.retractLeftTuple( fh4.getFirstLeftTuple(), context, ksession );
assertFalse( liaMem.getSegmentMemory().isSegmentLinked() );
}