Skip to content

Commit

Permalink
Clarify the unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkatufus committed Nov 1, 2022
1 parent 75e24b3 commit a0b5e8f
Showing 1 changed file with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<MySerializer>();

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);
}

Expand All @@ -83,6 +90,33 @@ public Task DisposeAsync()
return Task.CompletedTask;
}
}

internal sealed class Persisted: IEquatable<Persisted>
{
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
{
Expand Down

0 comments on commit a0b5e8f

Please sign in to comment.