Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test kit improve message filters #456

Merged
merged 1 commit into from
Aug 17, 2023
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
23 changes: 21 additions & 2 deletions src/ArtemisNetClient.Testing/SharedMessageSource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Data;
using System.Text.RegularExpressions;
using ActiveMQ.Artemis.Client.InternalUtilities;
using ActiveMQ.Artemis.Client.Testing.Utils;

Expand Down Expand Up @@ -94,7 +95,25 @@ private bool FilterExpressionMatches(Message message)
}

dataTable.Rows.Add(dataRow);

return dataTable.Select(Info.FilterExpression).Any();

while (true)
{
try
{
return dataTable.Select(Info.FilterExpression).Any();
}
catch (EvaluateException e) when(e.Message.StartsWith("Cannot find column"))
{
var match = Regex.Match(e.Message, @"Cannot find column \[(\w+)\]\.");
if (match.Success)
{
dataTable.Columns.Add(match.Groups[1].Value);
}
else
{
throw;
}
}
}
}
}
24 changes: 24 additions & 0 deletions test/ArtemisNetClient.Testing.UnitTests/FilterExpressionsSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@ public async Task Should_filter_messages_based_on_application_property()
Assert.All(blueMessages, x => Assert.Equal("blue", x.GetBody<string>()));
}

[Fact]
public async Task Should_filter_messages_when_property_used_in_filter_is_missing()
{
var endpoint = EndpointUtil.GetUniqueEndpoint();
using var testKit = new TestKit(endpoint);

var connectionFactory = new ConnectionFactory();
await using var connection = await connectionFactory.CreateAsync(endpoint);

var address = "test_address";
await using var messageConsumer = await connection.CreateConsumerAsync(new ConsumerConfiguration
{
Address = address,
RoutingType = RoutingType.Multicast,
FilterExpression = "color IS NULL"
});

await testKit.SendMessageAsync(address, new Message("msg"));

var message = await messageConsumer.ReceiveAsync();

Assert.Equal("msg", message.GetBody<string>());
}

static async Task<IReadOnlyList<Message>> ReceiveMessages(IConsumer consumer, int count)
{
var messages = new List<Message>();
Expand Down
Loading