public void ClusterSharding_should_use_second_node()
{
ClusterSharding_should_work_in_single_node_cluster();
Within(TimeSpan.FromSeconds(20), () =>
{
Join(_second, _first);
RunOn(() =>
{
var r = _region.Value;
r.Tell(new Counter.EntityEnvelope(2, Counter.Increment.Instance));
r.Tell(new Counter.EntityEnvelope(2, Counter.Increment.Instance));
r.Tell(new Counter.EntityEnvelope(2, Counter.Increment.Instance));
r.Tell(new Counter.EntityEnvelope(2, Counter.Decrement.Instance));
r.Tell(new Counter.Get(2));
ExpectMsg(2);
r.Tell(new Counter.EntityEnvelope(11, Counter.Increment.Instance));
r.Tell(new Counter.EntityEnvelope(12, Counter.Increment.Instance));
r.Tell(new Counter.Get(11));
ExpectMsg(1);
r.Tell(new Counter.Get(12));
ExpectMsg(1);
}, _second);
EnterBarrier("second-update");
RunOn(() =>
{
var r = _region.Value;
r.Tell(new Counter.EntityEnvelope(2, Counter.Increment.Instance));
r.Tell(new Counter.Get(2));
ExpectMsg(3);
Assert.Equal(Node(_second) / "user" / "counterRegion" / "2" / "2", LastSender.Path);
r.Tell(new Counter.Get(11));
ExpectMsg(1);
// local on first
Assert.Equal(r.Path / "11" / "11", LastSender.Path);
r.Tell(new Counter.Get(12));
ExpectMsg(1);
Assert.Equal(Node(_second) / "user" / "counterRegion" / "0" / "12", LastSender.Path);
}, _first);
EnterBarrier("first-update");
RunOn(() =>
{
var r = _region.Value;
r.Tell(new Counter.Get(2));
ExpectMsg(3);
Assert.Equal(r.Path / "2" / "2", LastSender.Path);
r.Tell(GetCurrentRegions.Instance);
ExpectMsg<CurrentRegions>(x => x.Regions.Length == 2
&& x.Regions[0].Equals(Cluster.SelfAddress)
&& x.Regions[1].Equals(Node(_first).Address));
}, _second);
EnterBarrier("after-3");
});
}