Search in sources :

Example 11 with Entry

use of org.drools.core.util.Entry in project drools by kiegroup.

the class LeftTupleIndexHashTableIteratorTest method testLastBucketInTheTable.

@Test
public void testLastBucketInTheTable() {
    // JBRULES-2574
    // setup the entry array with an element in the first bucket, one
    // in the middle and one in the last bucket
    Entry[] entries = new Entry[10];
    entries[0] = mock(TupleList.class);
    entries[5] = mock(TupleList.class);
    entries[9] = mock(TupleList.class);
    LeftTupleImpl[] tuples = new LeftTupleImpl[] { mock(LeftTupleImpl.class), mock(LeftTupleImpl.class), mock(LeftTupleImpl.class) };
    // set return values for methods
    when(entries[0].getNext()).thenReturn(null);
    when(((TupleList) entries[0]).getFirst()).thenReturn(tuples[0]);
    when(entries[5].getNext()).thenReturn(null);
    when(((TupleList) entries[5]).getFirst()).thenReturn(tuples[1]);
    when(entries[9].getNext()).thenReturn(null);
    when(((TupleList) entries[9]).getFirst()).thenReturn(tuples[2]);
    // create the mock table for the iterator
    AbstractHashTable table = mock(AbstractHashTable.class);
    when(table.getTable()).thenReturn(entries);
    // create the iterator
    FieldIndexHashTableFullIterator iterator = new FieldIndexHashTableFullIterator(table);
    // test it
    assertThat(iterator.next(), sameInstance((Object) tuples[0]));
    assertThat(iterator.next(), sameInstance((Object) tuples[1]));
    assertThat(iterator.next(), sameInstance((Object) tuples[2]));
    assertThat(iterator.next(), is((Object) null));
}
Also used : TupleList(org.drools.core.util.index.TupleList) Entry(org.drools.core.util.Entry) AbstractHashTable(org.drools.core.util.AbstractHashTable) FieldIndexHashTableFullIterator(org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator) LeftTupleImpl(org.drools.core.reteoo.LeftTupleImpl) Test(org.junit.Test)

Example 12 with Entry

use of org.drools.core.util.Entry in project drools by kiegroup.

the class RightTupleIndexHashTableIteratorTest method testLastBucketInTheTable.

@Test
public void testLastBucketInTheTable() {
    // JBRULES-2574
    // setup the entry array with an element in the first bucket, one
    // in the middle and one in the last bucket
    Entry[] entries = new Entry[10];
    entries[0] = mock(TupleList.class);
    entries[5] = mock(TupleList.class);
    entries[9] = mock(TupleList.class);
    RightTuple[] tuples = new RightTuple[] { mock(RightTuple.class), mock(RightTuple.class), mock(RightTuple.class) };
    // set return values for methods
    when(entries[0].getNext()).thenReturn(null);
    when(((TupleList) entries[0]).getFirst()).thenReturn(tuples[0]);
    when(entries[5].getNext()).thenReturn(null);
    when(((TupleList) entries[5]).getFirst()).thenReturn(tuples[1]);
    when(entries[9].getNext()).thenReturn(null);
    when(((TupleList) entries[9]).getFirst()).thenReturn(tuples[2]);
    // create the mock table for the iterator
    AbstractHashTable table = mock(AbstractHashTable.class);
    when(table.getTable()).thenReturn(entries);
    // create the iterator
    FieldIndexHashTableFullIterator iterator = new FieldIndexHashTableFullIterator(table);
    // test it
    assertThat(iterator.next(), sameInstance((Object) tuples[0]));
    assertThat(iterator.next(), sameInstance((Object) tuples[1]));
    assertThat(iterator.next(), sameInstance((Object) tuples[2]));
    assertThat(iterator.next(), is((Object) null));
}
Also used : TupleList(org.drools.core.util.index.TupleList) Entry(org.drools.core.util.Entry) AbstractHashTable(org.drools.core.util.AbstractHashTable) FieldIndexHashTableFullIterator(org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator) RightTuple(org.drools.core.reteoo.RightTuple) Test(org.junit.Test)

Aggregations

Entry (org.drools.core.util.Entry)12 ArrayList (java.util.ArrayList)5 TupleList (org.drools.core.util.index.TupleList)5 Tuple (org.drools.core.spi.Tuple)4 FastIterator (org.drools.core.util.FastIterator)4 Test (org.junit.Test)4 Field (java.lang.reflect.Field)3 List (java.util.List)2 ClassObjectType (org.drools.core.base.ClassObjectType)2 Declaration (org.drools.core.rule.Declaration)2 Pattern (org.drools.core.rule.Pattern)2 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)2 AbstractHashTable (org.drools.core.util.AbstractHashTable)2 FieldIndex (org.drools.core.util.AbstractHashTable.FieldIndex)2 RBTree (org.drools.core.util.RBTree)2 TupleIndexHashTable (org.drools.core.util.index.TupleIndexHashTable)2 FieldIndexHashTableFullIterator (org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator)2 IOException (java.io.IOException)1 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1