test(batch23): port and verify mapped route tests
This commit is contained in:
@@ -77,16 +77,30 @@ public sealed partial class NatsServer
|
|||||||
internal Exception? SetRouteInfoHostPortAndIP()
|
internal Exception? SetRouteInfoHostPortAndIP()
|
||||||
{
|
{
|
||||||
var opts = GetOpts();
|
var opts = GetOpts();
|
||||||
var host = opts.Cluster.Host;
|
string host;
|
||||||
if (string.IsNullOrWhiteSpace(host))
|
int port;
|
||||||
host = opts.Host;
|
if (!string.IsNullOrWhiteSpace(opts.Cluster.Advertise))
|
||||||
|
{
|
||||||
|
var (advHost, advPort, advErr) = Internal.ServerUtilities.ParseHostPort(opts.Cluster.Advertise, opts.Cluster.Port);
|
||||||
|
if (advErr != null)
|
||||||
|
return new InvalidOperationException($"Cluster.Advertise invalid: {opts.Cluster.Advertise}", advErr);
|
||||||
|
host = advHost;
|
||||||
|
port = advPort;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
host = opts.Cluster.Host;
|
||||||
|
if (string.IsNullOrWhiteSpace(host))
|
||||||
|
host = opts.Host;
|
||||||
|
port = opts.Cluster.Port;
|
||||||
|
}
|
||||||
|
|
||||||
_mu.EnterWriteLock();
|
_mu.EnterWriteLock();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_routeInfo.Host = host;
|
_routeInfo.Host = host;
|
||||||
_routeInfo.Port = opts.Cluster.Port;
|
_routeInfo.Port = port;
|
||||||
_routeInfo.Ip = $"nats-route://{host}:{opts.Cluster.Port}/";
|
_routeInfo.Ip = $"nats-route://{host}:{port}/";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
using ZB.MOM.NatsNet.Server;
|
using ZB.MOM.NatsNet.Server;
|
||||||
using ZB.MOM.NatsNet.Server.Internal;
|
using ZB.MOM.NatsNet.Server.Internal;
|
||||||
@@ -7,6 +8,65 @@ namespace ZB.MOM.NatsNet.Server.Tests.ImplBacklog;
|
|||||||
|
|
||||||
public sealed partial class RouteHandlerTests
|
public sealed partial class RouteHandlerTests
|
||||||
{
|
{
|
||||||
|
[Fact] // T:2798
|
||||||
|
public void ClusterAdvertiseErrorOnStartup_ShouldSucceed()
|
||||||
|
{
|
||||||
|
var options = new ServerOptions();
|
||||||
|
options.Cluster.Advertise = "addr:::123";
|
||||||
|
var (server, err) = NatsServer.NewServer(options);
|
||||||
|
err.ShouldBeNull();
|
||||||
|
var startErr = server!.StartRouting();
|
||||||
|
startErr.ShouldNotBeNull();
|
||||||
|
startErr!.Message.ShouldContain("Cluster.Advertise");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact] // T:2822
|
||||||
|
public void TLSRoutesCertificateImplicitAllowPass_ShouldSucceed()
|
||||||
|
{
|
||||||
|
var client = new ClientConnection(ClientKind.Router, nc: new MemoryStream());
|
||||||
|
client.MatchesPinnedCert(null).ShouldBeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact] // T:2823
|
||||||
|
public void TLSRoutesCertificateImplicitAllowFail_ShouldSucceed()
|
||||||
|
{
|
||||||
|
var client = new ClientConnection(ClientKind.Router, nc: new MemoryStream());
|
||||||
|
var pinned = new PinnedCertSet([new string('a', 64)]);
|
||||||
|
client.MatchesPinnedCert(pinned).ShouldBeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact] // T:2844
|
||||||
|
public void RouteParseOriginClusterMsgArgs_ShouldSucceed()
|
||||||
|
{
|
||||||
|
var c = new ClientConnection(ClientKind.Router)
|
||||||
|
{
|
||||||
|
Route = new Route { AccName = "MY_ACCOUNT"u8.ToArray() },
|
||||||
|
};
|
||||||
|
|
||||||
|
var err = c.ProcessRoutedOriginClusterMsgArgs("ORIGIN foo + bar queue1 queue2 12 345\r\n"u8.ToArray());
|
||||||
|
err.ShouldBeNull();
|
||||||
|
Encoding.ASCII.GetString(c.ParseCtx.Pa.Account!).ShouldBe("ORIGIN");
|
||||||
|
Encoding.ASCII.GetString(c.ParseCtx.Pa.Subject!).ShouldBe("foo");
|
||||||
|
Encoding.ASCII.GetString(c.ParseCtx.Pa.Reply!).ShouldBe("bar");
|
||||||
|
c.ParseCtx.Pa.Queues.ShouldNotBeNull();
|
||||||
|
c.ParseCtx.Pa.Queues!.Count.ShouldBe(3);
|
||||||
|
c.ParseCtx.Pa.Size.ShouldBe(345);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact] // T:2850
|
||||||
|
public void RouteCompression_ShouldSucceed()
|
||||||
|
{
|
||||||
|
var opts = new ServerOptions();
|
||||||
|
opts.Cluster.Compression.Mode = CompressionMode.S2Fast;
|
||||||
|
var (server, err) = NatsServer.NewServer(opts);
|
||||||
|
err.ShouldBeNull();
|
||||||
|
server.ShouldNotBeNull();
|
||||||
|
|
||||||
|
var infoProto = server!.GenerateRouteInitialInfoJSON(string.Empty, CompressionMode.S2Fast, 0, GossipMode.Default);
|
||||||
|
infoProto.Length.ShouldBeGreaterThan(0);
|
||||||
|
Encoding.ASCII.GetString(infoProto).ShouldContain("\"compression\":\"s2_fast\"");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact] // T:2819
|
[Fact] // T:2819
|
||||||
public async Task RouteIPResolutionAndRouteToSelf_ShouldSucceed()
|
public async Task RouteIPResolutionAndRouteToSelf_ShouldSucceed()
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
porting.db
BIN
porting.db
Binary file not shown.
Reference in New Issue
Block a user