Skip to content

Commit a0b5e8f

Browse files
committed
Clarify the unit test
1 parent 75e24b3 commit a0b5e8f

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/contrib/persistence/Akka.Persistence.Sqlite.Tests/CustomObjectSerializerSpec.cs

+36-2
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,23 @@ public async Task CustomSerializerTest()
5858
{
5959
var probe = CreateTestProbe();
6060

61+
// Sanity check to see that the system should serialize object type using MySerializer
62+
var serializer = Sys.Serialization.FindSerializerForType(typeof(Persisted));
63+
serializer.Should().BeOfType<MySerializer>();
64+
6165
var actor = Sys.ActorOf(Props.Create(() => new PersistedActor("a")));
62-
actor.Tell("a", probe);
63-
probe.ExpectMsg("a");
66+
actor.Tell(new Persisted("a"), probe);
67+
probe.ExpectMsg(new Persisted("a"));
6468

69+
// Read the database directly, make sure that we're using the correct object type serializer
6570
var conn = new SqliteConnection("DataSource=AkkaJournal.db");
6671
conn.Open();
6772
const string sql = "SELECT ej.serializer_id FROM event_journal ej WHERE ej.persistence_id = 'a'";
6873
await using var cmd = new SqliteCommand(sql, conn);
6974
var record = await cmd.ExecuteReaderAsync();
7075
await record.ReadAsync();
76+
77+
// In the bug this fails, the serializer id is JSON id instead of MySerializer id
7178
record[0].Should().Be(9999);
7279
}
7380

@@ -83,6 +90,33 @@ public Task DisposeAsync()
8390
return Task.CompletedTask;
8491
}
8592
}
93+
94+
internal sealed class Persisted: IEquatable<Persisted>
95+
{
96+
public Persisted(string payload)
97+
{
98+
Payload = payload;
99+
}
100+
101+
public string Payload { get; }
102+
103+
public bool Equals(Persisted other)
104+
{
105+
if (ReferenceEquals(null, other)) return false;
106+
if (ReferenceEquals(this, other)) return true;
107+
return Payload == other.Payload;
108+
}
109+
110+
public override bool Equals(object obj)
111+
{
112+
return ReferenceEquals(this, obj) || obj is Persisted other && Equals(other);
113+
}
114+
115+
public override int GetHashCode()
116+
{
117+
return (Payload != null ? Payload.GetHashCode() : 0);
118+
}
119+
}
86120

87121
internal class MySerializer : Serializer
88122
{

0 commit comments

Comments
 (0)