Ejemplo n.º 1
0
        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"));
            }
        }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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();
                }
            }
        }
Ejemplo n.º 5
0
        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();
            }
        }
Ejemplo n.º 6
0
        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();
                }
            }
        }
Ejemplo n.º 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;
            }
        }