SnapshotManager implements SnapshotState { @Override public void commit(final long sequenceNumber, final long timeStamp) { currentState.commit(sequenceNumber, timeStamp); } SnapshotManager(final RaftActorContext context, final Logger logger); boolean isApplying(); @Override boolean isCapturing(); @Override boolean captureToInstall(final ReplicatedLogEntry lastLogEntry, final long replicatedToAllIndex,
            final String targetFollower); @Override boolean capture(final ReplicatedLogEntry lastLogEntry, final long replicatedToAllIndex); @Override boolean captureWithForcedTrim(final ReplicatedLogEntry lastLogEntry, final long replicatedToAllIndex); @Override void apply(final ApplySnapshot snapshot); @Override void persist(final Snapshot.State state, final Optional<OutputStream> installSnapshotStream,
            final long totalMemory); @Override void commit(final long sequenceNumber, final long timeStamp); @Override void rollback(); @Override long trimLog(final long desiredTrimIndex); Snapshot.@NonNull State convertSnapshot(final ByteSource snapshotBytes); long getLastSequenceNumber(); @VisibleForTesting CaptureSnapshot getCaptureSnapshot(); CaptureSnapshot newCaptureSnapshot(final ReplicatedLogEntry lastLogEntry, final long replicatedToAllIndex,
                                              final boolean mandatoryTrim);  }
@Test public void testCommit() { doReturn(50L).when(mockDataPersistenceProvider).getLastSequenceNumber(); snapshotManager.capture(new SimpleReplicatedLogEntry(9, 6, new MockRaftActorContext.MockPayload()), -1); snapshotManager.persist(ByteState.empty(), Optional.empty(), Runtime.getRuntime().totalMemory()); assertEquals(true, snapshotManager.isCapturing()); snapshotManager.commit(100L, 1234L); assertEquals(false, snapshotManager.isCapturing()); verify(mockReplicatedLog).snapshotCommit(); verify(mockDataPersistenceProvider).deleteMessages(50L); ArgumentCaptor<SnapshotSelectionCriteria> criteriaCaptor = ArgumentCaptor.forClass(SnapshotSelectionCriteria.class); verify(mockDataPersistenceProvider).deleteSnapshots(criteriaCaptor.capture()); assertEquals(Long.MAX_VALUE, criteriaCaptor.getValue().maxSequenceNr()); assertEquals(1233L, criteriaCaptor.getValue().maxTimestamp()); MessageCollectorActor.expectFirstMatching(actorRef, SnapshotComplete.class); }
@Test public void testCommitBeforeCapture() { snapshotManager.commit(100L, 0); verify(mockReplicatedLog, never()).snapshotCommit(); verify(mockDataPersistenceProvider, never()).deleteMessages(anyLong()); verify(mockDataPersistenceProvider, never()).deleteSnapshots(any(SnapshotSelectionCriteria.class)); }