-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Akka.Serialization:
INoSerializationVerificationNeeded
does not han…
…dle `IWrappedMessage` correctly (#7010) * Added reproduction `INoSerializationVerificationNeeded` does not handle `IWrappedMessage` correctly * fixed issue * added correct unwrapping method * Fix dead letter behaviour change * Fix implementation --------- Co-authored-by: Gregorius Soedharmo <arkatufus@yahoo.com>
- Loading branch information
1 parent
93af6e4
commit 04630da
Showing
3 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/core/Akka.Tests/Serialization/SerializeAllMessagesSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="SerializeAllMessagesSpec.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; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.Event; | ||
using Akka.TestKit; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Akka.Tests.Serialization; | ||
|
||
public class SerializeAllMessagesSpec : AkkaSpec | ||
{ | ||
public SerializeAllMessagesSpec(ITestOutputHelper output) : base("akka.actor.serialize-messages = on", output) | ||
{ | ||
} | ||
|
||
private class MyMessage : INoSerializationVerificationNeeded | ||
{ | ||
public MyMessage(Action myAction) | ||
{ | ||
MyAction = myAction; | ||
} | ||
|
||
// add an unserializable member, such as a delegate | ||
public Action MyAction { get; } | ||
} | ||
|
||
private class MyWrappedMessage : IWrappedMessage | ||
{ | ||
public MyWrappedMessage(object message) | ||
{ | ||
Message = message; | ||
} | ||
|
||
public object Message { get; } | ||
} | ||
|
||
// create an actor that will process a MyWrappedMessage and invoke the delegate | ||
private class MyActor : ReceiveActor | ||
{ | ||
public MyActor() | ||
{ | ||
Receive<MyWrappedMessage>(msg => | ||
{ | ||
var myMessage = (MyMessage) msg.Message; | ||
myMessage.MyAction(); | ||
}); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task Should_not_serialize_WrappedMessage_with_INoSerializationVerificationNeeded() | ||
{ | ||
// Arrange | ||
var myProbe = CreateTestProbe(); | ||
var action = () => { myProbe.Tell("worked"); }; | ||
var message = new MyMessage(action); | ||
var wrappedMessage = new MyWrappedMessage(message); | ||
|
||
var myActor = Sys.ActorOf(Props.Create(() => new MyActor()), "wrapped-message-actor"); | ||
|
||
await EventFilter.Error().ExpectAsync(0, async () => | ||
{ | ||
// Act | ||
myActor.Tell(wrappedMessage); | ||
await myProbe.ExpectMsgAsync("worked"); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters