public void Persistent_cluster_shards_should_permanently_stop_entities_which_passivate()
{
Persistent_cluster_shards_should_recover_entities_upon_restart();
Within(TimeSpan.FromSeconds(15), () =>
{
RunOn(() =>
{
var x = _persistentRegion.Value;
}, _third, _fourth, _fifth);
EnterBarrier("cluster-started-12");
RunOn(() =>
{
//create and increment counter 1
_persistentRegion.Value.Tell(new Counter.EntityEnvelope(1, Counter.Increment.Instance));
_persistentRegion.Value.Tell(new Counter.Get(1));
ExpectMsg(1);
var counter1 = LastSender;
var shard = Sys.ActorSelection(counter1.Path.Parent);
var region = Sys.ActorSelection(counter1.Path.Parent.Parent);
//create and increment counter 13
_persistentRegion.Value.Tell(new Counter.EntityEnvelope(13, Counter.Increment.Instance));
_persistentRegion.Value.Tell(new Counter.Get(13));
ExpectMsg(1);
var counter13 = LastSender;
Assert.Equal(counter1.Path.Parent, counter13.Path.Parent);
//Send the shard the passivate message from the counter
Watch(counter1);
shard.Tell(new Passivate(Counter.Stop.Instance), counter1);
// watch for the Terminated message
ExpectTerminated(counter1, TimeSpan.FromSeconds(5));
var probe1 = CreateTestProbe();
AwaitAssert(() =>
{
// check counter 1 is dead
counter1.Tell(new Identify(1), probe1.Ref);
probe1.ExpectMsg<ActorIdentity>(i => i.MessageId.Equals(1) && i.Subject == null, TimeSpan.FromSeconds(1));
}, TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(500));
// stop shard cleanly
region.Tell(new PersistentShardCoordinator.HandOff("1"));
ExpectMsg<PersistentShardCoordinator.ShardStopped>(s => s.Shard == "1", TimeSpan.FromSeconds(10));
var probe2 = CreateTestProbe();
AwaitAssert(() =>
{
shard.Tell(new Identify(2), probe2.Ref);
probe1.ExpectMsg<ActorIdentity>(i => i.MessageId.Equals(1) && i.Subject == null, TimeSpan.FromSeconds(1));
}, TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(500));
}, _third);
EnterBarrier("shard-shutdonw-12");
RunOn(() =>
{
// force shard backup
_persistentRegion.Value.Tell(new Counter.Get(25));
ExpectMsg(0);
var shard = LastSender.Path.Parent;
// check counter 1 is still dead
Sys.ActorSelection(shard / "1").Tell(new Identify(3));
ExpectMsg<ActorIdentity>(i => i.MessageId.Equals(3) && i.Subject == null);
// check counter 13 is alive again
Sys.ActorSelection(shard / "13").Tell(new Identify(4));
ExpectMsg<ActorIdentity>(i => i.MessageId.Equals(4) && i.Subject != null);
}, _fourth);
EnterBarrier("after-13");
});
}