@Test
public void testIterator() {

    MemoryRecords recs1 = MemoryRecords.emptyRecords(ByteBuffer.allocate(1024), compression);
    MemoryRecords recs2 = MemoryRecords.emptyRecords(ByteBuffer.allocate(1024), compression);
    List<Record> list = Arrays.asList(new Record(0L, "a".getBytes(), "1".getBytes()),
                                      new Record(0L, "b".getBytes(), "2".getBytes()),
                                      new Record(0L, "c".getBytes(), "3".getBytes()));
    for (int i = 0; i < list.size(); i++) {
        Record r = list.get(i);
        recs1.append(i, r);
        recs2.append(i, 0L, toArray(r.key()), toArray(r.value()));
    }
    recs1.close();
    recs2.close();
    for (int iteration = 0; iteration < 2; iteration++) {
        for (MemoryRecords recs : Arrays.asList(recs1, recs2)) {
            Iterator<LogEntry> iter = recs.iterator();
            for (int i = 0; i < list.size(); i++) {
                assertTrue(iter.hasNext());
                LogEntry entry = iter.next();
                assertEquals((long) i, entry.offset());
                assertEquals(list.get(i), entry.record());
                entry.record().ensureValid();
            }
            assertFalse(iter.hasNext());
        }
    }
}