batch36 task5-6 group-d-e and test waves t3-t4

This commit is contained in:
Joseph Doherty
2026-02-28 23:20:30 -05:00
parent 856cd17554
commit f38c0e6b6e
11 changed files with 1030 additions and 6 deletions

View File

@@ -1,5 +1,7 @@
using System.Text;
using Shouldly;
using ZB.MOM.NatsNet.Server;
using ZB.MOM.NatsNet.Server.Internal;
namespace ZB.MOM.NatsNet.Server.Tests.JetStream;
@@ -161,6 +163,84 @@ public sealed class StreamLifecycleGroupBTests
NatsStream.CalculateRetryBackoff(1000).ShouldBe(TimeSpan.FromMinutes(2));
}
[Fact]
public void GroupD_SourceConsumersAndAckParsing_Behave()
{
var stream = CreateStream(new StreamConfig
{
Name = "ORDERS",
Subjects = ["orders.*"],
Storage = StorageType.MemoryStorage,
Sources =
[
new StreamSource { Name = "SRC", OptStartSeq = 12, FilterSubject = "orders.*" },
],
});
stream.SetupSourceConsumers();
var source = stream.StreamSource("SRC orders.* >");
source.ShouldNotBeNull();
source!.Name.ShouldBe("SRC");
stream.StartingSequenceForSources(source.IndexName).ShouldBe(12UL);
stream.SetupSourceConsumer(source.IndexName, 20, DateTime.UtcNow);
stream.ProcessInboundSourceMsg(source.IndexName, new InMsg { Subject = "orders.created", Msg = "x"u8.ToArray() }).ShouldBeTrue();
stream.ResetSourceInfo(source.IndexName);
stream.RetrySourceConsumerAtSeq(source.IndexName, 30);
stream.StartingSequenceForSources(source.IndexName).ShouldBe(30UL);
NatsStream.StreamAndSeqFromAckReply("ORDERS.99").ShouldBe(("ORDERS", 99UL));
NatsStream.StreamAndSeq("A.B.C").ShouldBe(("A", 0UL));
}
[Fact]
public void GroupD_MirrorAndControlPaths_Behave()
{
var stream = CreateStream();
stream.SetupMirrorConsumer();
stream.ProcessInboundMirrorMsg(new InMsg
{
Subject = "$JS.FC.orders",
Reply = "reply",
Hdr = Encoding.ASCII.GetBytes("NATS/1.0\r\n\r\n"),
}).ShouldBeTrue();
stream.ProcessMirrorMsgs(new StreamSourceInfo { Name = "M", Lag = 2 }, [new InMsg { Subject = "orders.created", Msg = [1] }]);
stream.RetryDisconnectedSyncConsumers();
}
[Fact]
public void GroupE_SubscriptionsAndInflightCleanup_Behave()
{
var stream = CreateStream();
stream.SubscribeToDirect();
stream.SubscribeToMirrorDirect();
var (sub, subErr) = stream.SubscribeInternal("orders.created", handler: null);
subErr.ShouldBeNull();
sub.ShouldNotBeNull();
var (qsub, qErr) = stream.QueueSubscribeInternal("orders.updated", "Q", handler: null);
qErr.ShouldBeNull();
qsub.ShouldNotBeNull();
qsub!.Queue.ShouldNotBeNull();
stream.UnsubscribeInternal("orders.created").ShouldBeNull();
stream.RemoveInternalConsumer("orders.updated");
stream.SubscribeToStream();
stream.UnsubscribeToStream();
stream.DeleteInflightBatches(preserveState: false);
stream.DeleteBatchApplyState();
stream.StopSourceConsumers();
stream.UnsubscribeToDirect();
stream.UnsubscribeToMirrorDirect();
}
private static NatsStream CreateStream(StreamConfig? cfg = null)
{
cfg ??= new StreamConfig { Name = "ORDERS", Subjects = ["orders.*"], Storage = StorageType.MemoryStorage };