/* This test checks whether dispatcher hangs on close if following two things
         * happen :
         * 1. A thread which was putting event to event queue is interrupted.
         * 2. Event queue is empty on close.
         */
        /// <exception cref="System.Exception"/>
        public virtual void TestDispatcherOnCloseIfQueueEmpty()
        {
            BlockingQueue <Org.Apache.Hadoop.Yarn.Event.Event> eventQueue = Org.Mockito.Mockito.Spy
                                                                                (new LinkedBlockingQueue <Org.Apache.Hadoop.Yarn.Event.Event>());

            Org.Apache.Hadoop.Yarn.Event.Event @event = Org.Mockito.Mockito.Mock <Org.Apache.Hadoop.Yarn.Event.Event
                                                                                  >();
            Org.Mockito.Mockito.DoThrow(new Exception()).When(eventQueue).Put(@event);
            DrainDispatcher disp = new DrainDispatcher(eventQueue);

            disp.Init(new Configuration());
            disp.SetDrainEventsOnStop();
            disp.Start();
            // Wait for event handler thread to start and begin waiting for events.
            disp.WaitForEventThreadToWait();
            try
            {
                disp.GetEventHandler().Handle(@event);
                NUnit.Framework.Assert.Fail("Expected YarnRuntimeException");
            }
            catch (YarnRuntimeException e)
            {
                NUnit.Framework.Assert.IsTrue(e.InnerException is Exception);
            }
            // Queue should be empty and dispatcher should not hang on close
            NUnit.Framework.Assert.IsTrue("Event Queue should have been empty", eventQueue.IsEmpty
                                              ());
            disp.Close();
        }
        protected internal override void Dispatch(Org.Apache.Hadoop.Yarn.Event.Event @event
                                                  )
        {
            Log.Info("Dispatching the event " + @event.GetType().FullName + "." + @event.ToString
                         ());
            Type type = @event.GetType().GetDeclaringClass();

            if (eventDispatchers[type] != null)
            {
                eventDispatchers[type].Handle(@event);
            }
        }
Beispiel #3
0
        protected internal virtual void Dispatch(Org.Apache.Hadoop.Yarn.Event.Event @event
                                                 )
        {
            //all events go thru this loop
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Dispatching the event " + @event.GetType().FullName + "." + @event.ToString
                              ());
            }
            Type type = @event.GetType().GetDeclaringClass();

            try
            {
                EventHandler handler = eventDispatchers[type];
                if (handler != null)
                {
                    handler.Handle(@event);
                }
                else
                {
                    throw new Exception("No handler for registered for " + type);
                }
            }
            catch (Exception t)
            {
                //TODO Maybe log the state of the queue
                Log.Fatal("Error in dispatcher thread", t);
                // If serviceStop is called, we should exit this thread gracefully.
                if (exitOnDispatchException && (ShutdownHookManager.Get().IsShutdownInProgress())
                    == false && stopped == false)
                {
                    Sharpen.Thread shutDownThread = new Sharpen.Thread(CreateShutDownThread());
                    shutDownThread.SetName("AsyncDispatcher ShutDown handler");
                    shutDownThread.Start();
                }
            }
        }
 public virtual void Handle(Org.Apache.Hadoop.Yarn.Event.Event @event)
 {
     this._enclosing.Dispatch(@event);
 }