/**
* Tests that interfaces and parent classes for an asserted class are cached, for quick future iterations
*/
@Test
public void testCache() {
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();
// Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
final Rete rete = kBase.getRete();
ObjectTypeNode objectTypeNode = new ObjectTypeNode(1,
this.entryPoint,
new ClassObjectType(List.class),
buildContext);
objectTypeNode.attach(buildContext);
MockObjectSink sink = new MockObjectSink();
objectTypeNode.addObjectSink(sink);
objectTypeNode = new ObjectTypeNode(1,
this.entryPoint,
new ClassObjectType(Collection.class),
buildContext);
objectTypeNode.attach(buildContext);
sink = new MockObjectSink();
objectTypeNode.addObjectSink(sink);
objectTypeNode = new ObjectTypeNode(1,
this.entryPoint,
new ClassObjectType(ArrayList.class),
buildContext);
objectTypeNode.attach(buildContext);
sink = new MockObjectSink();
objectTypeNode.addObjectSink(sink);
// ArrayList matches all three ObjectTypeNodes
final DefaultFactHandle h1 = new DefaultFactHandle(1,
new ArrayList());
rete.assertObject(h1,
pctxFactory.createPropagationContext(0,
PropagationContext.INSERTION,
null,
null,
null),
ksession);
// LinkedList matches two ObjectTypeNodes
h1.setObject(new LinkedList());
rete.assertObject(h1,
pctxFactory.createPropagationContext(0,
PropagationContext.INSERTION,
null,
null,
null),
ksession);
ClassObjectTypeConf conf = (ClassObjectTypeConf) ksession.getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPoint.getEntryPoint(), new ArrayList());
assertLength(3,
conf.getObjectTypeNodes());
conf = (ClassObjectTypeConf) ksession.getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPoint.getEntryPoint(), new ArrayList());
assertLength(3,
conf.getObjectTypeNodes());
}