Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,33 @@ public async Task Bugfix_4400_LWWDictionary_Deltas_must_merge_other_LWWDictionar
merged1.Entries["b"].Should().BeEquivalentTo("B2");
merged1.Entries["c"].Should().BeEquivalentTo("C");
}

/// <summary>
/// Bug reproduction: https://github.com/akkadotnet/akka.net/issues/7910
/// LWWDictionary.Delta should return null when underlying ORDictionary.Delta is null
/// </summary>
[Fact]
public void Bugfix_7910_LWWDictionary_Delta_should_handle_null_underlying_delta()
{
// Empty dictionary has no delta
var empty = LWWDictionary<string, string>.Empty;
empty.Delta.Should().BeNull("empty dictionary should have null delta");

// After ResetDelta(), delta should be null
var m1 = LWWDictionary<string, string>.Empty
.SetItem(_node1, "a", "A")
.SetItem(_node1, "b", "B");

m1.Delta.Should().NotBeNull("dictionary with modifications should have a delta");

var m2 = m1.ResetDelta();
m2.Delta.Should().BeNull("after ResetDelta(), delta should be null");

// Verify the dictionary still contains the data
m2.ContainsKey("a").Should().BeTrue();
m2.ContainsKey("b").Should().BeTrue();
m2["a"].Should().Be("A");
m2["b"].Should().Be("B");
}
}
}
4 changes: 2 additions & 2 deletions src/contrib/cluster/Akka.DistributedData/LWWDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ public override int GetHashCode()
}

// TODO: optimize this so it doesn't allocate each time it's called
public ORDictionary<TKey, LWWRegister<TValue>>.IDeltaOperation Delta =>
new LWWDictionaryDelta(Underlying.Delta);
public ORDictionary<TKey, LWWRegister<TValue>>.IDeltaOperation Delta =>
Underlying.Delta == null ? null : new LWWDictionaryDelta(Underlying.Delta);

IReplicatedDelta IDeltaReplicatedData.Delta => Delta;

Expand Down