NormalizedKeySorter<Record> sorter = newSortBuffer(memory);
TestData.Generator generator = new TestData.Generator(SEED, KEY_MAX, VALUE_LENGTH, KeyMode.RANDOM, ValueMode.FIX_LENGTH);
// write the buffer full with the first set of records
Record record = new Record();
int num = -1;
do {
generator.next(record);
num++;
}
while (sorter.write(record));
sorter.reset();
// write a second sequence of records. since the values are of fixed length, we must be able to write an equal number
generator = new TestData.Generator(SEED2, KEY_MAX, VALUE_LENGTH, KeyMode.RANDOM, ValueMode.FIX_LENGTH);
// write the buffer full with the first set of records
int num2 = -1;
do {
generator.next(record);
num2++;
}
while (sorter.write(record));
Assert.assertEquals("The number of records written after the reset was not the same as before.", num, num2);
// re-read the records
generator.reset();
Record readTarget = new Record();
int i = 0;
while (i < num) {
generator.next(record);
readTarget = sorter.getRecord(readTarget, i++);
Key rk = readTarget.getField(0, Key.class);
Key gk = record.getField(0, Key.class);
Value rv = readTarget.getField(1, Value.class);
Value gv = record.getField(1, Value.class);
Assert.assertEquals("The re-read key is wrong", gk, rk);
Assert.assertEquals("The re-read value is wrong", gv, rv);
}