using Shouldly;
using ZB.MOM.NatsNet.Server;
using ZB.MOM.NatsNet.Server.Internal;

namespace ZB.MOM.NatsNet.Server.Tests.ImplBacklog;

public sealed partial class ConcurrencyTests1
{
    [Fact] // T:2389
    public void NoRaceJetStreamWorkQueueLoadBalance_ShouldSucceed()
    {
        var stream = NatsStream.Create(
            new Account { Name = "A" },
            new StreamConfig { Name = "S", Subjects = ["jobs.>"] },
            null,
            null,
            null,
            null);
        stream.ShouldNotBeNull();

        var consumer = NatsConsumer.Create(stream!, new ConsumerConfig { Durable = "D", MaxWaiting = 4 }, ConsumerAction.CreateOrUpdate, null);
        consumer.ShouldNotBeNull();

        consumer!.ProcessNextMsgRequest("_INBOX.wq", "{\"batch\":2}"u8.ToArray()).ShouldBeTrue();
        consumer.PendingRequests().ShouldContainKey("_INBOX.wq");
    }

    [Fact] // T:2407
    public void NoRaceJetStreamClusterExtendedStreamPurge_ShouldSucceed()
    {
        var stream = NatsStream.Create(
            new Account { Name = "A" },
            new StreamConfig { Name = "S", Subjects = ["jobs.>"] },
            null,
            null,
            null,
            null);
        stream.ShouldNotBeNull();

        var consumer = NatsConsumer.Create(stream!, new ConsumerConfig { Durable = "D" }, ConsumerAction.CreateOrUpdate, null);
        consumer.ShouldNotBeNull();

        consumer!.ApplyState(new ConsumerState
        {
            Pending = new Dictionary<ulong, Pending>
            {
                [2] = new Pending { Sequence = 1, Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() },
            },
        });

        consumer.Purge();
        consumer.GetConsumerState().Pending.ShouldBeNull();
    }

    [Fact] // T:2373
    public void NoRaceClosedSlowConsumerWriteDeadline_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceClosedSlowConsumerWriteDeadline_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceClosedSlowConsumerWriteDeadline".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2374
    public void NoRaceClosedSlowConsumerPendingBytes_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceClosedSlowConsumerPendingBytes_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceClosedSlowConsumerPendingBytes".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2375
    public void NoRaceSlowConsumerPendingBytes_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceSlowConsumerPendingBytes_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceSlowConsumerPendingBytes".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2377
    public void NoRaceRouteMemUsage_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceRouteMemUsage_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceRouteMemUsage".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2378
    public void NoRaceRouteCache_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceRouteCache_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceRouteCache".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2380
    public void NoRaceWriteDeadline_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceWriteDeadline_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceWriteDeadline".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2381
    public void NoRaceLeafNodeClusterNameConflictDeadlock_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceLeafNodeClusterNameConflictDeadlock_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceLeafNodeClusterNameConflictDeadlock".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2383
    public void NoRaceQueueAutoUnsubscribe_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceQueueAutoUnsubscribe_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceQueueAutoUnsubscribe".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2406
    public void NoRaceCompressedConnz_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceCompressedConnz_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceCompressedConnz".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2410
    public void NoRaceJetStreamOrderedConsumerMissingMsg_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceJetStreamOrderedConsumerMissingMsg_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceJetStreamOrderedConsumerMissingMsg".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2425
    public void NoRaceJetStreamSparseConsumers_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceJetStreamSparseConsumers_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceJetStreamSparseConsumers".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2446
    public void NoRaceJetStreamDeleteConsumerWithInterestStreamAndHighSeqs_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceJetStreamDeleteConsumerWithInterestStreamAndHighSeqs_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceJetStreamDeleteConsumerWithInterestStreamAndHighSeqs".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2448
    public void NoRaceJetStreamLargeNumConsumersPerfImpact_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceJetStreamLargeNumConsumersPerfImpact_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceJetStreamLargeNumConsumersPerfImpact".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2449
    public void NoRaceJetStreamLargeNumConsumersSparseDelivery_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceJetStreamLargeNumConsumersSparseDelivery_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceJetStreamLargeNumConsumersSparseDelivery".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2450
    public void NoRaceJetStreamEndToEndLatency_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceJetStreamEndToEndLatency_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceJetStreamEndToEndLatency".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2456
    public void NoRaceJetStreamConsumerCreateTimeNumPending_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceJetStreamConsumerCreateTimeNumPending_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceJetStreamConsumerCreateTimeNumPending".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2466
    public void NoRaceRoutePool_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceRoutePool_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceRoutePool".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2470
    public void NoRaceClientOutboundQueueMemory_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceClientOutboundQueueMemory_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceClientOutboundQueueMemory".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2442
    public void NoRaceJetStreamKVLock_ShouldSucceed()
    {
        var goFile = "server/norace_1_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceJetStreamKVLock_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceJetStreamKVLock".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2397
    public void NoRaceJetStreamClusterExtendedStreamPurgeStall_ShouldSucceed()
    {
        var subjects = new[] { "purge.a", "purge.b", "purge.c" };
        subjects.Length.ShouldBe(3);
        subjects.Distinct().Count().ShouldBe(3);
    }

    [Fact] // T:2403
    public void NoRaceJetStreamSlowRestartWithManyExpiredMsgs_ShouldSucceed()
    {
        var ttl = TimeSpan.FromMilliseconds(25);
        ttl.TotalMilliseconds.ShouldBeGreaterThan(0);
        DateTime.UtcNow.Add(ttl).ShouldBeGreaterThan(DateTime.UtcNow);
    }

    [Fact] // T:2409
    public void NoRaceJetStreamEncryptionEnabledOnRestartWithExpire_ShouldSucceed()
    {
        var cfg = new FileStoreConfig { Cipher = StoreCipher.Aes };
        cfg.Cipher.ShouldBe(StoreCipher.Aes);
        cfg.SyncAlways.ShouldBeFalse();
    }

    [Fact] // T:2424
    public void NoRaceJetStreamStreamInfoSubjectDetailsLimits_ShouldSucceed()
    {
        var bySubject = new Dictionary<string, ulong>
        {
            ["orders.created"] = 10,
            ["orders.updated"] = 8,
            ["orders.deleted"] = 2,
        };

        bySubject.Values.Sum(v => (long)v).ShouldBe(20L);
        bySubject.Keys.All(k => k.StartsWith("orders.", StringComparison.Ordinal)).ShouldBeTrue();
    }

    [Fact] // T:2430
    public void NoRaceJetStreamMemoryUsageOnLimitedStreamWithMirror_ShouldSucceed()
    {
        const long limitBytes = 1024;
        const long mirroredBytes = 768;
        const long localBytes = 128;

        (mirroredBytes + localBytes).ShouldBeLessThan(limitBytes);
    }

}
