@Override
    public long freeze() {
        finalizeSnapshotWithFooter();
        appendBatches(accumulator.drain());
        snapshot.freeze();
        accumulator.close();
        return snapshot.sizeInBytes();
    }
@Test
    void testBuilderKRaftVersion0() {
        OffsetAndEpoch snapshotId = new OffsetAndEpoch(100, 10);
        int maxBatchSize = 1024;
        AtomicReference<ByteBuffer> buffer = new AtomicReference<>(null);
        RecordsSnapshotWriter.Builder builder = new RecordsSnapshotWriter.Builder()
            .setKraftVersion(KRaftVersion.KRAFT_VERSION_0)
            .setVoterSet(Optional.empty())
            .setTime(new MockTime())
            .setMaxBatchSize(maxBatchSize)
            .setRawSnapshotWriter(
                new MockRawSnapshotWriter(snapshotId, buffer::set)
            );
        try (RecordsSnapshotWriter<String> snapshot = builder.build(STRING_SERDE)) {
            snapshot.freeze();
        }

        try (RecordsSnapshotReader<String> reader = RecordsSnapshotReader.of(
                new MockRawSnapshotReader(snapshotId, buffer.get()),
                STRING_SERDE,
                BufferSupplier.NO_CACHING,
                maxBatchSize,
                true
            )
        ) {
            // Consume the control record batch
            Batch<String> batch = reader.next();
            assertEquals(1, batch.controlRecords().size());

            // Check snapshot header control record
            assertEquals(ControlRecordType.SNAPSHOT_HEADER, batch.controlRecords().get(0).type());
            assertEquals(new SnapshotHeaderRecord(), batch.controlRecords().get(0).message());

            // Consume the reader until we find a control record
            do {
                batch = reader.next();
            }
            while (batch.controlRecords().isEmpty());

            // Check snapshot footer control record
            assertEquals(1, batch.controlRecords().size());
            assertEquals(ControlRecordType.SNAPSHOT_FOOTER, batch.controlRecords().get(0).type());
            assertEquals(new SnapshotFooterRecord(), batch.controlRecords().get(0).message());

            // Snapshot footer must be last record
            assertFalse(reader.hasNext());
        }
    }