forked from akkadotnet/akka.net
/
BugFix5062Spec.cs
88 lines (76 loc) · 2.88 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
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");
}
}
}
}