Ejemplo n.º 1
0
        /// <summary>
        /// Continues monitoring the list of tasks for failures. While no failures occur, it checks the given buffers for any remaining items. When empty it signals the
        /// m_loader object and then it monitors the given number of tasks in the list starting at given index.
        /// </summary>
        /// <param name="tasks"></param>
        /// <param name="indexOfTask"></param>
        /// <param name="numTasks"></param>
        /// <param name="buffers"></param>
        /// <returns></returns>
        protected async Task UnwindSqlLoader(List <Task> tasks, int indexOfTask, int numTasks, List <BoundedConcurrentQueu <Row> > buffers)
        {
            while (!
                   (tasks.Any(
                        task => task.IsFaulted)))
            {
                //if any buffer in the list has anything in it
                if (buffers.Any(
                        buffer => buffer.Any()))
                {
                    await Task.Delay(DefaultMonitoringDelayInMilliSeconds);
                }
                else
                {
                    m_Loader.SignalCompletion();
                    await Task.WhenAll(tasks.GetRange(indexOfTask, numTasks));

                    return;
                }
            }
            GatherExceptionsAndThrow(tasks);
        }
Ejemplo n.º 2
0
        public void PausingReportingSQLLoaderTest()
        {
            D2S.LibraryTests.SqlExtractorTestHelper helper = new D2S.LibraryTests.SqlExtractorTestHelper();
            PipelineContext context = new PipelineContext();

            // ToDo: use connection string from app.config (local version)
            //context.SqlServerName = @"(localdb)\MSSQLLocalDB";
            //context.DatabaseName = "master";

            context.DestinationTableName = "loaderstest";
            try
            {
                context.DestinationTableName = helper.Initialize(ConfigVariables.Instance.ConfiguredConnection);
                context.ColumnNames          = new string[] { "col1", "col2" };
                ConcurrentQueue <Row> input = new ConcurrentQueue <Row>();
                Row newRow = new Row();
                newRow["col1"] = new Tuple <object, Type>("TestValue", typeof(string));
                newRow["col2"] = new Tuple <object, Type>(482, typeof(int));

                input.Enqueue(newRow);

                newRow         = new Row();
                newRow["col1"] = new Tuple <object, Type>("Hi", typeof(string));
                newRow["col2"] = new Tuple <object, Type>(483, typeof(int));

                input.Enqueue(newRow);

                SQLTableLoader loader = new SQLTableLoader();

                var action = loader.GetPausableReportingWorkItem();
                ManualResetEvent pauseButton = new ManualResetEvent(true);
                Progress <int>   progress    = new Progress <int>();

                Task work = Task.Factory.StartNew(() => action(context, input, pauseButton, progress));
                //wait for work to finish
                while (!input.IsEmpty)
                {
                    Task.Delay(200).Wait();
                }
                loader.SignalCompletion();

                work.Wait();

                //confirm that it worked
                SqlRecordExtractor reader = new SqlRecordExtractor();

                List <object>            Results = new List <object>();
                ConcurrentQueue <object> result  = new ConcurrentQueue <object>();
                Action <PipelineContext, IProducerConsumerCollection <object>, ManualResetEvent> readaction = reader.GetPausableWorkItem();
                context.SourceTableName          = context.DestinationTableName;
                context.SqlSourceColumnsSelected = new List <string>()
                {
                    "col1", "col2"
                };
                readaction(context, result, null);

                Results = result.ToList();
                Assert.AreEqual(expected: "TestValue", actual: ((object[])Results[2])[0]);
                Assert.AreEqual(expected: 482, actual: ((object[])Results[2])[1]);
                Assert.AreEqual(expected: "Hi", actual: ((object[])Results[3])[0]);
                Assert.AreEqual(expected: 483, actual: ((object[])Results[3])[1]);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                helper.Cleanup(ConfigVariables.Instance.ConfiguredConnection);
            }
        }