Search in sources :

Example 11 with FieldIndex

use of org.drools.core.util.AbstractHashTable.FieldIndex in project drools by kiegroup.

the class FieldIndexEntryTest method testSingleEntry.

@Test
public void testSingleEntry() {
    final ClassFieldReader extractor = store.getReader(Cheese.class, "type");
    final FieldIndex fieldIndex = new FieldIndex(extractor, null, MvelConstraint.INDEX_EVALUATOR);
    final SingleIndex singleIndex = new SingleIndex(new FieldIndex[] { fieldIndex }, 1);
    Tuple tuple = new RightTupleImpl(new DefaultFactHandle(1, new Cheese("stilton", 10)));
    final TupleList index = new AbstractHashTable.SingleIndexTupleList(singleIndex, tuple, "stilton".hashCode(), false);
    // Test initial construction
    assertNull(index.getFirst());
    assertEquals("stilton".hashCode(), index.hashCode());
    final Cheese stilton1 = new Cheese("stilton", 35);
    final InternalFactHandle h1 = new DefaultFactHandle(1, stilton1);
    // test add
    RightTuple h1RightTuple = new RightTupleImpl(h1, null);
    index.add(h1RightTuple);
    final Tuple entry1 = index.getFirst();
    assertSame(h1, entry1.getFactHandle());
    assertNull(entry1.getNext());
    assertSame(entry1, index.get(h1));
    // test get
    final Tuple entry2 = index.get(new RightTupleImpl(h1, null));
    assertSame(entry1, entry2);
    // test remove
    index.remove(h1RightTuple);
    assertNull(index.getFirst());
}
Also used : TupleList(org.drools.core.util.index.TupleList) SingleIndex(org.drools.core.util.AbstractHashTable.SingleIndex) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) FieldIndex(org.drools.core.util.AbstractHashTable.FieldIndex) ClassFieldReader(org.drools.core.base.ClassFieldReader) Cheese(org.drools.core.test.model.Cheese) RightTupleImpl(org.drools.core.reteoo.RightTupleImpl) InternalFactHandle(org.drools.core.common.InternalFactHandle) RightTuple(org.drools.core.reteoo.RightTuple) RightTuple(org.drools.core.reteoo.RightTuple) Tuple(org.drools.core.spi.Tuple) Test(org.junit.Test)

Aggregations

FieldIndex (org.drools.core.util.AbstractHashTable.FieldIndex)11 Test (org.junit.Test)10 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)9 InternalFactHandle (org.drools.core.common.InternalFactHandle)9 Cheese (org.drools.core.test.model.Cheese)9 RightTupleImpl (org.drools.core.reteoo.RightTupleImpl)8 ClassObjectType (org.drools.core.base.ClassObjectType)7 RightTuple (org.drools.core.reteoo.RightTuple)7 Declaration (org.drools.core.rule.Declaration)7 Pattern (org.drools.core.rule.Pattern)7 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)7 TupleIndexHashTable (org.drools.core.util.index.TupleIndexHashTable)7 Tuple (org.drools.core.spi.Tuple)6 LeftTupleImpl (org.drools.core.reteoo.LeftTupleImpl)4 TupleList (org.drools.core.util.index.TupleList)4 ClassFieldReader (org.drools.core.base.ClassFieldReader)3 SingleIndex (org.drools.core.util.AbstractHashTable.SingleIndex)3 ArrayList (java.util.ArrayList)1 IndexableConstraint (org.drools.core.rule.IndexableConstraint)1 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)1