Пример #1
0
        public void Serialization_respects_default_serializer_parameter()
        {
            var message    = new TestMessage("this is my test message");
            var serializer = _serialization.FindSerializerFor(message, "json");

            Assert.Equal(1, serializer.Identifier); //by default configuration the serializer id for json == newtonsoft == 1
        }
Пример #2
0
        public void SnapshotSerializer_should_handle_custom_snapshot_Serialization()
        {
            var wrapped    = new Akka.Persistence.Serialization.Snapshot(new MySnapshot("a"));
            var serializer = _serialization.FindSerializerFor(wrapped);

            var bytes        = serializer.ToBinary(wrapped);
            var deserialized = serializer.FromBinary(bytes, null);

            deserialized.ShouldBe(new Akka.Persistence.Serialization.Snapshot(new MySnapshot(".a.")));
        }
Пример #3
0
        protected virtual void WriteEvent(DbCommand command, IPersistentRepresentation e, IImmutableSet <string> tags)
        {
            var manifest   = string.IsNullOrEmpty(e.Manifest) ? e.Payload.GetType().QualifiedTypeName() : e.Manifest;
            var serializer = Serialization.FindSerializerFor(e.Payload);
            var binary     = serializer.ToBinary(e.Payload);

            AddParameter(command, "@PersistenceId", DbType.String, e.PersistenceId);
            AddParameter(command, "@SequenceNr", DbType.Int64, e.SequenceNr);
            AddParameter(command, "@Timestamp", DbType.Int64, TimestampProvider.GenerateTimestamp(e));
            AddParameter(command, "@IsDeleted", DbType.Boolean, false);
            AddParameter(command, "@Manifest", DbType.String, manifest);
            AddParameter(command, "@Payload", DbType.Binary, binary);

            if (tags.Count != 0)
            {
                var tagBuilder = new StringBuilder(";", tags.Sum(x => x.Length) + tags.Count + 1);
                foreach (var tag in tags)
                {
                    tagBuilder.Append(tag).Append(';');
                }

                AddParameter(command, "@Tag", DbType.String, tagBuilder.ToString());
            }
            else
            {
                AddParameter(command, "@Tag", DbType.String, DBNull.Value);
            }
        }
Пример #4
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="stream">TBD</param>
        /// <param name="snapshot">TBD</param>
        protected void Serialize(Stream stream, Serialization.Snapshot snapshot)
        {
            var serializer = _serialization.FindSerializerFor(snapshot, _defaultSerializer);
            var bytes      = serializer.ToBinary(snapshot);

            stream.Write(bytes, 0, bytes.Length);
        }
Пример #5
0
        private void Serialize(Serialization.Snapshot snapshot, Stream stream)
        {
            var serializer = _serialization.FindSerializerFor(snapshot);
            var bytes      = serializer.ToBinary(snapshot);

            stream.Write(bytes, 0, bytes.Length);
        }
        private void VerifySerialization(DaemonMsgCreate msg)
        {
            var daemonMsgSerializer = ser.FindSerializerFor(msg);

            AssertDaemonMsgCreate(msg, ser.Deserialize(daemonMsgSerializer.ToBinary(msg),
                                                       daemonMsgSerializer.Identifier, typeof(DaemonMsgCreate)).AsInstanceOf <DaemonMsgCreate>());
        }
        private SnapshotEntry ToSnapshotEntry(SnapshotMetadata metadata, object snapshot)
        {
            if (_settings.LegacySerialization)
            {
                var manifest = snapshot.GetType().TypeQualifiedName();

                return(new SnapshotEntry
                {
                    Id = metadata.PersistenceId + "_" + metadata.SequenceNr,
                    PersistenceId = metadata.PersistenceId,
                    SequenceNr = metadata.SequenceNr,
                    Snapshot = snapshot,
                    Timestamp = metadata.Timestamp.Ticks,
                    Manifest = manifest,
                    SerializerId = null
                });
            }

            var snapshotRep    = new Serialization.Snapshot(snapshot);
            var serializer     = _serialization.FindSerializerFor(snapshotRep);
            var binary         = serializer.ToBinary(snapshotRep);
            var binaryManifest = Akka.Serialization.Serialization.ManifestFor(serializer, snapshotRep);

            return(new SnapshotEntry
            {
                Id = metadata.PersistenceId + "_" + metadata.SequenceNr,
                PersistenceId = metadata.PersistenceId,
                SequenceNr = metadata.SequenceNr,
                Snapshot = binary,
                Timestamp = metadata.Timestamp.Ticks,
                Manifest = binaryManifest,
                SerializerId = serializer?.Identifier
            });
        }
