1
+ // //-----------------------------------------------------------------------
2
+ // // <copyright file="ReplicatedDataSerializerBackCompatSpec.cs" company="Akka.NET Project">
3
+ // // Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
4
+ // // Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
5
+ // // </copyright>
6
+ // //-----------------------------------------------------------------------
7
+
8
+ using Akka . Actor ;
9
+ using Akka . Cluster . Sharding ;
10
+ using Akka . DistributedData . Serialization ;
11
+ using Akka . DistributedData . Serialization . Proto . Msg ;
12
+ using FluentAssertions ;
13
+ using Xunit ;
14
+ using UniqueAddress = Akka . Cluster . UniqueAddress ;
15
+ using static FluentAssertions . FluentActions ;
16
+
17
+ namespace Akka . DistributedData . Tests . Serialization ;
18
+
19
+ public class ReplicatedDataSerializerBackCompatSpec
20
+ {
21
+ private readonly ReplicatedDataSerializer _serializer ;
22
+ private readonly UniqueAddress _address ;
23
+
24
+ public ReplicatedDataSerializerBackCompatSpec ( )
25
+ {
26
+ var sys = ActorSystem . Create ( "test" , @"
27
+ akka.actor.provider = cluster
28
+ akka.cluster.sharding.distributed-data.backward-compatible-wire-format = true" ) ;
29
+ _serializer = new ReplicatedDataSerializer ( ( ExtendedActorSystem ) sys ) ;
30
+ _address = Cluster . Cluster . Get ( sys ) . SelfUniqueAddress ;
31
+ sys . Terminate ( ) ;
32
+ }
33
+
34
+ [ Fact ( DisplayName = "DData replicated data serializer should serialize and deserialize correct backward compatible proto message" ) ]
35
+ public void SerializeTest ( )
36
+ {
37
+ var lwwReg = new LWWRegister < ShardCoordinator . CoordinatorState > ( _address , ShardCoordinator . CoordinatorState . Empty ) ;
38
+ var bytes = _serializer . ToBinary ( lwwReg ) ;
39
+ var proto = LWWRegister . Parser . ParseFrom ( bytes ) ;
40
+
41
+ // Serialized type name should be equal to the old v1.4 coordinator state FQCN
42
+ proto . TypeInfo . TypeName . Should ( ) . Be ( "Akka.Cluster.Sharding.PersistentShardCoordinator+State, Akka.Cluster.Sharding" ) ;
43
+
44
+ // Deserializing the same message should succeed
45
+ Invoking ( ( ) => _serializer . FromBinary ( bytes , _serializer . Manifest ( lwwReg ) ) )
46
+ . Should ( ) . NotThrow ( )
47
+ . And . Subject ( ) . Should ( ) . BeOfType < LWWRegister < ShardCoordinator . CoordinatorState > > ( ) ;
48
+ }
49
+ }
0 commit comments