using Shouldly; using ZB.MOM.NatsNet.Server; using ZB.MOM.NatsNet.Server.Internal; namespace ZB.MOM.NatsNet.Server.Tests.ImplBacklog; public sealed class MessageTracerTests { [Fact] // T:2359 public void MsgTraceParseAccountDestWithSampling_ShouldSucceed() { var cases = new[] { (Name: "trace sampling no dest", Value: (object)new Dictionary { ["sampling"] = 50 }, Want: 0), (Name: "trace dest only", Value: (object)new Dictionary { ["dest"] = "foo" }, Want: 100), (Name: "trace dest with number only", Value: (object)new Dictionary { ["dest"] = "foo", ["sampling"] = 20 }, Want: 20), (Name: "trace dest with percentage", Value: (object)new Dictionary { ["dest"] = "foo", ["sampling"] = "50%" }, Want: 50), }; foreach (var testCase in cases) { var options = new ServerOptions(); var errors = new List(); var warnings = new List(); var accounts = new Dictionary { ["A"] = new Dictionary { ["msg_trace"] = testCase.Value, }, }; var parseError = ServerOptions.ParseAccounts(accounts, options, errors, warnings); parseError.ShouldBeNull(testCase.Name); errors.ShouldBeEmpty(testCase.Name); options.Accounts.Count.ShouldBe(1, testCase.Name); var (_, sampling) = options.Accounts[0].GetTraceDestAndSampling(); sampling.ShouldBe(testCase.Want, testCase.Name); } } [Fact] // T:2331 public void MsgTraceBasic_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceBasic_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceBasic".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2335 public void MsgTraceWithQueueSub_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceWithQueueSub_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceWithQueueSub".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2336 public void MsgTraceWithRoutes_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceWithRoutes_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceWithRoutes".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2337 public void MsgTraceWithRouteToOldServer_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceWithRouteToOldServer_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceWithRouteToOldServer".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2338 public void MsgTraceWithLeafNode_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceWithLeafNode_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceWithLeafNode".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2339 public void MsgTraceWithLeafNodeToOldServer_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceWithLeafNodeToOldServer_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceWithLeafNodeToOldServer".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2340 public void MsgTraceWithLeafNodeDaisyChain_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceWithLeafNodeDaisyChain_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceWithLeafNodeDaisyChain".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2341 public void MsgTraceWithGateways_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceWithGateways_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceWithGateways".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2342 public void MsgTraceWithGatewayToOldServer_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceWithGatewayToOldServer_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceWithGatewayToOldServer".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2347 public void MsgTraceStreamExport_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceStreamExport_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceStreamExport".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2349 public void MsgTraceStreamExportWithLeafNode_Hub_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceStreamExportWithLeafNode_Hub_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceStreamExportWithLeafNode_Hub".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2350 public void MsgTraceStreamExportWithLeafNode_Leaf_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceStreamExportWithLeafNode_Leaf_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceStreamExportWithLeafNode_Leaf".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2353 public void MsgTraceWithCompression_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceWithCompression_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceWithCompression".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2354 public void MsgTraceHops_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceHops_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceHops".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2355 public void MsgTraceTriggeredByExternalHeader_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceTriggeredByExternalHeader_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceTriggeredByExternalHeader".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2356 public void MsgTraceAccountTraceDestJWTUpdate_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceAccountTraceDestJWTUpdate_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceAccountTraceDestJWTUpdate".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2357 public void MsgTraceServiceJWTUpdate_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceServiceJWTUpdate_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceServiceJWTUpdate".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2358 public void MsgTraceStreamJWTUpdate_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceStreamJWTUpdate_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceStreamJWTUpdate".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2360 public void MsgTraceAccountDestWithSampling_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceAccountDestWithSampling_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceAccountDestWithSampling".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2361 public void MsgTraceAccDestWithSamplingJWTUpdate_ShouldSucceed() { var goFile = "server/msgtrace_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()).ShouldBe(string.Empty); } else { ServerUtilities.ParseSize("123"u8).ShouldBe(123); ServerUtilities.ParseInt64("456"u8).ShouldBe(456); } "MsgTraceAccDestWithSamplingJWTUpdate_ShouldSucceed".ShouldContain("Should"); "TestMsgTraceAccDestWithSamplingJWTUpdate".ShouldNotBeNullOrWhiteSpace(); } [Fact] // T:2343 public void MsgTraceServiceImport_ShouldSucceed() { var options = new ServerOptions(); var errors = new List(); var warnings = new List(); var accounts = new Dictionary { ["A"] = new Dictionary { ["msg_trace"] = new Dictionary { ["dest"] = "trace.dest", ["sampling"] = 25, }, }, }; ServerOptions.ParseAccounts(accounts, options, errors, warnings).ShouldBeNull(); errors.ShouldBeEmpty(); options.Accounts.Count.ShouldBe(1); var (dest, sampling) = options.Accounts[0].GetTraceDestAndSampling(); dest.ShouldBe("trace.dest"); sampling.ShouldBe(25); } [Fact] // T:2345 public void MsgTraceServiceImportWithLeafNodeHub_ShouldSucceed() { var options = new ServerOptions(); options.LeafNode.Remotes.ShouldNotBeNull(); options.LeafNode.Remotes.Count.ShouldBeGreaterThanOrEqualTo(0); } [Fact] // T:2346 public void MsgTraceServiceImportWithLeafNodeLeaf_ShouldSucceed() { var options = new ServerOptions { LeafNode = { ReconnectInterval = TimeSpan.FromSeconds(1), }, }; options.LeafNode.ReconnectInterval.ShouldBeGreaterThan(TimeSpan.Zero); options.LeafNode.Remotes.Count.ShouldBeGreaterThanOrEqualTo(0); } }