예제 #1
0
        /// <summary>
        /// Construct a new TestWorker.
        /// </summary>
        /// <param name="queue">The queue from which to pull work items</param>
        /// <param name="name">The name of this worker</param>
        public TestWorker(WorkItemQueue queue, string name)
        {
            Guard.ArgumentNotNull(queue, nameof(queue));

            WorkQueue = queue;
            Name      = name;
        }
예제 #2
0
        /// <summary>
        /// Construct a ParallelWorkItemDispatcher
        /// </summary>
        /// <param name="levelOfParallelism">Number of workers to use</param>
        public ParallelWorkItemDispatcher(int levelOfParallelism)
        {
            _levelOfParallelism = levelOfParallelism;

            // Initialize WorkShifts
            Shifts = new WorkShift[]
            {
                _parallelShift,
                _nonParallelShift,
                _nonParallelSTAShift
            };

            foreach (var shift in Shifts)
            {
                shift.EndOfShift += OnEndOfShift;
            }

            // Set up queues for lazy initialization
            _parallelQueue = new Lazy <WorkItemQueue>(() =>
            {
                var parallelQueue = new WorkItemQueue("ParallelQueue");
                _parallelShift.AddQueue(parallelQueue);

                for (int i = 1; i <= _levelOfParallelism; i++)
                {
                    string name = string.Format("Worker#" + i.ToString());
                    _parallelShift.Assign(new TestWorker(parallelQueue, name, ApartmentState.MTA));
                }

                return(parallelQueue);
            });

            _parallelSTAQueue = new Lazy <WorkItemQueue>(() =>
            {
                var parallelSTAQueue = new WorkItemQueue("ParallelSTAQueue");
                _parallelShift.AddQueue(parallelSTAQueue);
                _parallelShift.Assign(new TestWorker(parallelSTAQueue, "Worker#STA", ApartmentState.STA));

                return(parallelSTAQueue);
            });

            _nonParallelQueue = new Lazy <WorkItemQueue>(() =>
            {
                var nonParallelQueue = new WorkItemQueue("NonParallelQueue");
                _nonParallelShift.AddQueue(nonParallelQueue);
                _nonParallelShift.Assign(new TestWorker(nonParallelQueue, "Worker#STA_NP", ApartmentState.MTA));

                return(nonParallelQueue);
            });

            _nonParallelSTAQueue = new Lazy <WorkItemQueue>(() =>
            {
                var nonParallelSTAQueue = new WorkItemQueue("NonParallelSTAQueue");
                _nonParallelSTAShift.AddQueue(nonParallelSTAQueue);
                _nonParallelSTAShift.Assign(new TestWorker(nonParallelSTAQueue, "Worker#NP_STA", ApartmentState.STA));

                return(nonParallelSTAQueue);
            });
        }
예제 #3
0
        /// <summary>
        /// Construct a new TestWorker.
        /// </summary>
        /// <param name="queue">The queue from which to pull work items</param>
        /// <param name="name">The name of this worker</param>
        /// <param name="apartmentState">The apartment state to use for running tests</param>
        public TestWorker(WorkItemQueue queue, string name, ApartmentState apartmentState)
        {
            _readyQueue = queue;

            _workerThread = new Thread(new ThreadStart(TestWorkerThreadProc));
            _workerThread.Name = name;
            _workerThread.SetApartmentState(apartmentState);
        }
예제 #4
0
        /// <summary>
        /// Construct a new TestWorker.
        /// </summary>
        /// <param name="queue">The queue from which to pull work items</param>
        /// <param name="name">The name of this worker</param>
        /// <param name="apartmentState">The apartment state to use for running tests</param>
        public TestWorker(WorkItemQueue queue, string name, ApartmentState apartmentState)
        {
            _readyQueue = queue;

            _workerThread      = new Thread(new ThreadStart(TestWorkerThreadProc));
            _workerThread.Name = name;
            _workerThread.SetApartmentState(apartmentState);
        }
예제 #5
0
        public void CreateQueue()
        {
#if APARTMENT_STATE
            _queue = new WorkItemQueue("TestQ", true, ApartmentState.MTA);
#else
            _queue = new WorkItemQueue("TestQ", true);
#endif
        }
예제 #6
0
        public void SetUp()
        {
            _queue = new WorkItemQueue("TestQ");
#if NETCF
            _worker = new TestWorker(_queue, "TestQ_Worker");
#else
            _worker = new TestWorker(_queue, "TestQ_Worker", ApartmentState.MTA);
#endif
        }
예제 #7
0
        public void SetUp()
        {
#if APARTMENT_STATE
            _queue = new WorkItemQueue("TestQ", true, ApartmentState.MTA);
#else
            _queue = new WorkItemQueue("TestQ", true);
#endif
            _worker = new TestWorker(_queue, "TestQ_Worker");
        }
예제 #8
0
        public void SetUp()
        {
            _queue = new WorkItemQueue("TestQ");
#if NETCF
            _worker = new TestWorker(_queue, "TestQ_Worker");
#else
            _worker = new TestWorker(_queue, "TestQ_Worker", ApartmentState.MTA);
#endif
        }
