Пример #1
0
        public void TestTaskQueuePreProcessing00()
        {
            var nodes           = CreateBaseNodes().ToArray();
            var tasksToSchedule = new List <AsyncTask>()
            {
                // This older task is kept because it wasn't re-scheduled.
                MakeUpdateRenderPackageAsyncTask(nodes[0].GUID), // 0

                // These older tasks are to be dropped.
                MakeUpdateRenderPackageAsyncTask(nodes[1].GUID), //1
                MakeUpdateRenderPackageAsyncTask(nodes[2].GUID), //2

                // This higher priority task moves to the front.
                MakeUpdateGraphAsyncTask(), //3

                // These newer tasks will be kept.
                MakeUpdateRenderPackageAsyncTask(nodes[1].GUID), //4
                MakeUpdateRenderPackageAsyncTask(nodes[2].GUID), //5

                // This higher priority task moves to the front.
                MakeUpdateGraphAsyncTask(), //6
            };

            // Due to defaulting to auto-run mode, multiple UpdateGraphAsyncTask
            // may have been scheduled prior to this. Clear those tasks before test
            // starts in a predictable state.
            //
            schedulerThread.GetSchedulerToProcessTasks();

            var scheduler = dynamoModel.Scheduler;

            foreach (var stubAsyncTask in tasksToSchedule)
            {
                scheduler.ScheduleForExecution(stubAsyncTask);
            }

            schedulerThread.GetSchedulerToProcessTasks();

            var expected = new List <string>
            {
                "FakeUpdateGraphAsyncTask: 6",
                "FakeUpdateRenderPackageAsyncTask: 0",
                "FakeUpdateRenderPackageAsyncTask: 4",
                "FakeUpdateRenderPackageAsyncTask: 5",
            };

            Assert.AreEqual(expected.Count, results.Count);

            int index = 0;

            foreach (var actual in results)
            {
                Assert.AreEqual(expected[index++], actual);
            }
        }
Пример #2
0
        public void TestTaskQueuePreProcessing05()
        {
            var schedulerThread = new SampleSchedulerThread();
            var scheduler       = new DynamoScheduler(schedulerThread, false);

            // Start scheduling a bunch of tasks.
            var asyncTasks = new AsyncTask[]
            {
                new PrioritizedAsyncTask(scheduler, 1),
                new InconsequentialAsyncTask(scheduler, 100),
            };

            var results = new List <string>();

            foreach (SampleAsyncTask asyncTask in asyncTasks)
            {
                asyncTask.InitializeWithResultList(results);
                scheduler.ScheduleForExecution(asyncTask);
            }

            schedulerThread.GetSchedulerToProcessTasks();

            // Drops all InconsequentialAsyncTask and leave behind one.
            // Kept all PrioritizedAsyncTask instances and sorted them.
            Assert.AreEqual(2, results.Count);
            Assert.AreEqual("PrioritizedAsyncTask: 1", results[0]);
            Assert.AreEqual("InconsequentialAsyncTask: 100", results[1]);
        }
Пример #3
0
        public void TestTaskQueuePreProcessing06()
        {
            var schedulerThread = new SampleSchedulerThread();
            var scheduler       = new DynamoScheduler(schedulerThread, false);

            schedulerThread.GetSchedulerToProcessTasks();
            Assert.Pass("Scheduler thread successfully exits");
        }
