@Test
public void testCommit() {

    doReturn(50L).when(mockDataPersistenceProvider).getLastSequenceNumber();
    // when replicatedToAllIndex = -1
    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);
}