Exemple #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));
     }
 }
Exemple #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;
 }
Exemple #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);
            }
        }
Exemple #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);
 }
Exemple #5
0
 public void SetWaitHandle_Enqueue_Asynchronous()
 {
     using (AutoResetEvent waitHandle = new AutoResetEvent(false))
     {
         this.q = new EventQueue();
         this.afterEnqueue = false;
         this.RunProducerConsumer();
     }
 }
Exemple #6
0
 public void DequeueBlocking_Stop()
 {
     this.q = new EventQueue();
     this.receivedEvents = 0;
     this.RunProducerConsumer();
     Assert.AreEqual(events.Length + 1, this.receivedEvents);
 }
Exemple #7
0
 public void DequeueEmpty()
 {
     EventQueue q = new EventQueue();
     Assert.IsNull(q.Dequeue(false));
 }
 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));
     }
 }
 /// <summary>
 /// Construct a QueuingEventListener
 /// </summary>
 public QueuingEventListener()
 {
     Events = new EventQueue();
 }
 /// <summary>
 /// Construct a QueuingEventListener
 /// </summary>
 public QueuingEventListener()
 {
     Events = new EventQueue();
 }
Exemple #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;
 }
Exemple #12
0
        public void DequeueEmpty()
        {
            EventQueue q = new EventQueue();

            Assert.IsNull(q.Dequeue(false));
        }
 /// <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);
 }
Exemple #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;
 }
        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);
            }
        }
Exemple #16
0
 private static void EnqueueEvents(EventQueue q)
 {
     foreach (Event e in events)
         q.Enqueue(e);
 }
Exemple #17
0
 public void QueueEvents()
 {
     EventQueue q = new EventQueue();
     EnqueueEvents(q);
     VerifyQueue(q);
 }
 /// <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);
 }