using NATS.Server.JetStream.Storage;

namespace NATS.Server.JetStream.Tests;

public class JetStreamFileStoreLayoutParityTests
{
    [Fact]
    public async Task File_store_uses_block_index_layout_with_ttl_prune_invariants()
    {
        var dir = Path.Combine(Path.GetTempPath(), $"natsdotnet-filestore-{Guid.NewGuid():N}");
        try
        {
            await using var store = new FileStore(new FileStoreOptions
            {
                Directory = dir,
                BlockSizeBytes = 128,
                MaxAgeMs = 60_000,
            });

            for (var i = 0; i < 100; i++)
                await store.AppendAsync($"orders.{i}", "x"u8.ToArray(), default);

            var state = await store.GetStateAsync(default);
            state.Messages.ShouldBe((ulong)100);
            store.BlockCount.ShouldBeGreaterThan(1);
        }
        finally
        {
            if (Directory.Exists(dir))
                Directory.Delete(dir, recursive: true);
        }
    }
}
