コード例 #1
0
ファイル: CohortCompilerTests.cs プロジェクト: rkm/RDMP
        public void AddContainer_StaysAtOne()
        {
            CohortCompiler compiler = new CohortCompiler(cohortIdentificationConfiguration);

            rootcontainer.AddChild(aggregate1, 1);

            compiler.AddTask(rootcontainer, null);//add the root container

            Assert.AreEqual(1, compiler.Tasks.Count);
            var oldTask = compiler.Tasks.First();

            //adding it again with the same SQL should result in it ignoring it
            compiler.AddTask(rootcontainer, null);
            Assert.AreEqual(1, compiler.Tasks.Count);

            //add another aggregate into the container
            rootcontainer.AddChild(aggregate2, 1);

            compiler.AddTask(rootcontainer, null);
            Assert.AreEqual(1, compiler.Tasks.Count);//should still be 1 task

            //old task should have been asked to cancel
            Assert.IsTrue(oldTask.Key.CancellationToken.IsCancellationRequested);
            Assert.AreNotSame(oldTask, compiler.Tasks.Single());                                   //new task should not be the same as the old one
            Assert.IsFalse(compiler.Tasks.Single().Key.CancellationToken.IsCancellationRequested); //new task should not be cancelled

            rootcontainer.RemoveChild(aggregate1);
            rootcontainer.RemoveChild(aggregate2);
        }
コード例 #2
0
        public void AddSameTaskTwice_StaysAtOne()
        {
            CohortCompiler compiler = new CohortCompiler(cohortIdentificationConfiguration);

            container1.AddChild(aggregate1, 0);
            try
            {
                compiler.AddTask(aggregate1, null);

                Assert.AreEqual(1, compiler.Tasks.Count);

                var oldTask = compiler.Tasks.First();

                //adding it again with the same SQL should result in it ignoring it
                compiler.AddTask(aggregate1, null);
                Assert.AreEqual(1, compiler.Tasks.Count);

                //make a change to the SQL
                foreach (var d in aggregate1.AggregateDimensions)
                {
                    d.SelectSQL = "'fish'";
                    d.SaveToDatabase();
                }

                //now add it again
                var newAggregate1 = CatalogueRepository.GetObjectByID <AggregateConfiguration>(aggregate1.ID);

                compiler.AddTask(newAggregate1, null);
                Assert.AreEqual(1, compiler.Tasks.Count); //should still be 1 task

                // TN: Task was never asked to start so was still at NotScheduled so cancellation wouldn't actually happen
                //old task should have been asked to cancel
                //   Assert.IsTrue(oldTask.Key.CancellationToken.IsCancellationRequested);

                Assert.AreNotSame(oldTask, compiler.Tasks.Single()); //new task should not be the same as the old one
                Assert.IsFalse(compiler.Tasks.Single().Key.CancellationToken.IsCancellationRequested);
                //new task should not be cancelled} finally {
            }
            finally
            {
                container1.RemoveChild(aggregate1);
            }
        }
コード例 #3
0
        private ICompileable RunRootContainerOnlyNoCaching(CohortCompiler cohortCompiler)
        {
            //add root container task
            var task = cohortCompiler.AddTask(_cohortIdentificationConfiguration.RootCohortAggregateContainer, _cohortIdentificationConfiguration.GetAllParameters());

            cohortCompiler.LaunchSingleTask(task, Timeout, false);

            //timeout is in seconds
            int countDown = Math.Max(5000, Timeout * 1000);

            while (
                //hasn't timed out
                countDown > 0 &&
                (
                    //state isn't a final state
                    task.State == CompilationState.Executing || task.State == CompilationState.NotScheduled || task.State == CompilationState.Scheduled)
                )
            {
                Task.Delay(100).Wait();
                countDown -= 100;
            }


            if (countDown <= 0)
            {
                try
                {
                    throw new Exception("Cohort failed to reach a final state (Finished/Crashed) after " + Timeout + " seconds. Current state is " + task.State + ".  The task will be cancelled");
                }
                finally
                {
                    cohortCompiler.CancelAllTasks(true);
                }
            }

            return(task);
        }