feat(batch17): port inbound, header, and service-import client features

This commit is contained in:
Joseph Doherty
2026-02-28 19:18:37 -05:00
parent 1baba5ac0e
commit 8d5964efff
5 changed files with 298 additions and 4 deletions

View File

@@ -239,4 +239,48 @@ public sealed class ClientConnectionStubFeaturesTests
c.PubAllowedFullCheck("_R_.x", fullCheck: true, hasLock: true).ShouldBeTrue();
c.PubAllowedFullCheck("_R_.x", fullCheck: true, hasLock: true).ShouldBeFalse();
}
[Fact]
public void InboundAndHeaderHelpers_GroupB_ShouldBehave()
{
ClientConnection.IsReservedReply(Encoding.ASCII.GetBytes("_R_.A.B")).ShouldBeTrue();
ClientConnection.IsReservedReply(Encoding.ASCII.GetBytes("$JS.ACK.A.B")).ShouldBeTrue();
ClientConnection.IsReservedReply(Encoding.ASCII.GetBytes("$GNR.A.B")).ShouldBeTrue();
ClientConnection.IsReservedReply(Encoding.ASCII.GetBytes("foo.bar")).ShouldBeFalse();
var c = new ClientConnection(ClientKind.Client)
{
ParseCtx = { Pa = { HeaderSize = 0 } },
};
var before = DateTime.UtcNow;
c.ProcessInboundMsg(Encoding.ASCII.GetBytes("data"));
c.LastIn.ShouldBeGreaterThan(before - TimeSpan.FromMilliseconds(1));
c.Subs["sid"] = new Subscription { Sid = Encoding.ASCII.GetBytes("sid"), Subject = Encoding.ASCII.GetBytes("foo") };
c.SubForReply(Encoding.ASCII.GetBytes("inbox")).ShouldNotBeNull();
var header = ClientConnection.GenHeader(null, "X-Test", "one");
Encoding.ASCII.GetString(ClientConnection.GetHeader("X-Test", header)!).ShouldBe("one");
ClientConnection.GetHeaderKeyIndex("X-Test", header).ShouldBeGreaterThan(0);
ClientConnection.SliceHeader("X-Test", header).ShouldNotBeNull();
var replaced = ClientConnection.SetHeaderStatic("X-Test", "two", header);
Encoding.ASCII.GetString(ClientConnection.GetHeader("X-Test", replaced)!).ShouldBe("two");
ClientConnection.RemoveHeaderIfPresent(replaced, "X-Test").ShouldBeNull();
var prefixed = ClientConnection.GenHeader(header, "Nats-Expected-Last-Sequence", "10");
ClientConnection.RemoveHeaderIfPrefixPresent(prefixed!, "Nats-Expected-").ShouldNotBeNull();
c.ParseCtx.Pa.HeaderSize = header.Length;
var merged = new byte[header.Length + 5];
Buffer.BlockCopy(header, 0, merged, 0, header.Length);
Buffer.BlockCopy("hello"u8.ToArray(), 0, merged, header.Length, 5);
var next = c.SetHeaderInternal("X-Test", "three", merged);
Encoding.ASCII.GetString(next).ShouldContain("X-Test: three");
var result = new SubscriptionIndexResult();
result.PSubs.Add(new Subscription { Subject = Encoding.ASCII.GetBytes("foo"), Sid = Encoding.ASCII.GetBytes("1") });
c.ProcessMsgResults(null, result, "hello\r\n"u8.ToArray(), null, Encoding.ASCII.GetBytes("foo"), null, PmrFlags.None).didDeliver.ShouldBeTrue();
}
}