feat: enforce filestore durability and recovery invariants

This commit is contained in:
Joseph Doherty
2026-02-23 14:51:30 -05:00
parent 3896512f84
commit 56177a7099
3 changed files with 77 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
using NATS.Server.JetStream.Storage;
namespace NATS.Server.Tests.JetStream;
public class JetStreamFileStoreRecoveryStrictParityTests
{
[Fact]
public async Task Filestore_recovery_preserves_sequence_subject_index_and_integrity_after_prune_and_restart_cycles()
{
var dir = Path.Combine(Path.GetTempPath(), $"nats-js-fs-recovery-{Guid.NewGuid():N}");
var options = new FileStoreOptions { Directory = dir };
try
{
await using (var store = new FileStore(options))
{
await store.AppendAsync("orders.created", "a"u8.ToArray(), default);
await store.AppendAsync("orders.created", "b"u8.ToArray(), default);
await store.RemoveAsync(2, default);
}
await using var reopened = new FileStore(options);
var state = await reopened.GetStateAsync(default);
state.Messages.ShouldBe((ulong)1);
state.LastSeq.ShouldBe((ulong)1);
var msg1 = await reopened.LoadAsync(1, default);
msg1.ShouldNotBeNull();
msg1.Subject.ShouldBe("orders.created");
}
finally
{
if (Directory.Exists(dir))
Directory.Delete(dir, recursive: true);
}
}
}