Inheritance: IAsynchronizer
Ejemplo n.º 1
0
        public void Check_if_data_is_not_retrieved_from_queue()
        {
            const int N = 200;
            const int N_THREADS = 3;

            var sut = new Parallelize(N_THREADS);

            var are = new AutoResetEvent(false);
            var results = new List<int>();
            var threads = new Dictionary<int,bool>();
            Action<IMessage> dequeue = _ => {
                lock(results)
                {
                    if (!threads.ContainsKey(Thread.CurrentThread.ManagedThreadId))
                        threads.Add(Thread.CurrentThread.ManagedThreadId, true);
                    var i = (int) _.Data;
                    results.Add(i);
                    if (results.Count == N) are.Set();
                    Thread.Sleep(i % 20);
                }
            };

            sut.Start();
            for(var i = 1; i<=N; i++)
                sut.Process(new Message("x", i), dequeue);

            Assert.IsTrue(are.WaitOne(4000));
            Assert.AreEqual((N*(N+1)/2), results.Sum());
            Assert.AreEqual(N_THREADS, threads.Count);
        }
Ejemplo n.º 2
0
        public void Check_if_data_is_not_retrieved_from_queue()
        {
            const int N = 200;
            const int N_THREADS = 3;

            var sut = new Parallelize<int>(N_THREADS);

            var are = new AutoResetEvent(false);
            var results = new List<int>();
            var threads = new Dictionary<long,bool>();
            Action<int> dequeue = _ => {
                lock(results)
                {
                    if (!threads.ContainsKey(Thread.CurrentThread.GetHashCode()))
                        threads.Add(Thread.CurrentThread.GetHashCode(), true);
                    results.Add(_);
                    if (results.Count == N) are.Set();
                    Thread.Sleep(_ % 10);
                }
            };

            sut.Start();
            for(var i = 1; i<=N; i++)
                sut.Process(i, dequeue);

            Assert.IsTrue(are.WaitOne(4000));
            Assert.AreEqual((N*(N+1)/2), results.Sum());
            Assert.AreEqual(N_THREADS, threads.Count);
        }
Ejemplo n.º 3
0
 internal AsynchronizeFIFO()
 {
     _parallelize = new Parallelize(1);
 }
 internal AsynchronizeRoundRobin()
 {
     _parallelize = new Parallelize(1, new NotifyingPartionedQueue<ScheduledTask>());
 }
Ejemplo n.º 5
0
 internal AsynchronizeFIFO()
 {
     _parallelize = new Parallelize(1);
 }
Ejemplo n.º 6
0
 internal AsynchronizeRoundRobin()
 {
     _parallelize = new Parallelize(1, new NotifyingPartionedQueue <ScheduledTask>());
 }