Search in sources :

Example 1 with FieldIndexHashTableFullIterator

use of org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator 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) FieldIndexHashTableFullIterator(org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator) RightTuple(org.drools.core.reteoo.RightTuple) Test(org.junit.Test)

Example 2 with FieldIndexHashTableFullIterator

use of org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator in project drools by kiegroup.

the class LeftLeftTupleIndexHashTableIteratorTest 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) FieldIndexHashTableFullIterator(org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator) LeftTupleImpl(org.drools.core.reteoo.LeftTupleImpl) Test(org.junit.Test)

Example 3 with FieldIndexHashTableFullIterator

use of org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator 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 4 with FieldIndexHashTableFullIterator

use of org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator 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

FieldIndexHashTableFullIterator (org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator)4 TupleList (org.drools.core.util.index.TupleList)4 Test (org.junit.Test)4 LeftTupleImpl (org.drools.core.reteoo.LeftTupleImpl)2 RightTuple (org.drools.core.reteoo.RightTuple)2 AbstractHashTable (org.drools.core.util.AbstractHashTable)2 Entry (org.drools.core.util.Entry)2