AbstractReplicatedLogImpl implements ReplicatedLog { @Override public void snapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm) { Preconditions.checkArgument(snapshotCapturedIndex >= snapshotIndex, "snapshotCapturedIndex must be greater than or equal to snapshotIndex"); snapshottedJournal = new ArrayList<>(journal.size()); List<ReplicatedLogEntry> snapshotJournalEntries = journal.subList(0, (int) (snapshotCapturedIndex - snapshotIndex)); snapshottedJournal.addAll(snapshotJournalEntries); snapshotJournalEntries.clear(); previousSnapshotIndex = snapshotIndex; setSnapshotIndex(snapshotCapturedIndex); previousSnapshotTerm = snapshotTerm; setSnapshotTerm(snapshotCapturedTerm); } 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 testSnapshotPreCommit() { replicatedLogImpl.append(new SimpleReplicatedLogEntry(4, 2, new MockPayload("E"))); replicatedLogImpl.append(new SimpleReplicatedLogEntry(5, 2, new MockPayload("F"))); replicatedLogImpl.append(new SimpleReplicatedLogEntry(6, 3, new MockPayload("G"))); replicatedLogImpl.append(new SimpleReplicatedLogEntry(7, 3, new MockPayload("H"))); replicatedLogImpl.snapshotPreCommit(-1, -1); assertEquals(8, replicatedLogImpl.size()); assertEquals(-1, replicatedLogImpl.getSnapshotIndex()); assertEquals(-1, replicatedLogImpl.getSnapshotTerm()); replicatedLogImpl.snapshotPreCommit(4, 2); assertEquals(3, replicatedLogImpl.size()); assertEquals(4, replicatedLogImpl.getSnapshotIndex()); assertEquals(2, replicatedLogImpl.getSnapshotTerm()); replicatedLogImpl.snapshotPreCommit(6, 3); assertEquals(1, replicatedLogImpl.size()); assertEquals(6, replicatedLogImpl.getSnapshotIndex()); assertEquals(3, replicatedLogImpl.getSnapshotTerm()); replicatedLogImpl.snapshotPreCommit(7, 3); assertEquals(0, replicatedLogImpl.size()); assertEquals(7, replicatedLogImpl.getSnapshotIndex()); assertEquals(3, replicatedLogImpl.getSnapshotTerm()); replicatedLogImpl.snapshotPreCommit(7, 3); assertEquals(0, replicatedLogImpl.size()); assertEquals(7, replicatedLogImpl.getSnapshotIndex()); assertEquals(3, replicatedLogImpl.getSnapshotTerm()); }