Implement deferred WaitQueue, DiskAvailability, and NoOpCache behavior with tests
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user