@Test public void testAppendEntry() throws IOException { ByteArraySeekableFile seekableFile = new ByteArraySeekableFile(); EntriesFile file = new EntriesFile(seekableFile); Assert.assertEquals(0L, file.appendEntry(new NoOpEntry(2, 3))); seekableFile.seek(0); Assert.assertEquals(Entry.KIND_NO_OP, seekableFile.readInt()); Assert.assertEquals(2, seekableFile.readInt()); Assert.assertEquals(3, seekableFile.readInt()); Assert.assertEquals(0, seekableFile.readInt()); byte[] commandBytes = "test".getBytes(); Assert.assertEquals(16L, file.appendEntry(new GeneralEntry(3, 3, commandBytes))); seekableFile.seek(16L); Assert.assertEquals(Entry.KIND_GENERAL, seekableFile.readInt()); Assert.assertEquals(3, seekableFile.readInt()); Assert.assertEquals(3, seekableFile.readInt()); Assert.assertEquals(4, seekableFile.readInt()); byte[] buffer = new byte[4]; seekableFile.read(buffer); Assert.assertArrayEquals(commandBytes, buffer); }
public long appendEntry(Entry entry) throws IOException { long offset = seekableFile.size(); seekableFile.seek(offset); seekableFile.writeInt(entry.getKind()); seekableFile.writeInt(entry.getIndex()); seekableFile.writeInt(entry.getTerm()); byte[] commandBytes = entry.getCommandBytes(); seekableFile.writeInt(commandBytes.length); seekableFile.write(commandBytes); return offset; }
EntriesFile { public long appendEntry(Entry entry) throws IOException { long offset = seekableFile.size(); seekableFile.seek(offset); seekableFile.writeInt(entry.getKind()); seekableFile.writeInt(entry.getIndex()); seekableFile.writeInt(entry.getTerm()); byte[] commandBytes = entry.getCommandBytes(); seekableFile.writeInt(commandBytes.length); seekableFile.write(commandBytes); return offset; } }
EntriesFile { public long appendEntry(Entry entry) throws IOException { long offset = seekableFile.size(); seekableFile.seek(offset); seekableFile.writeInt(entry.getKind()); seekableFile.writeInt(entry.getIndex()); seekableFile.writeInt(entry.getTerm()); byte[] commandBytes = entry.getCommandBytes(); seekableFile.writeInt(commandBytes.length); seekableFile.write(commandBytes); return offset; } EntriesFile(File file);  EntriesFile(SeekableFile seekableFile); }
EntriesFile { public long appendEntry(Entry entry) throws IOException { long offset = seekableFile.size(); seekableFile.seek(offset); seekableFile.writeInt(entry.getKind()); seekableFile.writeInt(entry.getIndex()); seekableFile.writeInt(entry.getTerm()); byte[] commandBytes = entry.getCommandBytes(); seekableFile.writeInt(commandBytes.length); seekableFile.write(commandBytes); return offset; } EntriesFile(File file);  EntriesFile(SeekableFile seekableFile); long appendEntry(Entry entry); Entry loadEntry(long offset, EntryFactory factory); long size(); void clear(); void truncate(long offset); void close(); }
EntriesFile { public long appendEntry(Entry entry) throws IOException { long offset = seekableFile.size(); seekableFile.seek(offset); seekableFile.writeInt(entry.getKind()); seekableFile.writeInt(entry.getIndex()); seekableFile.writeInt(entry.getTerm()); byte[] commandBytes = entry.getCommandBytes(); seekableFile.writeInt(commandBytes.length); seekableFile.write(commandBytes); return offset; } EntriesFile(File file);  EntriesFile(SeekableFile seekableFile); long appendEntry(Entry entry); Entry loadEntry(long offset, EntryFactory factory); long size(); void clear(); void truncate(long offset); void close();  }