AbstractReplicatedLogImpl implements ReplicatedLog { @Override public long removeFrom(long logEntryIndex) { int adjustedIndex = adjustedIndex(logEntryIndex); if (adjustedIndex < 0 || adjustedIndex >= journal.size()) { return -1; } for (int i = adjustedIndex; i < journal.size(); i++) { dataSize -= journal.get(i).size(); } journal.subList(adjustedIndex , journal.size()).clear(); return adjustedIndex; } protected  AbstractReplicatedLogImpl(long snapshotIndex, long snapshotTerm,
            List<ReplicatedLogEntry> unAppliedEntries, String logContext); protected  AbstractReplicatedLogImpl(); @Override ReplicatedLogEntry get(long logEntryIndex); @Override ReplicatedLogEntry last(); @Override long lastIndex(); @Override long lastTerm(); @Override long removeFrom(long logEntryIndex); @Override boolean append(ReplicatedLogEntry replicatedLogEntry); @Override void increaseJournalLogCapacity(int amount); @Override List<ReplicatedLogEntry> getFrom(long logEntryIndex); @Override List<ReplicatedLogEntry> getFrom(long logEntryIndex, int maxEntries, long maxDataSize); @Override long size(); @Override int dataSize(); @Override boolean isPresent(long logEntryIndex); @Override boolean isInSnapshot(long logEntryIndex); @Override long getSnapshotIndex(); @Override long getSnapshotTerm(); @Override void setSnapshotIndex(long snapshotIndex); @Override void setSnapshotTerm(long snapshotTerm); @Override void clear(int startIndex, int endIndex); @Override void snapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm); @Override void snapshotCommit(); @Override void snapshotRollback();  }
@Test public void testRemoveFrom() { replicatedLogImpl.append(new SimpleReplicatedLogEntry(4, 2, new MockPayload("E", 2))); replicatedLogImpl.append(new SimpleReplicatedLogEntry(5, 2, new MockPayload("F", 3))); assertEquals("dataSize", 9, replicatedLogImpl.dataSize()); long adjusted = replicatedLogImpl.removeFrom(4); assertEquals("removeFrom - adjusted", 4, adjusted); assertEquals("size", 4, replicatedLogImpl.size()); assertEquals("dataSize", 4, replicatedLogImpl.dataSize()); takeSnapshot(1); adjusted = replicatedLogImpl.removeFrom(2); assertEquals("removeFrom - adjusted", 1, adjusted); assertEquals("size", 1, replicatedLogImpl.size()); assertEquals("dataSize", 1, replicatedLogImpl.dataSize()); assertEquals("removeFrom - adjusted", -1, replicatedLogImpl.removeFrom(0)); assertEquals("removeFrom - adjusted", -1, replicatedLogImpl.removeFrom(100)); }