Exemple #1
0
        public void SendScheduledMessageWithRelativeTime()
        {
            m_moduleCoordinator.AddModule("ScheduledMessageReceiver", m_scheduledMessageReceiver);
            m_moduleCoordinator.AddModule("Scheduler", new SchedulerModule());
            m_moduleCoordinator.AddExtension <TimedTriggerExtension>("Scheduler", new TimedTriggerExtension());
            m_moduleCoordinator.StartAll();

            m_moduleCoordinator.PostMessage("Scheduler",
                                            new ScheduledMessage("ScheduledMessageReceiver", "TestMessage1", 100));
            Assert.AreEqual(0, m_scheduledMessageReceiver.ConsumedMessages.Count);
            Thread.Sleep(200);
            Assert.AreEqual(1, m_scheduledMessageReceiver.ConsumedMessages.Count);
            Assert.AreEqual("TestMessage1", m_scheduledMessageReceiver.ConsumedMessages[0]);

            m_moduleCoordinator.PostMessage("Scheduler",
                                            new ScheduledMessage("ScheduledMessageReceiver", "TestMessage2", 200));
            m_moduleCoordinator.PostMessage("Scheduler",
                                            new ScheduledMessage("ScheduledMessageReceiver", "TestMessage3", 100));
            Thread.Sleep(150);
            Assert.AreEqual(2, m_scheduledMessageReceiver.ConsumedMessages.Count);
            Assert.AreEqual("TestMessage3", m_scheduledMessageReceiver.ConsumedMessages[1]);
            Thread.Sleep(100);
            Assert.AreEqual(3, m_scheduledMessageReceiver.ConsumedMessages.Count);
            Assert.AreEqual("TestMessage2", m_scheduledMessageReceiver.ConsumedMessages[2]);

            m_moduleCoordinator.StopAll();
        }
        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();
        }