@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()); } } }
@Override public Iterator<LogEntry> iterator() { if (writable) { return new RecordsIterator((ByteBuffer) this.buffer.duplicate() .flip(), false); } else { return new RecordsIterator(this.buffer.duplicate(), false); } }
MemoryRecords implements Records { @Override public Iterator<LogEntry> iterator() { if (writable) { return new RecordsIterator((ByteBuffer) this.buffer.duplicate() .flip(), false); } else { return new RecordsIterator(this.buffer.duplicate(), false); } } }
MemoryRecords implements Records { @Override public Iterator<LogEntry> iterator() { if (writable) { return new RecordsIterator((ByteBuffer) this.buffer.duplicate() .flip(), false); } else { return new RecordsIterator(this.buffer.duplicate(), false); } } private  MemoryRecords(ByteBuffer buffer, CompressionType type, boolean writable, int writeLimit); }
MemoryRecords implements Records { @Override public Iterator<LogEntry> iterator() { if (writable) { return new RecordsIterator((ByteBuffer) this.buffer.duplicate() .flip(), false); } else { return new RecordsIterator(this.buffer.duplicate(), false); } } private  MemoryRecords(ByteBuffer buffer, CompressionType type, boolean writable, int writeLimit); static MemoryRecords emptyRecords(ByteBuffer buffer, CompressionType type, int writeLimit); static MemoryRecords emptyRecords(ByteBuffer buffer, CompressionType type); static MemoryRecords readableRecords(ByteBuffer buffer); void append(long offset, Record record); long append(long offset, long timestamp, byte[] key, byte[] value); boolean isFull(); boolean hasRoomFor(byte[] key, byte[] value); void close(); int sizeInBytes(); double compressionRate(); int initialCapacity(); ByteBuffer buffer(); @Override Iterator<LogEntry> iterator(); @Override String toString(); boolean isWritable(); }
MemoryRecords implements Records { @Override public Iterator<LogEntry> iterator() { if (writable) { return new RecordsIterator((ByteBuffer) this.buffer.duplicate() .flip(), false); } else { return new RecordsIterator(this.buffer.duplicate(), false); } } private  MemoryRecords(ByteBuffer buffer, CompressionType type, boolean writable, int writeLimit); static MemoryRecords emptyRecords(ByteBuffer buffer, CompressionType type, int writeLimit); static MemoryRecords emptyRecords(ByteBuffer buffer, CompressionType type); static MemoryRecords readableRecords(ByteBuffer buffer); void append(long offset, Record record); long append(long offset, long timestamp, byte[] key, byte[] value); boolean isFull(); boolean hasRoomFor(byte[] key, byte[] value); void close(); int sizeInBytes(); double compressionRate(); int initialCapacity(); ByteBuffer buffer(); @Override Iterator<LogEntry> iterator(); @Override String toString(); boolean isWritable();  }