예제 #9
0
        /// <summary>
        /// Construct a ParallelWorkItemDispatcher
        /// </summary>
        /// <param name="levelOfParallelism">Number of workers to use</param>
        public ParallelWorkItemDispatcher(int levelOfParallelism)
        {
            _levelOfParallelism = levelOfParallelism;

            Shifts = new WorkShift[]
            {
                _parallelShift,
                _nonParallelShift,
                _nonParallelSTAShift
            };
            foreach (var shift in Shifts)
                shift.EndOfShift += OnEndOfShift;

            _parallelQueue = new Lazy<WorkItemQueue>(() =>
            {
                var parallelQueue = new WorkItemQueue("ParallelQueue");
                _parallelShift.AddQueue(parallelQueue);

                for (int i = 1; i <= _levelOfParallelism; i++)
                {
                    string name = string.Format("Worker#" + i.ToString());
                    _parallelShift.Assign(new TestWorker(parallelQueue, name, ApartmentState.MTA));
                }

                return parallelQueue;
            });

            _parallelSTAQueue = new Lazy<WorkItemQueue>(() =>
            {
                var parallelSTAQueue = new WorkItemQueue("ParallelSTAQueue");
                _parallelShift.AddQueue(parallelSTAQueue);
                _parallelShift.Assign(new TestWorker(parallelSTAQueue, "Worker#STA", ApartmentState.STA));

                return parallelSTAQueue;
            });

            _nonParallelQueue = new Lazy<WorkItemQueue>(() =>
            {
                var nonParallelQueue = new WorkItemQueue("NonParallelQueue");
                _nonParallelShift.AddQueue(nonParallelQueue);
                _nonParallelShift.Assign(new TestWorker(nonParallelQueue, "Worker#STA_NP", ApartmentState.MTA));

                return nonParallelQueue;
            });

            _nonParallelSTAQueue = new Lazy<WorkItemQueue>(() =>
            {
                var nonParallelSTAQueue = new WorkItemQueue("NonParallelSTAQueue");
                _nonParallelSTAShift.AddQueue(nonParallelSTAQueue);
                _nonParallelSTAShift.Assign(new TestWorker(nonParallelSTAQueue, "Worker#NP_STA", ApartmentState.STA));

                return nonParallelSTAQueue;
            });
        }
예제 #10
0
        public void HasWorkTest()
        {
            var q = new WorkItemQueue("test", true, ApartmentState.MTA);

            _shift.AddQueue(q);
            Assert.False(_shift.HasWork, "Should not have work initially");
            q.Enqueue(Fakes.GetWorkItem(this, "Test1"));
            Assert.That(_shift.HasWork, "Should have work after enqueue");
            _shift.Start();
            Assert.That(_shift.HasWork, "Should have work after starting");
        }
예제 #11
0
        /// <summary>
        /// Add a WorkItemQueue to the shift, starting it if the
        /// shift is currently active.
        /// </summary>
        public void AddQueue(WorkItemQueue queue)
        {
            log.Debug("{0} shift adding queue {1}", Name, queue.Name);

            Queues.Add(queue);

            if (IsActive)
            {
                queue.Start();
            }
        }
예제 #12
0
        /// <summary>
        /// Construct a new TestWorker.
        /// </summary>
        /// <param name="queue">The queue from which to pull work items</param>
        /// <param name="name">The name of this worker</param>
        /// <param name="apartmentState">The apartment state to use for running tests</param>
        public TestWorker(WorkItemQueue queue, string name
#if !NETCF
                          , ApartmentState apartmentState
#endif
                          )
        {
            _readyQueue = queue;

            _workerThread      = new Thread(new ThreadStart(TestWorkerThreadProc));
            _workerThread.Name = name;
#if !NETCF
            _workerThread.SetApartmentState(apartmentState);
#endif
        }
예제 #13
0
파일: TestWorker.cs 프로젝트: elv1s42/nunit
        /// <summary>
        /// Construct a new TestWorker.
        /// </summary>
        /// <param name="queue">The queue from which to pull work items</param>
        /// <param name="name">The name of this worker</param>
        /// <param name="apartmentState">The apartment state to use for running tests</param>
        public TestWorker(WorkItemQueue queue, string name
#if !NETCF
                          , ApartmentState apartmentState
#endif
                          )
        {
            _readyQueue = queue;

            _workerThread = new Thread(new ThreadStart(TestWorkerThreadProc));
            _workerThread.Name = name;
#if !NETCF
            _workerThread.SetApartmentState(apartmentState);
#endif
        }
예제 #14
0
 /// <summary>
 /// Construct a new TestWorker.
 /// </summary>
 /// <param name="queue">The queue from which to pull work items</param>
 /// <param name="name">The name of this worker</param>
 public TestWorker(WorkItemQueue queue, string name)
 public void HasWorkTest()
 {
     var q = new WorkItemQueue("test");
     _shift.AddQueue(q);
     Assert.False(_shift.HasWork, "Should not have work initially");
     q.Enqueue(Fakes.GetWorkItem(this, "Test1"));
     Assert.That(_shift.HasWork, "Should have work after enqueue");
     _shift.Start();
     Assert.That(_shift.HasWork, "Should have work after starting");
 }