Пример #4
0
        public void TestTaskStateChangedEventHandling()
        {
            var observer        = new TaskEventObserver();
            var schedulerThread = new SampleSchedulerThread();
            var scheduler       = new DynamoScheduler(schedulerThread, false);

            scheduler.TaskStateChanged += observer.OnTaskStateChanged;

            // Start scheduling a bunch of tasks.
            var asyncTasks = new AsyncTask[]
            {
                new ErrorProneAsyncTask(scheduler, 7),
                new InconsequentialAsyncTask(scheduler, 100),
                new PrioritizedAsyncTask(scheduler, 1),
                new PrioritizedAsyncTask(scheduler, 5),
                new ErrorProneAsyncTask(scheduler, 3),
                new InconsequentialAsyncTask(scheduler, 500),
                new InconsequentialAsyncTask(scheduler, 300),
                new PrioritizedAsyncTask(scheduler, 3),
                new ErrorProneAsyncTask(scheduler, 5),
            };

            foreach (SampleAsyncTask asyncTask in asyncTasks)
            {
                scheduler.ScheduleForExecution(asyncTask);
            }

            schedulerThread.GetSchedulerToProcessTasks();

            // Drops all InconsequentialAsyncTask and leave behind one.
            // Kept all PrioritizedAsyncTask instances and sorted them.
            var expected = new List <string>
            {
                // Scheduling notifications...

                "Scheduled: ErrorProneAsyncTask: 7",
                "Scheduled: InconsequentialAsyncTask: 100",
                "Scheduled: PrioritizedAsyncTask: 1",
                "Scheduled: PrioritizedAsyncTask: 5",
                "Scheduled: ErrorProneAsyncTask: 3",
                "Scheduled: InconsequentialAsyncTask: 500",
                "Scheduled: InconsequentialAsyncTask: 300",
                "Scheduled: PrioritizedAsyncTask: 3",
                "Scheduled: ErrorProneAsyncTask: 5",

                // Task discarded notifications...

                "Discarded: InconsequentialAsyncTask: 100",
                "Discarded: InconsequentialAsyncTask: 300",

                // Execution of remaining tasks...

                "ExecutionStarting: ErrorProneAsyncTask: 7",
                "ExecutionFailed: ErrorProneAsyncTask: 7",
                "CompletionHandled: ErrorProneAsyncTask: 7",

                "ExecutionStarting: PrioritizedAsyncTask: 1",
                "ExecutionCompleted: PrioritizedAsyncTask: 1",
                "CompletionHandled: PrioritizedAsyncTask: 1",

                "ExecutionStarting: PrioritizedAsyncTask: 5",
                "ExecutionCompleted: PrioritizedAsyncTask: 5",
                "CompletionHandled: PrioritizedAsyncTask: 5",

                "ExecutionStarting: ErrorProneAsyncTask: 3",
                "ExecutionFailed: ErrorProneAsyncTask: 3",
                "CompletionHandled: ErrorProneAsyncTask: 3",

                "ExecutionStarting: PrioritizedAsyncTask: 3",
                "ExecutionCompleted: PrioritizedAsyncTask: 3",
                "CompletionHandled: PrioritizedAsyncTask: 3",

                "ExecutionStarting: ErrorProneAsyncTask: 5",
                "ExecutionFailed: ErrorProneAsyncTask: 5",
                "CompletionHandled: ErrorProneAsyncTask: 5",

                // Execution of InconsequentialAsyncTask last...

                "ExecutionStarting: InconsequentialAsyncTask: 500",
                "ExecutionCompleted: InconsequentialAsyncTask: 500",
                "CompletionHandled: InconsequentialAsyncTask: 500"
            };

            Assert.AreEqual(expected.Count, observer.Results.Count());

            int index = 0;

            foreach (var actual in observer.Results)
            {
                Assert.AreEqual(expected[index++], actual);
            }
        }
Пример #5
0
        public void TestTaskQueuePreProcessing00()
        {
            var nodes           = CreateBaseNodes().ToArray();
            var tasksToSchedule = new List <AsyncTask>()
            {
                // Query value for a given named variable.
                MakeQueryMirrorDataAsyncTask("variableOne"),

                // This older task is kept because it wasn't re-scheduled.
                MakeUpdateRenderPackageAsyncTask(nodes[0].GUID),

                // These older tasks are to be dropped.
                MakeUpdateRenderPackageAsyncTask(nodes[1].GUID),
                MakeUpdateRenderPackageAsyncTask(nodes[2].GUID),

                // These older tasks are to be dropped.
                MakeNotifyRenderPackagesReadyAsyncTask(),
                MakeAggregateRenderPackageAsyncTask(Guid.Empty),

                // This higher priority task moves to the front.
                MakeUpdateGraphAsyncTask(),

                // Query value for a given named variable.
                MakeQueryMirrorDataAsyncTask("variableOne"),

                // These newer tasks will be kept.
                MakeUpdateRenderPackageAsyncTask(nodes[1].GUID),
                MakeUpdateRenderPackageAsyncTask(nodes[2].GUID),

                // This higher priority task moves to the front.
                MakeUpdateGraphAsyncTask(),

                // These newer tasks will be kept.
                MakeNotifyRenderPackagesReadyAsyncTask(),
                MakeAggregateRenderPackageAsyncTask(Guid.Empty),
            };

            // Due to defaulting to auto-run mode, multiple UpdateGraphAsyncTask
            // may have been scheduled prior to this. Clear those tasks before test
            // starts in a predictable state.
            //
            schedulerThread.GetSchedulerToProcessTasks();

            var scheduler = dynamoModel.Scheduler;

            foreach (var stubAsyncTask in tasksToSchedule)
            {
                scheduler.ScheduleForExecution(stubAsyncTask);
            }

            schedulerThread.GetSchedulerToProcessTasks();

            var expected = new List <string>
            {
                "FakeUpdateGraphAsyncTask: 10",
                "FakeQueryMirrorDataAsyncTask: 0",
                "FakeUpdateRenderPackageAsyncTask: 1",
                "FakeQueryMirrorDataAsyncTask: 7",
                "FakeUpdateRenderPackageAsyncTask: 8",
                "FakeUpdateRenderPackageAsyncTask: 9",
                "FakeNotifyRenderPackagesReadyAsyncTask: 11",
                "FakeAggregateRenderPackageAsyncTask: 12",
            };

            Assert.AreEqual(expected.Count, results.Count);

            int index = 0;

            foreach (var actual in results)
            {
                Assert.AreEqual(expected[index++], actual);
            }
        }
