Exemplo n.º 1
0
 private static void VerifyQueue(EventQueue q)
 {
     for (int index = 0; index < events.Length; index++)
     {
         Event e = q.Dequeue(false);
         Assert.AreEqual(events[index].GetType(), e.GetType(), string.Format("Event {0}", index));
     }
 }
Exemplo n.º 2
0
 public EventProducer(EventQueue q, int id, bool delay)
 {
     this.queue = q;
     this.ProducerThread = new Thread(new ThreadStart(this.Produce));
     this.ProducerThread.Name = this.GetType().FullName + id;
     this.delay = delay;
 }
Exemplo n.º 3
0
        public void PumpSynchronousAndAsynchronousEvents()
        {
            EventQueue q = new EventQueue();
            using (EventPump pump = new EventPump(TestListener.NULL, q))
            {
                pump.Name = "PumpSynchronousAndAsynchronousEvents";
                pump.Start();

                int numberOfAsynchronousEvents = 0;
                int sumOfAsynchronousQueueLength = 0;
                const int Repetitions = 2;
                for (int i = 0; i < Repetitions; i++)
                {
                    foreach (Event e in events)
                    {
                        q.Enqueue(e);

                        sumOfAsynchronousQueueLength += q.Count;
                        numberOfAsynchronousEvents++;
                    }
                }

                Console.WriteLine("Average queue length: {0}", (float)sumOfAsynchronousQueueLength / numberOfAsynchronousEvents);
            }
        }
Exemplo n.º 4
0
 public void PumpEvents()
 {
     EventQueue q = new EventQueue();
     QueuingEventListener el = new QueuingEventListener();
     using (EventPump pump = new EventPump(el, q))
     {
         pump.Name = "PumpEvents";
         Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Stopped));
         StartPump(pump, 1000);
         Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Pumping));
         EnqueueEvents(q);
         StopPump(pump, 1000);
         Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Stopped));
     }
     VerifyQueue(el.Events);
 }
Exemplo n.º 5
0
 public void SetWaitHandle_Enqueue_Asynchronous()
 {
     using (AutoResetEvent waitHandle = new AutoResetEvent(false))
     {
         this.q = new EventQueue();
         this.afterEnqueue = false;
         this.RunProducerConsumer();
     }
 }
Exemplo n.º 6
0
 public void DequeueBlocking_Stop()
 {
     this.q = new EventQueue();
     this.receivedEvents = 0;
     this.RunProducerConsumer();
     Assert.AreEqual(events.Length + 1, this.receivedEvents);
 }
Exemplo n.º 7
0
 public void DequeueEmpty()
 {
     EventQueue q = new EventQueue();
     Assert.IsNull(q.Dequeue(false));
 }
Exemplo n.º 8
0
 public void StartAndStopPumpOnEmptyQueue()
 {
     EventQueue q = new EventQueue();
     using (EventPump pump = new EventPump(TestListener.NULL, new EventQueue()))
     {
         pump.Name = "StartAndStopPumpOnEmptyQueue";
         StartPump(pump, 1000);
         Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Pumping));
         StopPump(pump, 1000);
         Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Stopped));
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Construct a QueuingEventListener
 /// </summary>
 public QueuingEventListener()
 {
     Events = new EventQueue();
 }
Exemplo n.º 10
0
 /// <summary>
 /// Construct a QueuingEventListener
 /// </summary>
 public QueuingEventListener()
 {
     Events = new EventQueue();
 }
Exemplo n.º 11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="eventListener">The EventListener to receive events</param>
 /// <param name="events">The event queue to pull events from</param>
 public EventPump(ITestListener eventListener, EventQueue events)
 {
     _eventListener = eventListener;
     _events        = events;
 }
Exemplo n.º 12
0
        public void DequeueEmpty()
        {
            EventQueue q = new EventQueue();

            Assert.IsNull(q.Dequeue(false));
        }
Exemplo n.º 13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="eventListener">The EventListener to receive events</param>
 /// <param name="events">The event queue to pull events from</param>
 public EventPump( ITestListener eventListener, EventQueue events)
 {
     this.eventListener = eventListener;
     this.events = events;
     this.events.SetWaitHandleForSynchronizedEvents(this.synchronousEventSent);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="eventListener">The EventListener to receive events</param>
 /// <param name="events">The event queue to pull events from</param>
 public EventPump( ITestListener eventListener, EventQueue events)
 {
     _eventListener = eventListener;
     _events = events;
 }
Exemplo n.º 15
0
        public void EventPumpQueueLength(int numberOfProducers, bool producerDelay)
        {
            EventQueue q = new EventQueue();
            EventProducer[] producers = new EventProducer[numberOfProducers];
            for (int i = 0; i < numberOfProducers; i++)
            {
                producers[i] = new EventProducer(q, i, producerDelay);
            }

            using (EventPump pump = new EventPump(TestListener.NULL, q))
            {
                pump.Name = "EventPumpQueueLength";
                pump.Start();

                foreach (EventProducer p in producers)
                {
                    p.ProducerThread.Start();
                }
                foreach (EventProducer p in producers)
                {
                    p.ProducerThread.Join();
                }
                pump.Stop();
            }
            Assert.That(q.Count, Is.EqualTo(0));

            foreach (EventProducer p in producers)
            {
                Console.WriteLine(
                    "#Events: {0}, MaxQueueLength: {1}", p.SentEventsCount, p.MaxQueueLength);
                Assert.IsNull(p.Exception, "{0}", p.Exception);
            }
        }
Exemplo n.º 16
0
 private static void EnqueueEvents(EventQueue q)
 {
     foreach (Event e in events)
         q.Enqueue(e);
 }
Exemplo n.º 17
0
 public void QueueEvents()
 {
     EventQueue q = new EventQueue();
     EnqueueEvents(q);
     VerifyQueue(q);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="eventListener">The EventListener to receive events</param>
 /// <param name="events">The event queue to pull events from</param>
 public EventPump(ITestListener eventListener, EventQueue events)
 {
     this.eventListener = eventListener;
     this.events        = events;
     this.events.SetWaitHandleForSynchronizedEvents(this.synchronousEventSent);
 }