Пример #8
0
        private void VerifySerialization(DaemonMsgCreate msg)
        {
            var daemonMsgSerializer = _ser.FindSerializerFor(msg);
            var binary = daemonMsgSerializer.ToBinary(msg);
            var actual = (DaemonMsgCreate)_ser.Deserialize(binary, daemonMsgSerializer.Identifier, typeof(DaemonMsgCreate));

            AssertDaemonMsgCreate(msg, actual);
        }
Пример #9
0
        public void MessageSerializer_should_serialize_manifest_provided_by_EventAdapter()
        {
            var p1         = new Persistent(new MyPayload("a"), sender: TestActor).WithManifest("manifest");
            var serializer = _serialization.FindSerializerFor(p1);
            var bytes      = serializer.ToBinary(p1);
            var back       = (Persistent)serializer.FromBinary(bytes, typeof(Persistent));

            back.Manifest.ShouldBe(p1.Manifest);
        }
Пример #10
0
        public void MessageSerializer_when_not_given_a_manifest_should_handle_custom_Persistent_message_serialization()
        {
            var persistent = new Persistent(new MyPayload("a"), 13, "p1", "", writerGuid: Guid.NewGuid().ToString());
            var serializer = _serialization.FindSerializerFor(persistent);

            var bytes        = serializer.ToBinary(persistent);
            var deserialized = serializer.FromBinary(bytes, null);

            deserialized.ShouldBe(persistent.WithPayload(new MyPayload(".a.")));
        }
Пример #11
0
        private JournalEntry ToJournalEntry(IPersistentRepresentation message)
        {
            object payload = message.Payload;

            if (message.Payload is Tagged tagged)
            {
                payload = tagged.Payload;
                message = message.WithPayload(payload); // need to update the internal payload when working with tags
            }

            // per https://github.com/akkadotnet/Akka.Persistence.MongoDB/issues/107
            // BSON serialization
            if (_settings.LegacySerialization)
            {
                var manifest = string.IsNullOrEmpty(message.Manifest) ? payload.GetType().TypeQualifiedName() : message.Manifest;
                return(new JournalEntry
                {
                    Id = message.PersistenceId + "_" + message.SequenceNr,
                    Ordering = new BsonTimestamp(0), // Auto-populates with timestamp
                    IsDeleted = message.IsDeleted,
                    Payload = payload,
                    PersistenceId = message.PersistenceId,
                    SequenceNr = message.SequenceNr,
                    Manifest = manifest,
                    Tags = tagged.Tags?.ToList(),
                    SerializerId = null // don't need a serializer ID here either; only for backwards-compat
                });
            }

            // default serialization
            var serializer = _serialization.FindSerializerFor(message);
            var binary     = serializer.ToBinary(message);


            return(new JournalEntry
            {
                Id = message.PersistenceId + "_" + message.SequenceNr,
                Ordering = new BsonTimestamp(0), // Auto-populates with timestamp
                IsDeleted = message.IsDeleted,
                Payload = binary,
                PersistenceId = message.PersistenceId,
                SequenceNr = message.SequenceNr,
                Manifest = string.Empty, // don't need a manifest here - it's embedded inside the PersistentMessage
                Tags = tagged.Tags?.ToList(),
                SerializerId = null      // don't need a serializer ID here either; only for backwards-compat
            });
        }