@Test public void testRestract() { final PropagationContext context = pctxFactory.createPropagationContext(0, PropagationContext.INSERTION, null, null, null); final StatefulKnowledgeSessionImpl workingMemory = new StatefulKnowledgeSessionImpl( 1L, (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase()); final ClassFieldReader extractor = store.getReader(Cheese.class, "type"); final MvelConstraint constraint = new MvelConstraintTestUtil( "type == \"stilton\"", FieldFactory.getInstance().getFieldValue("stilton"), extractor); final List list = new ArrayList(); final Cheese cheese1 = new Cheese("stilton", 5); final Cheese cheese2 = new Cheese("stilton", 15); list.add(cheese1); list.add(cheese2); final MockDataProvider dataProvider = new MockDataProvider(list); final Pattern pattern = new Pattern(0, new ClassObjectType(Cheese.class)); From fromCe = new From(dataProvider); fromCe.setResultPattern(pattern); final ReteFromNode from = new ReteFromNode( 3, dataProvider, new MockTupleSource(30), new AlphaNodeFieldConstraint[] {constraint}, null, true, buildContext, fromCe); final MockLeftTupleSink sink = new MockLeftTupleSink(5); from.addTupleSink(sink); final List asserted = sink.getAsserted(); final Person person1 = new Person("xxx2", 30); final FactHandle person1Handle = workingMemory.insert(person1); final LeftTuple tuple = new LeftTupleImpl((DefaultFactHandle) person1Handle, from, true); from.assertLeftTuple(tuple, context, workingMemory); assertEquals(2, asserted.size()); final FromMemory memory = (FromMemory) workingMemory.getNodeMemory(from); assertEquals(1, memory.getBetaMemory().getLeftTupleMemory().size()); assertNull(memory.getBetaMemory().getRightTupleMemory()); RightTuple rightTuple2 = tuple.getFirstChild().getRightParent(); RightTuple rightTuple1 = tuple.getFirstChild().getHandleNext().getRightParent(); assertFalse(rightTuple1.equals(rightTuple2)); assertNull(tuple.getFirstChild().getHandleNext().getHandleNext()); final InternalFactHandle handle2 = rightTuple2.getFactHandle(); final InternalFactHandle handle1 = rightTuple1.getFactHandle(); assertEquals(handle1.getObject(), cheese2); assertEquals(handle2.getObject(), cheese1); from.retractLeftTuple(tuple, context, workingMemory); assertEquals(0, memory.getBetaMemory().getLeftTupleMemory().size()); assertNull(memory.getBetaMemory().getRightTupleMemory()); }