-
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.
Fix Akka.Remote serialization exception bubbling and messages (#5072)
* Fix exception bubbling and messages * Remove reference to DData project * Remove reference to Akka.Cluster * Remove generic exception handling * Add a very specific exception handling for failed payload deserialization Co-authored-by: Aaron Stannard <[email protected]>
- Loading branch information
1 parent
35b1bb5
commit 6a7373f
Showing
2 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
src/core/Akka.Remote.Tests/Serialization/BugFix5062Spec.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,88 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.Serialization; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.Configuration; | ||
using Akka.Remote.Configuration; | ||
using Akka.Serialization; | ||
using Akka.TestKit; | ||
using FluentAssertions; | ||
using Google.Protobuf; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Akka.Remote.Tests.Serialization | ||
{ | ||
public class BugFix5062Spec: AkkaSpec | ||
{ | ||
private static Config DDataConfig => ConfigurationFactory.ParseString($@" | ||
akka.actor {{ | ||
serializers {{ | ||
dummyWithManifest = ""{typeof(DummySerializerWithStringManifest).AssemblyQualifiedName}"" | ||
}} | ||
serialization-bindings {{ | ||
""{typeof(SomeMessage).AssemblyQualifiedName}"" = dummyWithManifest | ||
}} | ||
serialization-identifiers {{ | ||
""{typeof(DummySerializerWithStringManifest).AssemblyQualifiedName}"" = 13 | ||
}} | ||
}}") | ||
.WithFallback(RemoteConfigFactory.Default()); | ||
|
||
public BugFix5062Spec(ITestOutputHelper output) : base(output, DDataConfig) | ||
{ } | ||
|
||
[Fact] | ||
public void Failed_serialization_should_give_proper_exception_message() | ||
{ | ||
var childName = "dummy"; | ||
var message = new ActorSelectionMessage( | ||
new SomeMessage(), | ||
new SelectionPathElement[] { new SelectChildName(childName) }, | ||
true); | ||
|
||
var node1 = new Address("akka.tcp", "Sys", "localhost", 2551); | ||
var serialized = MessageSerializer.Serialize((ExtendedActorSystem)Sys, node1, message); | ||
|
||
var o = new object(); | ||
o.Invoking(s => MessageSerializer.Deserialize((ExtendedActorSystem)Sys, serialized)).Should() | ||
.Throw<SerializationException>() | ||
.WithMessage($"Failed to deserialize payload object when deserializing {nameof(ActorSelectionMessage)} addressed to [{childName}]") | ||
.WithInnerExceptionExactly<NotImplementedException>(); | ||
} | ||
|
||
public class SomeMessage | ||
{ | ||
} | ||
|
||
public class DummySerializerWithStringManifest : SerializerWithStringManifest | ||
{ | ||
public DummySerializerWithStringManifest(ExtendedActorSystem system) : base(system) | ||
{ | ||
} | ||
|
||
public override byte[] ToBinary(object obj) | ||
{ | ||
return Array.Empty<byte>(); | ||
} | ||
|
||
public override object FromBinary(byte[] bytes, string manifest) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override string Manifest(object o) | ||
{ | ||
if (o is SomeMessage) | ||
return "SM"; | ||
throw new Exception("Unknown object type"); | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
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