Skip to content

Commit

Permalink
Fix an inconstant ToString on ConsistentRoutee when the node is remot…
Browse files Browse the repository at this point in the history
…e vs local (#3164)

Signed-off-by: Joshua Benjamin <benjamin@syncromatics.com>
  • Loading branch information
annymsMthd authored and Aaronontheweb committed Oct 19, 2017
1 parent 7eef2c3 commit 85dae97
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
40 changes: 39 additions & 1 deletion src/core/Akka.Remote.Tests/RemoteConsistentHashingRouterSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,44 @@ public void ConsistentHashingGroup_must_use_same_hash_ring_independent_of_self_a
var result2 = keys.Select(k => consistentHash2.NodeFor(k).Routee);
Assert.Equal(result2,result1);
}

/// <summary>
/// This test creates two nodes each with a local routee to themselves and a remote routee to the other node.
/// When using ToString on ConsistentRoutee the local and remote routees are treated differently.
/// This test ensures the two are hashed the same.
/// </summary>
[Fact]
public void ConsistentHashingGroup_must_use_same_hash_ring_independent_of_local_and_remote_nodes()
{
var a1 = new Address("akka.tcp", "RemoteConsistentHashingRouterSpec-1", "client1", 2552);
var a2 = new Address("akka.tcp", "RemoteConsistentHashingRouterSpec-1", "client2", 2552);
var localActor = Sys.ActorOf(Props.Empty, "a");

var s1 = new ActorRefRoutee(localActor);
var s2 = new ActorSelectionRoutee(Sys.ActorSelection("akka.tcp://RemoteConsistentHashingRouterSpec-1@client2:2552/user/a"));
var nodes1 = new List<ConsistentRoutee>(new[] { new ConsistentRoutee(s1, a1), new ConsistentRoutee(s2, a1) });

var s4 = new ActorSelectionRoutee(Sys.ActorSelection("akka.tcp://RemoteConsistentHashingRouterSpec-1@client1:2552/user/a"));
var s5 = new ActorRefRoutee(localActor);

var nodes2 = new List<ConsistentRoutee>(new[] { new ConsistentRoutee(s5, a2), new ConsistentRoutee(s4, a2) });

var consistentHash1 = ConsistentHash.Create(nodes1, 10);
var consistentHash2 = ConsistentHash.Create(nodes2, 10);
var keys = new List<string>(new[] { "A", "B", "C", "D", "E", "F", "G" });

var result1 = keys
.Select(k => consistentHash1.NodeFor(k))
.Select(routee => routee.ToString())
.ToArray();

var result2 = keys
.Select(k => consistentHash2.NodeFor(k))
.Select(routee => routee.ToString())
.ToArray();

result1
.ShouldOnlyContainInOrder(result2);
}
}
}

2 changes: 1 addition & 1 deletion src/core/Akka/Routing/ConsistentHashRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public override string ToString()
case ActorRefRoutee actorRef:
return ToStringWithFullAddress(actorRef.Actor.Path);
case ActorSelectionRoutee selection:
return ToStringWithFullAddress(selection.Selection.Anchor.Path) +
return ToStringWithFullAddress(selection.Selection.Anchor.Path).TrimEnd('/') +
selection.Selection.PathString;
default:
return Routee.ToString();
Expand Down

0 comments on commit 85dae97

Please sign in to comment.