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

LogEvent type of UnhandledMessage was changed to INFO in Akka.TestKit (#6354). #6360

Merged
merged 2 commits into from
Jan 26, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// //-----------------------------------------------------------------------
// // <copyright file="UnhandledMessageEventFilterTestsBase.cs" company="Akka.NET Project">
// // Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
// // Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// // </copyright>
// //-----------------------------------------------------------------------

using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Event;
using Akka.TestKit.TestActors;
using Xunit;

namespace Akka.TestKit.Tests.TestEventListenerTests
{
public class UnhandledMessageEventFilterTests : EventFilterTestBase
{
private readonly IActorRef _unhandledMessageActor;

public UnhandledMessageEventFilterTests() : base("akka.loglevel=INFO")
{
_unhandledMessageActor = Sys.ActorOf<UnhandledMessageActor>();
}

protected override void SendRawLogEventMessage(object message)
{
Sys.EventStream.Publish(new Error(null, "UnhandledMessageEventFilterTests", GetType(), message));
}

[Fact]
public async Task Unhandled_message_should_produce_info_message()
{
await EventFilter
.Info(new Regex("^Unhandled message from"))
.ExpectOneAsync(async () =>
{
_unhandledMessageActor.Tell("whatever");
});
}

[Fact]
public async Task Unhandled_message_should_not_produce_warn_and_error_message()
{
await EventFilter
.Warning()
.And
.Error()
.ExpectAsync(0, async () =>
{
_unhandledMessageActor.Tell("whatever");
});
}
}
}
25 changes: 12 additions & 13 deletions src/core/Akka.TestKit/EventFilter/TestEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override bool Receive(object message)
}
case Mute mute:
{
foreach(var filter in mute.Filters)
foreach (var filter in mute.Filters)
{
AddFilter(filter);
}
Expand All @@ -64,7 +64,7 @@ protected override bool Receive(object message)
}
case LogEvent logEvent:
{
if(!ShouldFilter(logEvent))
if (!ShouldFilter(logEvent))
{
Print(logEvent);
}
Expand All @@ -78,9 +78,9 @@ protected override bool Receive(object message)
case UnhandledMessage un:
{
var rcp = un.Recipient;
var warning = new Warning(rcp.Path.ToString(), rcp.GetType(), "Unhandled message from " + un.Sender + ": " + un.Message);
if(!ShouldFilter(warning))
Print(warning);
var info = new Info(rcp.Path.ToString(), rcp.GetType(), "Unhandled message from " + un.Sender + ": " + un.Message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is a Warning in the JVM. Are we sure this is the root cause of the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As i see in Akka.Event.DeadLetterListener message UnhandledMessage is handled as Info message instead of TestEventListener.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case UnhandledMessage unhandled:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like @F0b0s is right - in the real logging system unhandled messages get logged as Info unless he's not looking in the right place. I did a quick (not complete) look through the code and the DeadLetterListener is the only built-in subscriber for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found solution for #6316 and it's blocked by this PR. When it will be merged i can create MR for it.

if (!ShouldFilter(info))
Print(info);
break;
}

Expand All @@ -97,23 +97,22 @@ private void HandleDeadLetter(DeadLetter message)
var msg = message.Message;
var rcp = message.Recipient;
var snd = message.Sender;
if(!(msg is Terminate))
if (!(msg is Terminate))
{
var recipientPath = rcp.Path.ToString();
var recipientType = rcp.GetType();
var warning = new Warning(recipientPath, recipientType, message);
if(!ShouldFilter(warning))
if (!ShouldFilter(warning))
{
var msgStr = (msg is ISystemMessage)
? "Received dead system message: " + msg
: "Received dead letter from " + snd + ": " + msg;
var warning2 = new Warning(recipientPath, recipientType, new DeadLetter(msgStr,snd,rcp));
if(!ShouldFilter(warning2))
var warning2 = new Warning(recipientPath, recipientType, new DeadLetter(msgStr, snd, rcp));
if (!ShouldFilter(warning2))
{
Print(warning2);
}
}

}
}

Expand All @@ -129,20 +128,20 @@ private void RemoveFilter(IEventFilter filter)

private bool ShouldFilter(LogEvent message)
{
foreach(var filter in _filters)
foreach (var filter in _filters)
{
try
{
if(filter.Apply(message))
if (filter.Apply(message))
return true;
}
// ReSharper disable once EmptyGeneralCatchClause
catch
{
}
}
return false;

return false;
}
}
}
20 changes: 20 additions & 0 deletions src/core/Akka.TestKit/TestActors/UnhandledMessageActor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// //-----------------------------------------------------------------------
// // <copyright file="NoMessageHandlingActor.cs" company="Akka.NET Project">
// // Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
// // Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// // </copyright>
// //-----------------------------------------------------------------------

using Akka.Actor;

namespace Akka.TestKit.TestActors
{
/// <summary>
/// An <see cref="UnhandledMessageActor"/> is an actor that don't handle any message
/// sent to it. An UnhandledMessage will be generated as result of handling any message
/// </summary>
public class UnhandledMessageActor : ReceiveActor
{

}
}