Snapshot getOrCreateSnapshot(long epoch) {
        Snapshot last = head.prev();
        if (last.epoch() > epoch) {
            throw new RuntimeException("Can't create a new in-memory snapshot at epoch " + epoch +
                " because there is already a snapshot with epoch " + last.epoch() + ". Snapshot epochs are " +
                epochsToString());
        } else if (last.epoch() == epoch) {
            return last;
        }
        Snapshot snapshot = new Snapshot(epoch);
        last.appendNext(snapshot);
        snapshots.put(epoch, snapshot);
        log.debug("Creating in-memory snapshot {}", epoch);
        return snapshot;
    }
@Test
    public void testCreateSnapshotOfLatest() {
        SnapshotRegistry registry = new SnapshotRegistry(new LogContext());
        registry.getOrCreateSnapshot(10);
        Snapshot latest = registry.getOrCreateSnapshot(12);
        Snapshot duplicate = registry.getOrCreateSnapshot(12);

        assertEquals(latest, duplicate);
    }