diff --git a/src/contrib/cluster/Akka.DistributedData/Internal/Internal.cs b/src/contrib/cluster/Akka.DistributedData/Internal/Internal.cs index a1096e2cd71..b6295fd7550 100644 --- a/src/contrib/cluster/Akka.DistributedData/Internal/Internal.cs +++ b/src/contrib/cluster/Akka.DistributedData/Internal/Internal.cs @@ -269,9 +269,15 @@ public bool Equals(DataEnvelope other) if (ReferenceEquals(other, null)) return false; if (ReferenceEquals(this, other)) return true; - var pruningCountsEqual = Pruning.Count == other.Pruning.Count; - var elementsEqual = !Pruning.Except(other.Pruning).Any(); - return Data.Equals(other.Data) && pruningCountsEqual && elementsEqual; + if (!Equals(Data, other.Data)) return false; + if (Pruning.Count != other.Pruning.Count) return false; + + foreach (var entry in Pruning) + { + if (!Equals(entry.Value, other.Pruning[entry.Key])) return false; + } + + return true; } public override bool Equals(object obj) => obj is DataEnvelope && Equals((DataEnvelope)obj); diff --git a/src/contrib/cluster/Akka.DistributedData/PruningState.cs b/src/contrib/cluster/Akka.DistributedData/PruningState.cs index c3a4b1bd080..15b3ab1aac3 100644 --- a/src/contrib/cluster/Akka.DistributedData/PruningState.cs +++ b/src/contrib/cluster/Akka.DistributedData/PruningState.cs @@ -9,6 +9,7 @@ using Akka.Cluster; using System; using System.Collections.Immutable; +using System.Text; namespace Akka.DistributedData { @@ -38,10 +39,24 @@ public bool Equals(PruningInitialized other) return Seen.SetEquals(other.Seen); } - public override bool Equals(object obj) => - obj is PruningInitialized && Equals((PruningInitialized) obj); + public override bool Equals(object obj) => + obj is PruningInitialized && Equals((PruningInitialized)obj); public override int GetHashCode() => Seen.GetHashCode(); + + public override string ToString() + { + var sb = new StringBuilder("PruningInitialized("); + if (Seen != null) + { + foreach (var entry in Seen) + { + sb.Append(entry).Append(", "); + } + } + sb.Append(')'); + return sb.ToString(); + } } internal sealed class PruningPerformed : IPruningPhase @@ -51,6 +66,8 @@ internal sealed class PruningPerformed : IPruningPhase private PruningPerformed() { } public override bool Equals(object obj) => obj != null && obj is PruningPerformed; + + public override int GetHashCode() => -1798412870; // "PruningPerformed".GetHashCode() } internal sealed class PruningState @@ -70,7 +87,7 @@ internal PruningState AddSeen(Address node) if (Phase is PruningPerformed) return this; if (Phase is PruningInitialized) { - var p = (PruningInitialized) Phase; + var p = (PruningInitialized)Phase; if (p.Seen.Contains(node) || Owner.Address == node) { return this; @@ -92,8 +109,8 @@ internal PruningState Merge(PruningState that) if (that.Phase is PruningPerformed) return that; if (Phase is PruningInitialized && that.Phase is PruningInitialized) { - var p1 = (PruningInitialized) Phase; - var p2 = (PruningInitialized) that.Phase; + var p1 = (PruningInitialized)Phase; + var p2 = (PruningInitialized)that.Phase; if (this.Owner == that.Owner) return new PruningState(Owner, new PruningInitialized(p1.Seen.Union(p2.Seen))); else if (Member.AddressOrdering.Compare(this.Owner.Address, that.Owner.Address) > 0) @@ -107,19 +124,13 @@ internal PruningState Merge(PruningState that) } } - public override bool Equals(object obj) - { - var other = obj as PruningState; - if (other != null) - { - var equal = Owner.Equals(other.Owner) && Phase.Equals(other.Phase); - return equal; - } - return false; - } + public override bool Equals(object obj) => obj is PruningState && Equals((PruningState) obj); private bool Equals(PruningState other) { + if (ReferenceEquals(other, null)) return false; + if (ReferenceEquals(other, this)) return true; + return Equals(Owner, other.Owner) && Equals(Phase, other.Phase); } @@ -127,7 +138,7 @@ public override int GetHashCode() { unchecked { - return ((Owner != null ? Owner.GetHashCode() : 0)*397) ^ (Phase != null ? Phase.GetHashCode() : 0); + return ((Owner != null ? Owner.GetHashCode() : 0) * 397) ^ (Phase != null ? Phase.GetHashCode() : 0); } }