forked from akkadotnet/akka.net
/
BugFix5062Spec.cs
97 lines (84 loc) · 3.46 KB
/
BugFix5062Spec.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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.Cluster;
using Akka.Configuration;
using Akka.DistributedData;
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())
.WithFallback(DistributedData.DistributedData.DefaultConfig());
public BugFix5062Spec(ITestOutputHelper output) : base(output, DDataConfig)
{ }
[Fact]
public void Failed_serialization_should_give_proper_exception_message()
{
var node1 = new UniqueAddress(new Address("akka.tcp", "Sys", "localhost", 2551), 1);
var payload = new LWWRegister<SomeMessage>(node1, new SomeMessage());
var message = new ActorSelectionMessage(
payload,
new SelectionPathElement[] { new SelectChildName("dummy") },
true);
var serialized = MessageSerializer.Serialize((ExtendedActorSystem)Sys, node1.Address, message);
var o = new object();
var ex = o.Invoking(s => MessageSerializer.Deserialize((ExtendedActorSystem)Sys, serialized)).Should()
.Throw<SerializationException>()
.WithMessage("Failed to deserialize object with serialization id [6] (manifest []).")
.WithInnerExceptionExactly<SerializationException>()
.WithMessage("Failed to deserialize object with serialization id [11] (manifest [E]).")
.WithInnerExceptionExactly<TargetInvocationException>()
.WithMessage("Exception has been thrown by the target of an invocation.")
.WithInnerExceptionExactly<SerializationException>()
.WithMessage("Failed to deserialize object with serialization id [13] (manifest [SM]).");
}
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");
}
}
}
}