public void deleteSnapshotsBefore(long offset) throws IOException {
        for (SnapshotFile snapshot : snapshots.subMap(0L, offset).values()) {
            removeAndDeleteSnapshot(snapshot.offset);
        }
    }
@Test
    public void testDeleteSnapshotsBefore() throws IOException {
        appendClientEntry(stateManager, producerId, epoch, defaultSequence, 0L, false);
        appendClientEntry(stateManager, producerId, epoch, 1, 1L, false);
        stateManager.takeSnapshot();
        assertEquals(1, Objects.requireNonNull(logDir.listFiles()).length);
        assertEquals(singleton(2L), currentSnapshotOffsets());

        appendClientEntry(stateManager, producerId, epoch, 2, 2L, false);
        stateManager.takeSnapshot();
        assertEquals(2, Objects.requireNonNull(logDir.listFiles()).length);
        assertEquals(new HashSet<>(asList(2L, 3L)), currentSnapshotOffsets());

        stateManager.deleteSnapshotsBefore(3L);
        assertEquals(1, Objects.requireNonNull(logDir.listFiles()).length);
        assertEquals(singleton(3L), currentSnapshotOffsets());

        stateManager.deleteSnapshotsBefore(4L);
        assertEquals(0, Objects.requireNonNull(logDir.listFiles()).length);
        assertEquals(emptySet(), currentSnapshotOffsets());
    }