public void PollingThreadShouldHaveCorrectCultureSet()
        {
            var task = new ThreadCultureRecordingTask();

            using (PollingTaskManager pollingTaskManager = new PollingTaskManager(new BasePollingTask[] { task }, TimeSpanOf25Milliseconds))
            {
                pollingTaskManager.Start();

                WaitForThrowOnTimeout(() => pollingTaskManager.PollCounter > 1, TimeSpanOf100Milliseconds);

                pollingTaskManager.Stop(TimeSpanOf100Milliseconds);

                Assert.That(task.ThreadCulture.Name.ToLowerInvariant(), Is.EqualTo("en-au"));
            }
        }
        public void StartShouldStartTheManager()
        {
            using (PollingTaskManager pollingTaskManager = new PollingTaskManager(new BasePollingTask[0], TimeSpanOf25Milliseconds))
            {
                pollingTaskManager.Start();

                Assert.That(WaitFor(() => pollingTaskManager.PollCounter > 0, TimeSpanOf100Milliseconds), Is.True);

                Assert.That(pollingTaskManager.Status, Is.EqualTo(PollingTaskManagerStatus.Started));
            }
        }
        public void TerminateShouldStopManager()
        {
            using (PollingTaskManager pollingTaskManager = new PollingTaskManager(new BasePollingTask[0], TimeSpanOf25Milliseconds))
            {
                pollingTaskManager.Start();

                WaitForThrowOnTimeout(() => pollingTaskManager.PollCounter > 0, TimeSpanOf100Milliseconds);

                pollingTaskManager.Terminate();

                Assert.That(pollingTaskManager.Status, Is.EqualTo(PollingTaskManagerStatus.Terminated));

                long counter = pollingTaskManager.PollCounter;

                Assert.That(WaitFor(() => pollingTaskManager.PollCounter != counter, TimeSpanOf100Milliseconds), Is.False);
            }
        }
        public void TerminateShouldForcibleyStopExecutingTasks()
        {
            NeverEndingPollingTask task = new NeverEndingPollingTask();

            using (PollingTaskManager pollingTaskManager = new PollingTaskManager(new BasePollingTask[] { task }, TimeSpanOf25Milliseconds))
            {
                pollingTaskManager.Start();

                WaitForThrowOnTimeout(() => pollingTaskManager.PollCounter > 0, TimeSpanOf100Milliseconds);

                WaitForThrowOnTimeout(() => task.Counter > 0, TimeSpanOf100Milliseconds);

                Assert.That(pollingTaskManager.Stop(TimeSpanOf100Milliseconds), Is.False);

                Assert.That(task.IsStillAlive, Is.True);

                pollingTaskManager.Terminate();

                Assert.That(task.IsStillAlive, Is.False);

                if (task.IsStillAlive)
                {
                    task.TerminateTask();
                }
            }
        }
        public void StopShouldNotStopAndReturnWhenTimeoutIsExceeded()
        {
            NeverEndingPollingTask task = new NeverEndingPollingTask();

            using (PollingTaskManager pollingTaskManager = new PollingTaskManager(new BasePollingTask[] { task }, TimeSpanOf25Milliseconds))
            {
                pollingTaskManager.Start();

                WaitForThrowOnTimeout(() => pollingTaskManager.PollCounter > 0, TimeSpanOf100Milliseconds);

                Assert.That(pollingTaskManager.Stop(TimeSpanOf100Milliseconds), Is.False);

                Assert.That(pollingTaskManager.Status, Is.EqualTo(PollingTaskManagerStatus.Started));

                Assert.That(task.IsStillAlive, Is.True);

                task.TerminateTask();
            }
        }
        public void StopShouldCancelRunningTasks()
        {
            LongRunningPollingTask task = new LongRunningPollingTask();

            using (PollingTaskManager pollingTaskManager = new PollingTaskManager(new BasePollingTask[] { task }, TimeSpanOf25Milliseconds))
            {
                pollingTaskManager.Start();

                WaitForThrowOnTimeout(() => pollingTaskManager.PollCounter > 0, TimeSpanOf100Milliseconds);

                WaitForThrowOnTimeout(() => task.Counter > 0, TimeSpanOf100Milliseconds);

                Assert.That(pollingTaskManager.Stop(TimeSpanOf100Milliseconds), Is.True);

                Assert.That(pollingTaskManager.Status, Is.EqualTo(PollingTaskManagerStatus.Stopped));

                Assert.That(task.HasCallToCancelMethod, Is.True);

                Assert.That(task.IsStillAlive, Is.False);

                if (task.IsStillAlive)
                {
                    task.TerminateTask();
                }
            }
        }
Example #7
0
        protected override void OnStart(string[] args)
        {
            try
            {
                Log.Information(this, "Service has been requested to start.");

                if (Manager == null)
                {
                    Log.Debug(this, "Service manager not yet instantiated. Creating instance of service manager.");

                    Manager = new PollingTaskManager(LoadPollingTasks(), PollInterval, Log);
                }

                if (Manager.Status != PollingTaskManagerStatus.Started)
                {
                    Log.Information(this, "Staring service manager.");

                    Manager.Start();
                }
            }
            catch (Exception e)
            {
                LogExceptionError("OnStart", e);
                throw;
            }
        }