コード例 #1
0
        public void ThrowException_On_Enqueue_WhenWorker_Has_Faulted()
        {
            bool bCalled = false;
            BlockingQueue <string> work = new BlockingQueue <string>();

            WorkItemDispatcher <string> dispatcher = new WorkItemDispatcher <string>(
                5, // work in 5 threads
                (data) =>
            {
                try
                {
                    throw new Exception(ExceptionMessage);
                }
                finally
                {
                    bCalled = true;
                }
            },
                work
                );

            work.Enqueue("some work");
            work.ReleaseWaiters();

            while (!bCalled)
            {
                Thread.Sleep(10);
            }
            Thread.Sleep(10);

            Assert.Throws <AggregateException>(() => dispatcher.Dispose());
        }
コード例 #2
0
        /// <summary>
        ///     Downloads the pdbs from the symbol server.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="symbolServer">The symbol server name.</param>
        /// <param name="downloadDir">The download directory. Can be null.</param>
        /// <returns>
        ///     true if all symbols could be downloaded. False otherwise.
        /// </returns>
        public bool DownloadPdbs(FileQuery query, string symbolServer, string downloadDir)
        {
            using (var t = new Tracer(myType, "DownloadPdbs"))
            {
                var lret             = SymChkExecutor.bCanStartSymChk;
                var currentFailCount = this.FailedPdbs.Count;

                var fileQueue  = query.EnumerateFiles;
                var aggregator = new BlockingQueueAggregator <string>(fileQueue);

                Action <string> downLoadPdbThread = (string fileName) =>
                {
                    var pdbFileName = GetPdbNameFromBinaryName(fileName);

                    // delete old pdb to ensure that the new matching pdb is really downloaded. Symchk does not replace existing but not matching pdbs.
                    try
                    {
                        File.Delete(pdbFileName);
                    }
                    catch
                    {
                    }

                    if (!this.Executor.DownLoadPdb(fileName, symbolServer, downloadDir))
                    {
                        lock (this.FailedPdbs)
                        {
                            this.FailedPdbs.Add(Path.GetFileName(fileName));
                        }
                    }
                    else
                    {
                        lock (this.FailedPdbs)
                        {
                            this.SucceededPdbCount++;
                        }
                    }
                };

                var dispatcher = new WorkItemDispatcher <string>(this.myDownLoadThreadCount, downLoadPdbThread, "Pdb Downloader", aggregator, WorkItemOptions.AggregateExceptions);

                try
                {
                    dispatcher.Dispose();
                }
                catch (AggregateException ex)
                {
                    t.Error(ex, "Got error during pdb download");
                    lret = false;
                }

                if (this.FailedPdbs.Count > currentFailCount)
                {
                    t.Warning("The failed pdb count has increased by {0}", this.FailedPdbs.Count - currentFailCount);
                    lret = false;
                }

                return(lret);
            }
        }
コード例 #3
0
ファイル: CommandBase.cs プロジェクト: arlm/apichange
        protected void GetFilesFromQueryMultiThreaded(List <FileQuery> fileQueries, Action <string> fileOperator)
        {
            BlockingQueue <string> [] queues = (from query in fileQueries
                                                select query.EnumerateFiles).ToArray();

            BlockingQueueAggregator <string> aggregator = new BlockingQueueAggregator <string>(queues);

            var dispatcher = new WorkItemDispatcher <string>(myParsedArgs.ThreadCount, fileOperator, "File Loader", aggregator, WorkItemOptions.AggregateExceptions);

            // Wait until work is done
            dispatcher.Dispose();
        }
コード例 #4
0
        public void RethrowException_On_Dispose_By_Default()
        {
            BlockingQueue <string>      work       = new BlockingQueue <string>();
            WorkItemDispatcher <string> dispatcher = new WorkItemDispatcher <string>(
                5, // work in 5 threads
                (data) =>
            {
                throw new Exception(ExceptionMessage);
            },
                work
                );

            work.Enqueue("some work");
            work.ReleaseWaiters();

            Assert.Throws <AggregateException>(() => dispatcher.Dispose());
        }
