Exemple #1
0
        public void ThreadPoolShouldRunTasksWithoutAnyArguments()
        {
            System.Threading.ManualResetEvent canContinue = new System.Threading.ManualResetEvent(false);

            ThreadPoolImpl pool = new ThreadPoolImpl();

            bool argumentIsNull = false;

            pool.StartTask((obj) => {
                argumentIsNull = null == obj;
                canContinue.Set();
            });

            Assert.True(canContinue.WaitOne(1000));
            Assert.True(argumentIsNull);
        }
Exemple #2
0
        public void ThreadPoolShouldRunTasksWithArgument()
        {
            System.Threading.ManualResetEvent canContinue = new System.Threading.ManualResetEvent(false);

            ThreadPoolImpl pool = new ThreadPoolImpl();

            object o           = new object();
            bool   gotArgument = false;

            pool.StartTask((obj) => {
                gotArgument = object.ReferenceEquals(obj, o);
                canContinue.Set();
            }, o);

            Assert.True(canContinue.WaitOne(1000));
            Assert.True(gotArgument);
        }
 /// <summary>
 /// Default ctor
 /// </summary>
 internal ThreadPoolScheduler(bool isIOScheduler)
 {
     // TODO: Think about why the IO scheduler in the original code would only ever
     //       have cores-1 threads. Does this makes sense? The current code mimics this
     //       behavoir. I'm not sure what the intention of the IO scheduler 
     //       is in the first place, but it seems to be only used in WebClient when 
     //       processing HTTP requests..
     
     if (!isIOScheduler)
         _threadPool = ThreadPool.Default;
     else
     {
         var numCores = ThreadPoolImpl.GetNumCores();
         var coreThreads = Math.Max(1, numCores - 1);
         _threadPool = new ThreadPoolImpl(coreThreads, coreThreads);    
     }
     
 }
        /// <summary>
        /// Default ctor
        /// </summary>
        internal ThreadPoolScheduler(bool isIOScheduler)
        {
            // TODO: Think about why the IO scheduler in the original code would only ever
            //       have cores-1 threads. Does this makes sense? The current code mimics this
            //       behavoir. I'm not sure what the intention of the IO scheduler
            //       is in the first place, but it seems to be only used in WebClient when
            //       processing HTTP requests..

            if (!isIOScheduler)
            {
                _threadPool = ThreadPool.Default;
            }
            else
            {
                var numCores    = ThreadPoolImpl.GetNumCores();
                var coreThreads = Math.Max(1, numCores - 1);
                _threadPool = new ThreadPoolImpl(coreThreads, coreThreads);
            }
        }
Exemple #5
0
        public void PingPongTest()
        {
            ThreadPoolImpl threadPool = new ThreadPoolImpl();
            RouterImpl     router     = new RouterImpl();

            Mock <IMessage> pingMessage = repository.Create <IMessage>();

            pingMessage.SetupGet(m => m.Target).Returns("ping");

            Actor pongActor = new PongActor(pingMessage.Object);

            Mock <IMessage> pongMessage = repository.Create <IMessage>();

            pongMessage.SetupGet(m => m.Target).Returns("pong");

            ManualResetEvent waitSignal = new ManualResetEvent(false);
            PingActor        pingActor  = new PingActor(pongMessage.Object, waitSignal);

            Assert.True(waitSignal.WaitOne(1000));
            pingActor.Verify();
        }