Search in sources :

Example 26 with AbstractInvokable

use of org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable in project flink by apache.

the class ReusingBlockResettableIteratorTest method testSerialBlockResettableIterator.

@Test
public void testSerialBlockResettableIterator() throws Exception {
    final AbstractInvokable memOwner = new DummyInvokable();
    // create the resettable Iterator
    final ReusingBlockResettableIterator<Record> iterator = new ReusingBlockResettableIterator<Record>(this.memman, this.reader, this.serializer, 1, memOwner);
    // open the iterator
    iterator.open();
    // now test walking through the iterator
    int lower = 0;
    int upper = 0;
    do {
        lower = upper;
        upper = lower;
        // find the upper bound
        while (iterator.hasNext()) {
            Record target = iterator.next();
            int val = target.getField(0, IntValue.class).getValue();
            Assert.assertEquals(upper++, val);
        }
        // now reset the buffer a few times
        for (int i = 0; i < 5; ++i) {
            iterator.reset();
            int count = 0;
            while (iterator.hasNext()) {
                Record target = iterator.next();
                int val = target.getField(0, IntValue.class).getValue();
                Assert.assertEquals(lower + (count++), val);
            }
            Assert.assertEquals(upper - lower, count);
        }
    } while (iterator.nextBlock());
    Assert.assertEquals(NUM_VALUES, upper);
    // close the iterator
    iterator.close();
}
Also used : DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) Record(org.apache.flink.types.Record) AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) IntValue(org.apache.flink.types.IntValue) Test(org.junit.Test)

Aggregations

AbstractInvokable (org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable)26 Test (org.junit.Test)23 DummyInvokable (org.apache.flink.runtime.operators.testutils.DummyInvokable)22 MemorySegment (org.apache.flink.core.memory.MemorySegment)14 Record (org.apache.flink.types.Record)8 ArrayList (java.util.ArrayList)7 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)6 IntValue (org.apache.flink.types.IntValue)6 Random (java.util.Random)5 TupleTypeInfo (org.apache.flink.api.java.typeutils.TupleTypeInfo)5 IOManager (org.apache.flink.runtime.io.disk.iomanager.IOManager)5 IOManagerAsync (org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync)5 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)5 IOException (java.io.IOException)4 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)3 StatefulTask (org.apache.flink.runtime.jobgraph.tasks.StatefulTask)3 List (java.util.List)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)2