Skip to content

Commit

Permalink
fixed tests & local-context ddata
Browse files Browse the repository at this point in the history
  • Loading branch information
Horusiath committed Nov 22, 2016
1 parent 0678b5f commit fa99b55
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
12 changes: 9 additions & 3 deletions src/contrib/cluster/Akka.DistributedData/Internal/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
43 changes: 27 additions & 16 deletions src/contrib/cluster/Akka.DistributedData/PruningState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Akka.Cluster;
using System;
using System.Collections.Immutable;
using System.Text;

namespace Akka.DistributedData
{
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -107,27 +124,21 @@ 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);
}

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

Expand Down

0 comments on commit fa99b55

Please sign in to comment.