Exemple #1
0
 public Remote(AppDomainStarter st)
 {
     this.st = st;
 }
Exemple #2
0
        private void DoTest(TestConfig cfg, TestActions actions, int timeoutMillis)
        {
            ManualResetEvent ev = new ManualResetEvent(false);

            cfg.Ports = new ushort[6];

            for (int i = 0; i < 6; i++)
            {
                cfg.Ports[i] = StateMachineManager.GetFreePort();
            }

            cfg.RslData = ".\\rsldata";
            cfg.LogPath = ".\\logpath";

            if (Directory.Exists(cfg.RslData))
            {
                Directory.Delete(cfg.RslData, true);
            }

            if (Directory.Exists(cfg.LogPath))
            {
                Directory.Delete(cfg.LogPath, true);
            }

            TestTracer tr = new TestTracer();

            AppDomainStarter ad0             = null;
            AppDomainStarter ad1             = null;
            AppDomainStarter ad2             = null;
            Exception        resultException = null;

            if (cfg.Subject1 != null)
            {
                cfg.Subject1 = cfg.Subject1.Split('=').Last();
            }

            if (cfg.Subject2 != null)
            {
                cfg.Subject2 = cfg.Subject2.Split('=').Last();
            }

            ManagedRSLStateMachine.Init(cfg.LogPath, cfg.Th1, cfg.Th2, cfg.Subject1, cfg.ThumbprintsParent1, cfg.Subject2, cfg.Subjectparent2, false, true, false, false);

            ThreadPool.QueueUserWorkItem(_ =>
            {
                if (!ev.WaitOne(timeoutMillis))
                {
                    resultException = new TimeoutException("not finished on time");
                    ad0.Stop();
                    ad1.Stop();
                    ad2.Stop();
                }
            });

            try
            {
                ad0        = new AppDomainStarter("sm0", 0, cfg);
                ad0.Tracer = tr;
                ad0.Start(true);

                ad1        = new AppDomainStarter("sm1", 1, cfg);
                ad1.Tracer = tr;
                ad1.Start(false);

                ad2        = new AppDomainStarter("sm2", 2, cfg);
                ad2.Tracer = tr;
                ad2.Start(false);

                ad0.SM.WaitForPrimary(30000);

                Console.WriteLine("we got the primary!!");
                ad0.SM.ReplicateCommand(new CommandA(11));
                ad0.SM.ReplicateCommand(new CommandB("eleven"), true);

                if (actions.HasFlag(TestActions.FailoverPrimary))
                {
                    Console.WriteLine("stopping first instance...");
                    ad1.SM.CanBP = true;
                    ad0.Stop();
                    ad1.SM.WaitForPrimary(30000);
                }

                Thread.Sleep(5000);
                if (actions.HasFlag(TestActions.ThumbprintRollover))
                {
                    Console.WriteLine("rolling over thumbprints");
                    ManagedRSLStateMachine.ReplaceThumbprints(cfg.Th3, cfg.Th4, false, false);
                }

                if (actions.HasFlag(TestActions.RecoverFirstInstance) || actions.HasFlag(TestActions.ReturnToFirstPrimary))
                {
                    Console.WriteLine("restarting first instance");
                    ad0.Start(false);
                }

                if (actions.HasFlag(TestActions.ReturnToFirstPrimary))
                {
                    Console.WriteLine("failing second instance into first instance");
                    ad0.SM.CanBP = true;
                    ad1.Stop();
                    ad0.SM.WaitForPrimary(30000);
                }

                ev.Set();
            }
            catch (Exception e)
            {
                if (resultException == null)
                {
                    resultException = e;
                }
            }
            finally
            {
                Console.WriteLine("Unloading all");

                if (ad0 != null)
                {
                    ad0.Stop();
                }

                if (ad1 != null)
                {
                    ad1.Stop();
                }

                if (ad2 != null)
                {
                    ad2.Stop();
                }

                ManagedRSLStateMachine.Unload();
            }

            if (resultException != null)
            {
                if (resultException.InnerException != null)
                {
                    resultException = resultException.InnerException;
                }

                throw resultException;
            }
        }