Beispiel #1
0
        public void Setup_disallow_unsafe_type_should_work(object dangerousObject, Type type)
        {
            var serializer = new HyperionSerializer((ExtendedActorSystem)Sys, HyperionSerializerSettings.Default);
            var serialized = serializer.ToBinary(dangerousObject);

            serializer.Invoking(s => s.FromBinary(serialized, type)).Should().Throw <SerializationException>();
        }
Beispiel #2
0
        private void CheckDeserialize(object msg, string message)
        {
            Log.Info("testing " + message);
            var serializer = new HyperionSerializer((ExtendedActorSystem)Sys);
            var bytes      = serializer.ToBinary(msg);
            var restored   = serializer.FromBinary(bytes, msg.GetType());

            Assert.NotNull(restored);
        }
Beispiel #3
0
        public void Test_deserialization()
        {
            //CoffeMakeFailedEvent
            var msg = new Akka.Actor.Status.Failure(new UndefinedCoffeMachineException());
            //var msg =
            var serializer = new HyperionSerializer((ExtendedActorSystem)Sys);
            var bytes      = serializer.ToBinary(msg);
            var restored   = serializer.FromBinary(bytes, msg.GetType());

            Assert.NotNull(restored);
        }
Beispiel #4
0
        public override byte[] ToBinary(object obj)
        {
            if (obj is IClusterShardingSerializable)
            {
                throw new Exception($"THIS ISN'T SUPPOSED TO BE SERIALIZED. Type: {obj.GetType().FullName}");
            }

            // IShardRegionCommand isn't serialized using cluster sharding serializer
            if (!(obj is IShardRegionCommand))
            {
                var typeName = obj.GetType().AssemblyQualifiedName;
                if (typeName.StartsWith("Akka.Cluster.Sharding") && !typeName.Contains("Tests"))
                {
                    throw new Exception($"THIS ISN'T SUPPOSED TO BE SERIALIZED. Type: {typeName}");
                }
            }

            return(_serializer.ToBinary(obj));
        }
Beispiel #5
0
        public void Setup_surrogate_should_work()
        {
            var surrogated = new List <Foo>();
            var setup      = HyperionSerializerSetup.Empty
                             .WithSurrogates(new [] { Surrogate.Create <Foo, FooSurrogate>(
                                                          foo =>
                {
                    surrogated.Add(foo);
                    return(new FooSurrogate(foo.Bar + "."));
                },
                                                          surrogate => new Foo(surrogate.Bar)) });
            var settings   = setup.ApplySettings(HyperionSerializerSettings.Default);
            var serializer = new HyperionSerializer((ExtendedActorSystem)Sys, settings);

            var expected     = new Foo("bar");
            var serialized   = serializer.ToBinary(expected);
            var deserialized = serializer.FromBinary <Foo>(serialized);

            deserialized.Bar.Should().Be("bar.");
            surrogated.Count.Should().Be(1);
            surrogated[0].Should().BeEquivalentTo(expected);
        }
Beispiel #6
0
        public string Hyperion_serialize_string()
        {
            var bytes = HyperionSerializer.ToBinary(TestString);

            return(HyperionSerializer.FromBinary <string>(bytes));
        }