this.memoryManager.allocatePages(this.parentTask, memory, NUM_MEMORY_SEGMENTS);
final SpillingBuffer outView = new SpillingBuffer(this.ioManager,
new ListMemorySegmentSource(memory), this.memoryManager.getPageSize());
// write a number of pairs
final Record rec = new Record();
for (int i = 0; i < NUM_PAIRS_EXTERNAL; i++) {
generator.next(rec);
rec.write(outView);
}
// create the reader input view
DataInputView inView = outView.flip();
generator.reset();
// read and re-generate all records and compare them
final Record readRec = new Record();
try {
for (int i = 0; i < NUM_PAIRS_EXTERNAL + 1; i++) {
generator.next(rec);
readRec.read(inView);
Key k1 = rec.getField(0, Key.class);
Value v1 = rec.getField(1, Value.class);
Key k2 = readRec.getField(0, Key.class);
Value v2 = readRec.getField(1, Value.class);
Assert.assertTrue("The re-generated and the read record do not match.", k1.equals(k2) && v1.equals(v2));
}
Assert.fail("Read too much, expected EOFException.");
}
catch (EOFException eofex) {
// expected
}
// re-read the data
inView = outView.flip();
generator.reset();
// read and re-generate all records and compare them
for (int i = 0; i < NUM_PAIRS_EXTERNAL; i++) {
generator.next(rec);
readRec.read(inView);
Key k1 = rec.getField(0, Key.class);
Value v1 = rec.getField(1, Value.class);
Key k2 = readRec.getField(0, Key.class);
Value v2 = readRec.getField(1, Value.class);
Assert.assertTrue("The re-generated and the read record do not match.", k1.equals(k2) && v1.equals(v2));
}
this.memoryManager.release(outView.close());