Search in sources :

Example 1 with CompositeObjectSinkAdapter

use of org.drools.core.reteoo.CompositeObjectSinkAdapter in project drools by kiegroup.

the class IndexingTest method testBuildsIndexedAlphaNodes.

@Test(timeout = 10000)
public void testBuildsIndexedAlphaNodes() {
    String drl = "";
    drl += "package org.drools.compiler.test\n";
    drl += "import org.drools.compiler.Person\n";
    drl += "rule test1\n";
    drl += "when\n";
    drl += "   Person(name == \"Mark\", age == 37)\n";
    drl += "   Person(name == \"Mark\", happy == true)\n";
    drl += "then\n";
    drl += "end\n";
    KieBase kbase = loadKnowledgeBaseFromString(drl);
    ObjectTypeNode otn = getObjectTypeNode(kbase, Person.class);
    InternalWorkingMemory wm = ((StatefulKnowledgeSessionImpl) kbase.newKieSession());
    AlphaNode alphaNode1 = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
    CompositeObjectSinkAdapter sinkAdapter = (CompositeObjectSinkAdapter) alphaNode1.getObjectSinkPropagator();
    ObjectSinkNodeList hashableSinks = sinkAdapter.getHashableSinks();
    assertNotNull(hashableSinks);
    assertEquals(2, hashableSinks.size());
    AlphaNode alphaNode2 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertSame(hashableSinks.getFirst(), alphaNode2);
    AlphaNode alphaNode3 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[1];
    assertSame(hashableSinks.getLast(), alphaNode3);
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) CompositeObjectSinkAdapter(org.drools.core.reteoo.CompositeObjectSinkAdapter) AlphaNode(org.drools.core.reteoo.AlphaNode) ObjectSinkNodeList(org.drools.core.reteoo.ObjectSinkNodeList) Test(org.junit.Test)

Aggregations

InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)1 AlphaNode (org.drools.core.reteoo.AlphaNode)1 CompositeObjectSinkAdapter (org.drools.core.reteoo.CompositeObjectSinkAdapter)1 ObjectSinkNodeList (org.drools.core.reteoo.ObjectSinkNodeList)1 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1