Exemplo n.º 1
0
        public void RecoverTwoTimesAndThenGiveUp()
        {
            MockUnhandledExceptionReceiver exceptionReceiver = new MockUnhandledExceptionReceiver();

            m_moduleCoordinator.UnhandledExceptionOccurred +=
                new EventHandler <UnhandledModuleExceptionEventArgs>(exceptionReceiver.OnUnhandledExceptionOccurred);
            m_moduleCoordinator.AddModule("SuicidalModule", m_suicidalModule);
            m_moduleCoordinator.AddModule("Watchdog", new WatchdogModule(2));
            m_moduleCoordinator.AddExtension <TimedTriggerExtension>("Watchdog", new TimedTriggerExtension(100, 100, true));
            m_moduleCoordinator.StartAll();

            Assert.IsTrue(m_moduleCoordinator.ModuleControllers["SuicidalModule"].IsAlive);
            m_moduleCoordinator.PostMessage("SuicidalModule", true);
            Thread.Sleep(50);
            Assert.IsFalse(m_moduleCoordinator.ModuleControllers["SuicidalModule"].IsAlive);
            Thread.Sleep(100);
            Assert.IsTrue(m_moduleCoordinator.ModuleControllers["SuicidalModule"].IsAlive);
            m_moduleCoordinator.PostMessage("SuicidalModule", true);
            Thread.Sleep(100);
            m_moduleCoordinator.PostMessage("SuicidalModule", true);
            Thread.Sleep(100);
            Assert.IsFalse(m_moduleCoordinator.ModuleControllers["SuicidalModule"].IsAlive);

            Assert.AreEqual(4, exceptionReceiver.Exceptions.Count);
            Assert.IsInstanceOfType(typeof(ThreadAbortException), exceptionReceiver.Exceptions[0].UnhandledException);
            Assert.IsInstanceOfType(typeof(ThreadAbortException), exceptionReceiver.Exceptions[1].UnhandledException);
            Assert.IsInstanceOfType(typeof(ThreadAbortException), exceptionReceiver.Exceptions[2].UnhandledException);
            Assert.AreEqual("SuicidalModule", exceptionReceiver.Exceptions[3].ModuleName);
            Assert.AreEqual("Module SuicidalModule died and could not be restarted.",
                            exceptionReceiver.Exceptions[3].UnhandledException.Message);

            m_moduleCoordinator.StopAll();
        }
Exemplo n.º 2
0
        public void RecoverTwoTimesAndThenGiveUp()
        {
            MockUnhandledExceptionReceiver exceptionReceiver = new MockUnhandledExceptionReceiver();
            m_moduleCoordinator.UnhandledExceptionOccurred +=
                new EventHandler<UnhandledModuleExceptionEventArgs>(exceptionReceiver.OnUnhandledExceptionOccurred);
            m_moduleCoordinator.AddModule("SuicidalModule", m_suicidalModule);
            m_moduleCoordinator.AddModule("Watchdog", new WatchdogModule(2));
            m_moduleCoordinator.AddExtension<TimedTriggerExtension>("Watchdog", new TimedTriggerExtension(100,100, true));
            m_moduleCoordinator.StartAll();

            Assert.IsTrue(m_moduleCoordinator.ModuleControllers["SuicidalModule"].IsAlive);
            m_moduleCoordinator.PostMessage("SuicidalModule", true);
            Thread.Sleep(50);
            Assert.IsFalse(m_moduleCoordinator.ModuleControllers["SuicidalModule"].IsAlive);
            Thread.Sleep(100);
            Assert.IsTrue(m_moduleCoordinator.ModuleControllers["SuicidalModule"].IsAlive);
            m_moduleCoordinator.PostMessage("SuicidalModule", true);
            Thread.Sleep(100);
            m_moduleCoordinator.PostMessage("SuicidalModule", true);
            Thread.Sleep(100);
            Assert.IsFalse(m_moduleCoordinator.ModuleControllers["SuicidalModule"].IsAlive);

            Assert.AreEqual(4, exceptionReceiver.Exceptions.Count);
            Assert.IsInstanceOfType(typeof(ThreadAbortException), exceptionReceiver.Exceptions[0].UnhandledException);
            Assert.IsInstanceOfType(typeof(ThreadAbortException), exceptionReceiver.Exceptions[1].UnhandledException);
            Assert.IsInstanceOfType(typeof(ThreadAbortException), exceptionReceiver.Exceptions[2].UnhandledException); 
            Assert.AreEqual("SuicidalModule", exceptionReceiver.Exceptions[3].ModuleName);
            Assert.AreEqual("Module SuicidalModule died and could not be restarted.",
                exceptionReceiver.Exceptions[3].UnhandledException.Message);

            m_moduleCoordinator.StopAll();

        }