Skip to content

Commit

Permalink
Fix case where PersistenceMessageSerializer.FromBinary got a null for…
Browse files Browse the repository at this point in the history
… its type parameter (akkadotnet#4923)
  • Loading branch information
Arkatufus authored Apr 9, 2021
1 parent 5cc93ee commit 1d144d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ public void MessageSerializer_should_serialize_manifest_provided_by_EventAdapter
back.Manifest.Should().Be(p1.Manifest);
}

[Fact]
public void MessageSerializer_should_serialize_events_with_no_manifest_and_null_type()
{
var p1 = new Persistent(new MyPayload("a"), sender: TestActor);
var bytes = _serializer.ToBinary(p1);
var back = _serializer.FromBinary(bytes, null);

back.Should().BeOfType<Persistent>();
var persisted = (Persistent)back;
persisted.Payload.Should().BeOfType<MyPayload>();
persisted.Sender.Should().BeEquivalentTo(TestActor);
var payload = (MyPayload)persisted.Payload;

// Yes, the data isn't "a" but ".a.", the custom serializer added these dots.
payload.Data.ShouldBe(".a.");
}

[Fact]
public void MessageSerializer_should_serialize_state_change_event()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private PersistentFSMSnapshot GetPersistentFSMSnapshot(object obj)

public override object FromBinary(byte[] bytes, Type type)
{
if(type == null) return GetPersistentRepresentation(PersistentMessage.Parser.ParseFrom(bytes));
if (type == typeof(Persistent)) return GetPersistentRepresentation(PersistentMessage.Parser.ParseFrom(bytes));
if (type == typeof(IPersistentRepresentation)) return GetPersistentRepresentation(PersistentMessage.Parser.ParseFrom(bytes));
if (type == typeof(AtomicWrite)) return GetAtomicWrite(bytes);
Expand Down

0 comments on commit 1d144d7

Please sign in to comment.