Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Particular.LicensingComponent.UnitTests/AuditQuery_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,42 @@ public async Task Should_return_each_remote_with_only_its_own_queues()
Assert.That(remotes.Select(remote => remote.Queues), Is.EqualTo(new[] { new[] { "audit.a", "audit.a.log" }, new[] { "audit.b", "audit.b.log" } }));
}

/// <summary>
/// Tests that the backwards compatibility handling of the instance name property works for both formats of this response, in version 5.4 and earlier the field
/// was called service_name, and was renamed instance_name after that.
/// The version number is not used to determine the property name, but is included in the test to ensure that the correct property name is used for each version.
/// </summary>
[TestCase("6.21.0", "instance_name")]
[TestCase("5.4.0", "service_name")]
public async Task Should_include_the_input_queue_named_after_the_audit_instance(string version, string instanceNameProperty)
Comment thread
rbev marked this conversation as resolved.
{
var configuration = $$"""
{
"host": {
"{{instanceNameProperty}}": "Contoso.Audit",
"logging": { "log_path": "/var/log/servicecontrol-audit", "logging_level": "debug" }
},
"data_retention": { "audit_retention_period": "30.00:00:00" },
"performance_tunning": { "max_body_size_to_store": 102400 },
"transport": {
"transport_type": "LearningTransport",
"audit_log_queue": "audit.log",
"audit_queue": "audit",
"forward_audit_messages": false
},
"persistence": { "persistence_type": "PostgreSQL" },
"plugins": {}
}
""";
var configurationApi = new ConfigurationApi_ReturningRemotes(
new RemoteConfiguration { ApiUri = "http://audit:44444/api/", Status = "online", Version = version, Configuration = JsonNode.Parse(configuration) });
var auditQuery = new AuditQuery(NullLogger<AuditQuery>.Instance, new FakeEndpointApi(), new FakeAuditCountApi(), configurationApi);

var remotes = await auditQuery.GetAuditRemotes();

Assert.That(remotes.Single().Queues, Is.EquivalentTo(new[] { "Contoso.Audit", "audit", "audit.log" }));
}

[Test]
public async Task Should_return_successful_audit_connection_if_instances_exist_and_are_online()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ public async Task<List<RemoteInstanceInformation>> GetAuditRemotes(CancellationT
: null;

if (remote.Configuration.AsObject().TryGetPropertyValue("host", out var host) &&
host?.AsObject().TryGetPropertyValue("service_name", out var serviceName) == true)
(host?.AsObject().TryGetPropertyValue("instance_name", out var instanceName) == true ||
host?.AsObject().TryGetPropertyValue("service_name", out instanceName) == true))
{
queues.Add(serviceName!.GetValue<string>());
queues.Add(instanceName!.GetValue<string>());
}

if (remote.Configuration.AsObject().TryGetPropertyValue("transport", out var transport))
Expand Down
Loading