Implement deferred WaitQueue, DiskAvailability, and NoOpCache behavior with tests

This commit is contained in:
Joseph Doherty
2026-02-27 09:58:37 -05:00
parent 8849265780
commit a660e38575
11 changed files with 508 additions and 25 deletions

View File

@@ -0,0 +1,58 @@
// Copyright 2012-2026 The NATS Authors
// Licensed under the Apache License, Version 2.0
using Shouldly;
using ZB.MOM.NatsNet.Server;
namespace ZB.MOM.NatsNet.Server.Tests.JetStream;
public sealed class DiskAvailabilityTests
{
private const long JetStreamMaxStoreDefault = 1L * 1024 * 1024 * 1024 * 1024;
[Fact]
public void DiskAvailable_MissingDirectory_ShouldCreateDirectory()
{
var root = Path.Combine(Path.GetTempPath(), $"disk-avail-{Guid.NewGuid():N}");
var target = Path.Combine(root, "nested");
try
{
Directory.Exists(target).ShouldBeFalse();
var available = DiskAvailability.DiskAvailable(target);
Directory.Exists(target).ShouldBeTrue();
available.ShouldBeGreaterThan(0L);
}
finally
{
if (Directory.Exists(root))
Directory.Delete(root, recursive: true);
}
}
[Fact]
public void DiskAvailable_InvalidPath_ShouldReturnFallback()
{
var available = DiskAvailability.DiskAvailable("\0");
available.ShouldBe(JetStreamMaxStoreDefault);
}
[Fact]
public void Check_ShouldUseDiskAvailableThreshold()
{
var root = Path.Combine(Path.GetTempPath(), $"disk-check-{Guid.NewGuid():N}");
try
{
var available = DiskAvailability.DiskAvailable(root);
DiskAvailability.Check(root, Math.Max(0, available - 1)).ShouldBeTrue();
DiskAvailability.Check(root, available + 1).ShouldBeFalse();
}
finally
{
if (Directory.Exists(root))
Directory.Delete(root, recursive: true);
}
}
}