コード例 #1
0
ファイル: Class1.cs プロジェクト: tide999/RSL
        static void DoTestNoActivityBadSecondary()
        {
            Console.WriteLine("BadNoActivitySecondary");

            bool        cleanup = (bool)AppDomain.CurrentDomain.GetData("cleanup");
            Application app     = new Application(cleanup);

            Console.WriteLine("  Starting");
            app.StartUp(5);
            app.WaitForPrimary();

            int maxState = app.PrimaryReplica.InternalState;

            if (cleanup)
            {
                maxState = 0;
            }

            bool cycle = false;

            cycle = true;

            Thread thr = new Thread(() =>
            {
                BasicRSLTestMachine oldReplica = app.PrimaryReplica;

                while (cycle)
                {
                    if (oldReplica.IsPrimary)
                    {
                        oldReplica = app.SecondaryReplicas[0];
                    }

                    app.UnloadReplica(oldReplica);
                    Thread.Sleep(5000);
                    app.ReloadReplica(oldReplica);
                }
            });

            thr.Start();

            app.UnloadReplica(app.SecondaryReplicas[0]);

            for (int i = 0; i < 100; i++)
            {
                app.PrimaryReplica.OnPrimaryLoss = new Action <BasicRSLTestMachine>((p) =>
                {
                    Debug.Assert(false, "We should not lose primariness here (" + p.Self + ")");
                });

                for (int j = 0; j < 5; j++)
                {
                    maxState++;
                    app.ReplicateCommand(maxState);

                    Thread.Sleep(5000);
                }

                for (int j = 0; j < 5; j++)
                {
                    maxState++;
                    app.ReplicateCommand(maxState);

                    Thread.Sleep(5000);
                }
                app.PrimaryReplica.OnPrimaryLoss = null;

                Console.WriteLine("failing over...");
                app.FailoverAndWaitForPrimary();
            }

            cycle = false;
            thr.Join();

            Console.WriteLine("  Waiting...");
            app.WaitForAllReplicasInternalState(maxState);

            Console.WriteLine("  Unloading...");
            app.Unload();
            Console.WriteLine("  Unloaded!");
        }
コード例 #2
0
ファイル: Class1.cs プロジェクト: tide999/RSL
        static void DoTestFailover()
        {
            Console.WriteLine("FailoverTest");

            bool        cleanup = (bool)AppDomain.CurrentDomain.GetData("cleanup");
            Application app     = new Application(cleanup);

            Console.WriteLine("  Starting");
            app.StartUp(25);
            app.WaitForPrimary();

            DateTime maxTime = DateTime.UtcNow + TimeSpan.FromSeconds(60);

            int n         = 1;
            int nFailures = 0;
            BasicRSLTestMachine evicted = null;

            Thread thr = new Thread(() =>
            {
                while (DateTime.UtcNow < maxTime)
                {
                    BasicRSLTestMachine prim = app.PrimaryReplica;

                    if (n % 10 == 0)
                    {
                        if (evicted == null)
                        {
                            app.EvictMember(prim.Self.MemberId);
                            evicted = prim;
                            ThreadPool.QueueUserWorkItem((object o) =>
                            {
                                BasicRSLTestMachine oldPrim = (BasicRSLTestMachine)o;
                                while (app.PrimaryReplica == oldPrim)
                                {
                                    Thread.Sleep(100);
                                }
                                nFailures = 0;
                                app.EvictMember(null);
                                evicted = null;
                            }, prim);

                            continue;
                        }
                    }

                    if (prim != evicted || nFailures < 100)
                    {
                        n++;

                        if (!prim.ReplicateRequest(new UserRequest(n)))
                        {
                            nFailures++;
                            Console.WriteLine("{0} couldnt replicate {1}", prim.Self.MemberId, n);
                            app.WaitForPrimary();
                        }
                    }
                }
            });

            thr.Start();
            thr.Join();
            while (evicted != null)
            {
                Thread.Sleep(100);
            }
            Console.WriteLine("==================================== DONE ==================================");

            Console.WriteLine("  Unloading...");
            app.Unload();
            Console.WriteLine("  Unloaded!");
        }