Пример #6
0
        public void TestTaskStateChangedEventHandling()
        {
            var observer = new TaskEventObserver();
            var schedulerThread = new SampleSchedulerThread();
            var scheduler = new DynamoScheduler(schedulerThread, false);
            scheduler.TaskStateChanged += observer.OnTaskStateChanged;

            // Start scheduling a bunch of tasks.
            var asyncTasks = new AsyncTask[]
            {
                new ErrorProneAsyncTask(scheduler, 7), 
                new InconsequentialAsyncTask(scheduler, 100),
                new PrioritizedAsyncTask(scheduler, 1),
                new PrioritizedAsyncTask(scheduler, 5),
                new ErrorProneAsyncTask(scheduler, 3), 
                new InconsequentialAsyncTask(scheduler, 500),
                new InconsequentialAsyncTask(scheduler, 300),
                new PrioritizedAsyncTask(scheduler, 3), 
                new ErrorProneAsyncTask(scheduler, 5), 
            };

            foreach (SampleAsyncTask asyncTask in asyncTasks)
                scheduler.ScheduleForExecution(asyncTask);

            schedulerThread.GetSchedulerToProcessTasks();

            // Drops all InconsequentialAsyncTask and leave behind one.
            // Kept all PrioritizedAsyncTask instances and sorted them.
            var expected = new List<string>
            {
                // Scheduling notifications...

                "Scheduled: ErrorProneAsyncTask: 7",
                "Scheduled: InconsequentialAsyncTask: 100",
                "Scheduled: PrioritizedAsyncTask: 1",
                "Scheduled: PrioritizedAsyncTask: 5",
                "Scheduled: ErrorProneAsyncTask: 3",
                "Scheduled: InconsequentialAsyncTask: 500",
                "Scheduled: InconsequentialAsyncTask: 300",
                "Scheduled: PrioritizedAsyncTask: 3",
                "Scheduled: ErrorProneAsyncTask: 5",

                // Task discarded notifications...

                "Discarded: InconsequentialAsyncTask: 100",
                "Discarded: InconsequentialAsyncTask: 300",

                // Execution of remaining tasks...

                "ExecutionStarting: ErrorProneAsyncTask: 7",
                "ExecutionFailed: ErrorProneAsyncTask: 7",
                "CompletionHandled: ErrorProneAsyncTask: 7",

                "ExecutionStarting: PrioritizedAsyncTask: 1",
                "ExecutionCompleted: PrioritizedAsyncTask: 1",
                "CompletionHandled: PrioritizedAsyncTask: 1",

                "ExecutionStarting: PrioritizedAsyncTask: 5",
                "ExecutionCompleted: PrioritizedAsyncTask: 5",
                "CompletionHandled: PrioritizedAsyncTask: 5",

                "ExecutionStarting: ErrorProneAsyncTask: 3",
                "ExecutionFailed: ErrorProneAsyncTask: 3",
                "CompletionHandled: ErrorProneAsyncTask: 3",

                "ExecutionStarting: PrioritizedAsyncTask: 3",
                "ExecutionCompleted: PrioritizedAsyncTask: 3",
                "CompletionHandled: PrioritizedAsyncTask: 3",

                "ExecutionStarting: ErrorProneAsyncTask: 5",
                "ExecutionFailed: ErrorProneAsyncTask: 5",
                "CompletionHandled: ErrorProneAsyncTask: 5",

                // Execution of InconsequentialAsyncTask last...

                "ExecutionStarting: InconsequentialAsyncTask: 500",
                "ExecutionCompleted: InconsequentialAsyncTask: 500",
                "CompletionHandled: InconsequentialAsyncTask: 500"
            };

            Assert.AreEqual(expected.Count, observer.Results.Count());

            int index = 0;
            foreach (var actual in observer.Results)
            {
                Assert.AreEqual(expected[index++], actual);
            }
        }
Пример #7
0
        public void TestTaskQueuePreProcessing06()
        {
            var schedulerThread = new SampleSchedulerThread();
            var scheduler = new DynamoScheduler(schedulerThread, false);

            schedulerThread.GetSchedulerToProcessTasks();
            Assert.Pass("Scheduler thread successfully exits");
        }
Пример #8
0
        public void TestTaskQueuePreProcessing05()
        {
            var schedulerThread = new SampleSchedulerThread();
            var scheduler = new DynamoScheduler(schedulerThread, false);

            // Start scheduling a bunch of tasks.
            var asyncTasks = new AsyncTask[]
            {
                new PrioritizedAsyncTask(scheduler, 1), 
                new InconsequentialAsyncTask(scheduler, 100),
            };

            var results = new List<string>();
            foreach (SampleAsyncTask asyncTask in asyncTasks)
            {
                asyncTask.InitializeWithResultList(results);
                scheduler.ScheduleForExecution(asyncTask);
            }

            schedulerThread.GetSchedulerToProcessTasks();

            // Drops all InconsequentialAsyncTask and leave behind one.
            // Kept all PrioritizedAsyncTask instances and sorted them.
            Assert.AreEqual(2, results.Count);
            Assert.AreEqual("PrioritizedAsyncTask: 1", results[0]);
            Assert.AreEqual("InconsequentialAsyncTask: 100", results[1]);
        }