예제 #16
0
 public void SetUp()
 {
     _queue  = new WorkItemQueue("TestQ");
     _worker = new TestWorker(_queue, "TestQ_Worker", ApartmentState.MTA);
 }
예제 #17
0
 public SavedState(WorkItemQueue queue)
 {
     InnerQueues = queue._innerQueues;
     AddId       = queue._addId;
     RemoveId    = queue._removeId;
 }
예제 #18
0
 public void SetUp()
 {
     _queue = new WorkItemQueue("TestQ");
     _worker = new TestWorker(_queue, "TestQ_Worker", ApartmentState.MTA);
 }
예제 #19
0
파일: TestWorker.cs 프로젝트: liusile/nunit
 /// <summary>
 /// Construct a new TestWorker.
 /// </summary>
 /// <param name="queue">The queue from which to pull work items</param>
 /// <param name="name">The name of this worker</param>
 /// <param name="apartmentState">The apartment state to use for running tests</param>
 public TestWorker(WorkItemQueue queue, string name, ApartmentState apartmentState)
 {
     WorkQueue = queue;
     Name      = name;
     Apartment = apartmentState;
 }
예제 #20
0
 public SavedState(WorkItemQueue queue)
 {
     InnerQueues = queue._innerQueues;
 }
예제 #21
0
 public void CreateQueue()
 {
     _queue = new WorkItemQueue("TestQ");
 }
예제 #22
0
        /// <summary>
        /// Construct a ParallelWorkItemDispatcher
        /// </summary>
        /// <param name="levelOfParallelism">Number of workers to use</param>
        public ParallelWorkItemDispatcher(int levelOfParallelism)
        {
            _levelOfParallelism = levelOfParallelism;

            Shifts = new WorkShift[]
            {
                _parallelShift,
                _nonParallelShift,
#if !NETCF
                _nonParallelSTAShift
#endif
            };
            foreach (var shift in Shifts)
            {
                shift.EndOfShift += OnEndOfShift;
            }

            _parallelQueue = new Lazy <WorkItemQueue>(() =>
            {
                var parallelQueue = new WorkItemQueue("ParallelQueue");
                _parallelShift.AddQueue(parallelQueue);

                for (int i = 1; i <= _levelOfParallelism; i++)
                {
                    string name = string.Format("Worker#" + i.ToString());
#if NETCF
                    _parallelShift.Assign(new TestWorker(parallelQueue, name));
#else
                    _parallelShift.Assign(new TestWorker(parallelQueue, name, ApartmentState.MTA));
#endif
                }

                return(parallelQueue);
            });

#if !NETCF
            _parallelSTAQueue = new Lazy <WorkItemQueue>(() =>
            {
                var parallelSTAQueue = new WorkItemQueue("ParallelSTAQueue");
                _parallelShift.AddQueue(parallelSTAQueue);
                _parallelShift.Assign(new TestWorker(parallelSTAQueue, "Worker#STA", ApartmentState.STA));

                return(parallelSTAQueue);
            });
#endif

            _nonParallelQueue = new Lazy <WorkItemQueue>(() =>
            {
                var nonParallelQueue = new WorkItemQueue("NonParallelQueue");
                _nonParallelShift.AddQueue(nonParallelQueue);
#if NETCF
                _nonParallelShift.Assign(new TestWorker(nonParallelQueue, "Worker#NP"));
#else
                _nonParallelShift.Assign(new TestWorker(nonParallelQueue, "Worker#STA_NP", ApartmentState.MTA));
#endif

                return(nonParallelQueue);
            });

#if !NETCF
            _nonParallelSTAQueue = new Lazy <WorkItemQueue>(() =>
            {
                var nonParallelSTAQueue = new WorkItemQueue("NonParallelSTAQueue");
                _nonParallelSTAShift.AddQueue(nonParallelSTAQueue);
                _nonParallelSTAShift.Assign(new TestWorker(nonParallelSTAQueue, "Worker#NP_STA", ApartmentState.STA));

                return(nonParallelSTAQueue);
            });
#endif
        }
예제 #23
0
 public void CreateQueue()
 {
     _queue = new WorkItemQueue("TestQ", true, ApartmentState.MTA);
 }
예제 #24
0
 /// <summary>
 /// Construct a new TestWorker.
 /// </summary>
 /// <param name="queue">The queue from which to pull work items</param>
 /// <param name="name">The name of this worker</param>
 public TestWorker(WorkItemQueue queue, string name)
예제 #25
0
파일: WorkShift.cs 프로젝트: et1975/nunit
        /// <summary>
        /// Add a WorkItemQueue to the shift, starting it if the
        /// shift is currently active.
        /// </summary>
        public void AddQueue(WorkItemQueue queue)
        {
            log.Debug("{0} shift adding queue {1}", _name, queue.Name);

            Queues.Add(queue);

            if (this.IsActive)
                queue.Start();
        }
예제 #26
0
 public void CreateQueue()
 {
     _queue = new WorkItemQueue("TestQ");
 }