Beispiel #1
0
        public void Cluster_sharding_with_remember_entities_should_setup_shared_journal()
        {
            // start the Persistence extension
            Persistence.Persistence.Instance.Apply(Sys);
            RunOn(() =>
            {
                Persistence.Persistence.Instance.Apply(Sys).JournalFor("akka.persistence.journal.MemoryJournal");
            }, _config.First);
            EnterBarrier("persistence-started");

            RunOn(() =>
            {
                Sys.ActorSelection(Node(_config.First) / "system" / "akka.persistence.journal.MemoryJournal").Tell(new Identify(null));
                var sharedStore = ExpectMsg <ActorIdentity>(TimeSpan.FromSeconds(10)).Subject;
                sharedStore.Should().NotBeNull();

                MemoryJournalShared.SetStore(sharedStore, Sys);
            }, _config.First, _config.Second, _config.Third);
            EnterBarrier("after-1");

            RunOn(() =>
            {
                //check persistence running
                var probe   = CreateTestProbe();
                var journal = Persistence.Persistence.Instance.Get(Sys).JournalFor(null);
                journal.Tell(new Persistence.ReplayMessages(0, 0, long.MaxValue, Guid.NewGuid().ToString(), probe.Ref));
                probe.ExpectMsg <Persistence.RecoverySuccess>(TimeSpan.FromSeconds(10));
            }, _config.First, _config.Second, _config.Third);
            EnterBarrier("after-1-test");
        }
Beispiel #2
0
        public void Cluster_sharding_with_remember_entities_should_start_remembered_entities_in_new_cluster()
        {
            Within(TimeSpan.FromSeconds(30), () =>
            {
                RunOn(() =>
                {
                    Watch(_region.Value);

                    Cluster.Get(Sys).Leave(Cluster.Get(Sys).SelfAddress);
                    ExpectTerminated(_region.Value);
                    AwaitAssert(() =>
                    {
                        Cluster.Get(Sys).IsTerminated.Should().BeTrue();
                    });
                    // no nodes left of the original cluster, start a new cluster

                    var sys2   = ActorSystem.Create(Sys.Name, Sys.Settings.Config);
                    var probe2 = CreateTestProbe(sys2);

                    if (!IsDDataMode)
                    {
                        // setup Persistence
                        Persistence.Persistence.Instance.Apply(sys2);
                        sys2.ActorSelection(Node(_config.First) / "system" / "akka.persistence.journal.MemoryJournal").Tell(new Identify(null), probe2.Ref);
                        var sharedStore = probe2.ExpectMsg <ActorIdentity>(TimeSpan.FromSeconds(10)).Subject;
                        sharedStore.Should().NotBeNull();

                        MemoryJournalShared.SetStore(sharedStore, sys2);
                    }

                    Cluster.Get(sys2).Join(Cluster.Get(sys2).SelfAddress);
                    StartSharding(sys2, probe2.Ref);
                    probe2.ExpectMsg <Started>(TimeSpan.FromSeconds(20));

                    Shutdown(sys2);
                }, _config.Third);
                EnterBarrier("after-3");
            });
        }
        public void Cluster_sharding_with_remember_entities_should_start_new_nodes_with_different_extractor_and_have_the_entities_running_on_the_right_shards()
        {
            Within(TimeSpan.FromSeconds(30), () =>
            {
                // start it with a new shard id extractor, which will put the entities
                // on different shards

                RunOn(() =>
                {
                    Watch(Region(Sys));
                    Cluster.Get(Sys).Leave(Cluster.Get(Sys).SelfAddress);
                    ExpectTerminated(Region(Sys));
                    AwaitAssert(() =>
                    {
                        Cluster.Get(Sys).IsTerminated.Should().BeTrue();
                    });
                }, _config.Second, _config.Third);
                EnterBarrier("first-cluster-terminated");

                // no sharding nodes left of the original cluster, start a new nodes
                RunOn(() =>
                {
                    var sys2   = ActorSystem.Create(Sys.Name, Sys.Settings.Config);
                    var probe2 = CreateTestProbe(sys2);

                    if (!IsDDataMode)
                    {
                        // setup Persistence
                        Persistence.Persistence.Instance.Apply(sys2);
                        sys2.ActorSelection(Node(_config.First) / "system" / "akka.persistence.journal.MemoryJournal").Tell(new Identify(null), probe2.Ref);
                        var sharedStore = probe2.ExpectMsg <ActorIdentity>(TimeSpan.FromSeconds(10)).Subject;
                        sharedStore.Should().NotBeNull();

                        MemoryJournalShared.SetStore(sharedStore, sys2);
                    }

                    Cluster.Get(sys2).Join(Node(_config.First).Address);
                    StartShardingWithExtractor2(sys2, probe2.Ref);
                    probe2.ExpectMsg <Started>(TimeSpan.FromSeconds(20));

                    CurrentShardRegionState stats = null;
                    Within(TimeSpan.FromSeconds(10), () =>
                    {
                        AwaitAssert(() =>
                        {
                            Region(sys2).Tell(GetShardRegionState.Instance);
                            var reply = ExpectMsg <CurrentShardRegionState>();
                            reply.Shards.Should().NotBeEmpty();
                            stats = reply;
                        });
                    });

                    foreach (var shardState in stats.Shards)
                    {
                        foreach (var entityId in shardState.EntityIds)
                        {
                            var calculatedShardId = extractShardId2(int.Parse(entityId));
                            calculatedShardId.ShouldAllBeEquivalentTo(shardState.ShardId);
                        }
                    }

                    EnterBarrier("verified");
                    Shutdown(sys2);
                }, _config.Second, _config.Third);

                RunOn(() =>
                {
                    EnterBarrier("verified");
                }, _config.First);

                EnterBarrier("done");
            });
        }