コード例 #5
0
        public void Do_Not_Throw_On_Enqueue_When_Aggregating()
        {
            int called = 0;

            BlockingQueue <string>      work       = new BlockingQueue <string>();
            WorkItemDispatcher <string> dispatcher = new WorkItemDispatcher <string>(
                5, // work in 5 threads
                (data) =>
            {
                Interlocked.Increment(ref called);
                throw new Exception(ExceptionMessage);
            },
                work,
                WorkItemOptions.AggregateExceptions
                );

            work.Enqueue("some work");

            while (called == 0)
            {
                Thread.Sleep(10);
            }

            for (int i = 0; i < 100; i++)
            {
                work.Enqueue("other work");
            }

            work.ReleaseWaiters();

            try
            {
                dispatcher.Dispose();
            }
            catch (AggregateException ex)
            {
                Assert.AreEqual(101, ex.InnerExceptions.Count);
            }
        }
コード例 #6
0
        public void Can_Use_WorkItemDispatcher_On_STA_Thread()
        {
            Exception cex = null;
            Thread    t   = new Thread(() =>
            {
                try
                {
                    var queue = new BlockingQueue <string>();

                    int processed  = 0;
                    var dispatcher = new WorkItemDispatcher <string>(5,
                                                                     (workstring) =>
                    {
                        Interlocked.Increment(ref processed);
                    },
                                                                     "Tester", queue);

                    queue.Enqueue("Work1");
                    queue.Enqueue("Work2");
                    queue.ReleaseWaiters();

                    dispatcher.Dispose();
                }
                catch (Exception ex)
                {
                    cex = ex;
                }
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();

            if (cex != null)
            {
                Assert.Fail("Get Exception On STA Thread: " + cex);
            }
        }
コード例 #7
0
        public void Can_Process_List_Of_Queues()
        {
            var q1     = new BlockingQueue <string>();
            var q2     = new BlockingQueue <string>();
            var q3     = new BlockingQueue <string>();
            var queues = new BlockingQueue <string>[] { q1, q2, q3 };

            var agg = new BlockingQueueAggregator <string>(queues);

            int processed  = 0;
            var dispatcher = new WorkItemDispatcher <string>(5,
                                                             (workstring) =>
            {
                Interlocked.Increment(ref processed);
            },
                                                             "Tester", agg);

            const int Runs = 10;

            for (int i = 0; i < Runs; i++)
            {
                for (int k = 0; k < queues.Length; k++)
                {
                    queues[k].Enqueue("q" + k.ToString() + "_" + i.ToString());
                }
            }

            // signal end of each queue
            q1.Enqueue(null);
            q2.Enqueue(null);
            q3.Enqueue(null);

            dispatcher.Dispose();

            Assert.AreEqual(Runs * queues.Length, processed);
        }
コード例 #8
0
        /// <summary>
        ///     Downloads the pdbs from the symbol server.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="symbolServer">The symbol server name.</param>
        /// <param name="downloadDir">The download directory. Can be null.</param>
        /// <returns>
        ///     true if all symbols could be downloaded. False otherwise.
        /// </returns>
        public bool DownloadPdbs(FileQuery query, string symbolServer, string downloadDir)
        {
            using (var t = new Tracer(myType, "DownloadPdbs"))
            {
                var lret = SymChkExecutor.bCanStartSymChk;
                var currentFailCount = this.FailedPdbs.Count;

                var fileQueue = query.EnumerateFiles;
                var aggregator = new BlockingQueueAggregator<string>(fileQueue);

                Action<string> downLoadPdbThread = (string fileName) =>
                {
                    var pdbFileName = GetPdbNameFromBinaryName(fileName);

                    // delete old pdb to ensure that the new matching pdb is really downloaded. Symchk does not replace existing but not matching pdbs.
                    try
                    {
                        File.Delete(pdbFileName);
                    }
                    catch
                    {
                    }

                    if (!this.Executor.DownLoadPdb(fileName, symbolServer, downloadDir))
                    {
                        lock (this.FailedPdbs)
                        {
                            this.FailedPdbs.Add(Path.GetFileName(fileName));
                        }
                    }
                    else
                    {
                        lock (this.FailedPdbs)
                        {
                            this.SucceededPdbCount++;
                        }
                    }
                };

                var dispatcher = new WorkItemDispatcher<string>(this.myDownLoadThreadCount, downLoadPdbThread, "Pdb Downloader", aggregator, WorkItemOptions.AggregateExceptions);

                try
                {
                    dispatcher.Dispose();
                }
                catch (AggregateException ex)
                {
                    t.Error(ex, "Got error during pdb download");
                    lret = false;
                }

                if (this.FailedPdbs.Count > currentFailCount)
                {
                    t.Warning("The failed pdb count has increased by {0}", this.FailedPdbs.Count - currentFailCount);
                    lret = false;
                }

                return lret;
            }
        }