feat(batch17): port inbound, header, and service-import client features
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,6 +181,20 @@ public class ProtocolParserTests
|
||||
Encoding.ASCII.GetString(c.ArgBuf!).ShouldBe("foo 1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClientConnection_InboundDispatchAndPingIntervalHelpers_ShouldBehave()
|
||||
{
|
||||
var c = new ClientConnection(ClientKind.Client);
|
||||
var before = DateTime.UtcNow;
|
||||
c.ProcessInboundMsg(Encoding.ASCII.GetBytes("hello"));
|
||||
c.LastIn.ShouldBeGreaterThan(before - TimeSpan.FromMilliseconds(1));
|
||||
|
||||
ClientConnection.AdjustPingInterval(ClientKind.Router, TimeSpan.FromHours(1))
|
||||
.ShouldBeLessThan(TimeSpan.FromHours(1));
|
||||
ClientConnection.AdjustPingInterval(ClientKind.Gateway, TimeSpan.FromHours(1))
|
||||
.ShouldBeLessThan(TimeSpan.FromHours(1));
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// TestParsePub — Go test ID 2602
|
||||
// =====================================================================
|
||||
|
||||
Reference in New Issue
Block a user