diff --git a/src/contrib/persistence/Akka.Persistence.Sqlite.Tests/CustomObjectSerializerSpec.cs b/src/contrib/persistence/Akka.Persistence.Sqlite.Tests/CustomObjectSerializerSpec.cs index 2a07a2a6b74..5e290070cc9 100644 --- a/src/contrib/persistence/Akka.Persistence.Sqlite.Tests/CustomObjectSerializerSpec.cs +++ b/src/contrib/persistence/Akka.Persistence.Sqlite.Tests/CustomObjectSerializerSpec.cs @@ -58,16 +58,23 @@ public async Task CustomSerializerTest() { var probe = CreateTestProbe(); + // Sanity check to see that the system should serialize object type using MySerializer + var serializer = Sys.Serialization.FindSerializerForType(typeof(Persisted)); + serializer.Should().BeOfType(); + var actor = Sys.ActorOf(Props.Create(() => new PersistedActor("a"))); - actor.Tell("a", probe); - probe.ExpectMsg("a"); + actor.Tell(new Persisted("a"), probe); + probe.ExpectMsg(new Persisted("a")); + // Read the database directly, make sure that we're using the correct object type serializer var conn = new SqliteConnection("DataSource=AkkaJournal.db"); conn.Open(); const string sql = "SELECT ej.serializer_id FROM event_journal ej WHERE ej.persistence_id = 'a'"; await using var cmd = new SqliteCommand(sql, conn); var record = await cmd.ExecuteReaderAsync(); await record.ReadAsync(); + + // In the bug this fails, the serializer id is JSON id instead of MySerializer id record[0].Should().Be(9999); } @@ -83,6 +90,33 @@ public Task DisposeAsync() return Task.CompletedTask; } } + + internal sealed class Persisted: IEquatable + { + public Persisted(string payload) + { + Payload = payload; + } + + public string Payload { get; } + + public bool Equals(Persisted other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return Payload == other.Payload; + } + + public override bool Equals(object obj) + { + return ReferenceEquals(this, obj) || obj is Persisted other && Equals(other); + } + + public override int GetHashCode() + { + return (Payload != null ? Payload.GetHashCode() : 0); + } + } internal class MySerializer : Serializer {