Example #1
0
        public virtual void TestSchedulerEventDispatcherForPreemptionEvents()
        {
            AsyncDispatcher   rmDispatcher = new AsyncDispatcher();
            CapacityScheduler sched        = Org.Mockito.Mockito.Spy(new CapacityScheduler());
            YarnConfiguration conf         = new YarnConfiguration();

            ResourceManager.SchedulerEventDispatcher schedulerDispatcher = new ResourceManager.SchedulerEventDispatcher
                                                                               (sched);
            rmDispatcher.Register(typeof(SchedulerEventType), schedulerDispatcher);
            rmDispatcher.Init(conf);
            rmDispatcher.Start();
            schedulerDispatcher.Init(conf);
            schedulerDispatcher.Start();
            try
            {
                ApplicationAttemptId appAttemptId = Org.Mockito.Mockito.Mock <ApplicationAttemptId
                                                                              >();
                RMContainer           container = Org.Mockito.Mockito.Mock <RMContainer>();
                ContainerPreemptEvent event1    = new ContainerPreemptEvent(appAttemptId, container,
                                                                            SchedulerEventType.DropReservation);
                rmDispatcher.GetEventHandler().Handle(event1);
                ContainerPreemptEvent event2 = new ContainerPreemptEvent(appAttemptId, container,
                                                                         SchedulerEventType.KillContainer);
                rmDispatcher.GetEventHandler().Handle(event2);
                ContainerPreemptEvent event3 = new ContainerPreemptEvent(appAttemptId, container,
                                                                         SchedulerEventType.PreemptContainer);
                rmDispatcher.GetEventHandler().Handle(event3);
                // Wait for events to be processed by scheduler dispatcher.
                Sharpen.Thread.Sleep(1000);
                Org.Mockito.Mockito.Verify(sched, Org.Mockito.Mockito.Times(3)).Handle(Matchers.Any
                                                                                       <SchedulerEvent>());
                Org.Mockito.Mockito.Verify(sched).DropContainerReservation(container);
                Org.Mockito.Mockito.Verify(sched).PreemptContainer(appAttemptId, container);
                Org.Mockito.Mockito.Verify(sched).KillContainer(container);
            }
            catch (Exception)
            {
                NUnit.Framework.Assert.Fail();
            }
            finally
            {
                schedulerDispatcher.Stop();
                rmDispatcher.Stop();
            }
        }
Example #2
0
        public virtual void TestCommitWindow()
        {
            Configuration conf = new Configuration();

            conf.Set(MRJobConfig.MrAmStagingDir, stagingDir);
            AsyncDispatcher dispatcher = new AsyncDispatcher();

            dispatcher.Init(conf);
            dispatcher.Start();
            TestCommitterEventHandler.TestingJobEventHandler jeh = new TestCommitterEventHandler.TestingJobEventHandler
                                                                       ();
            dispatcher.Register(typeof(JobEventType), jeh);
            SystemClock          clock      = new SystemClock();
            AppContext           appContext = Org.Mockito.Mockito.Mock <AppContext>();
            ApplicationAttemptId attemptid  = ConverterUtils.ToApplicationAttemptId("appattempt_1234567890000_0001_0"
                                                                                    );

            Org.Mockito.Mockito.When(appContext.GetApplicationID()).ThenReturn(attemptid.GetApplicationId
                                                                                   ());
            Org.Mockito.Mockito.When(appContext.GetApplicationAttemptId()).ThenReturn(attemptid
                                                                                      );
            Org.Mockito.Mockito.When(appContext.GetEventHandler()).ThenReturn(dispatcher.GetEventHandler
                                                                                  ());
            Org.Mockito.Mockito.When(appContext.GetClock()).ThenReturn(clock);
            OutputCommitter committer = Org.Mockito.Mockito.Mock <OutputCommitter>();

            TestCommitterEventHandler.TestingRMHeartbeatHandler rmhh = new TestCommitterEventHandler.TestingRMHeartbeatHandler
                                                                           ();
            CommitterEventHandler ceh = new CommitterEventHandler(appContext, committer, rmhh
                                                                  );

            ceh.Init(conf);
            ceh.Start();
            // verify trying to commit when RM heartbeats are stale does not commit
            ceh.Handle(new CommitterJobCommitEvent(null, null));
            long timeToWaitMs = 5000;

            while (rmhh.GetNumCallbacks() != 1 && timeToWaitMs > 0)
            {
                Sharpen.Thread.Sleep(10);
                timeToWaitMs -= 10;
            }
            NUnit.Framework.Assert.AreEqual("committer did not register a heartbeat callback"
                                            , 1, rmhh.GetNumCallbacks());
            Org.Mockito.Mockito.Verify(committer, Org.Mockito.Mockito.Never()).CommitJob(Matchers.Any
                                                                                         <JobContext>());
            NUnit.Framework.Assert.AreEqual("committer should not have committed", 0, jeh.numCommitCompletedEvents
                                            );
            // set a fresh heartbeat and verify commit completes
            rmhh.SetLastHeartbeatTime(clock.GetTime());
            timeToWaitMs = 5000;
            while (jeh.numCommitCompletedEvents != 1 && timeToWaitMs > 0)
            {
                Sharpen.Thread.Sleep(10);
                timeToWaitMs -= 10;
            }
            NUnit.Framework.Assert.AreEqual("committer did not complete commit after RM hearbeat"
                                            , 1, jeh.numCommitCompletedEvents);
            Org.Mockito.Mockito.Verify(committer, Org.Mockito.Mockito.Times(1)).CommitJob(Matchers.Any
                                                                                          <JobContext>());
            //Clean up so we can try to commit again (Don't do this at home)
            Cleanup();
            // try to commit again and verify it goes through since the heartbeat
            // is still fresh
            ceh.Handle(new CommitterJobCommitEvent(null, null));
            timeToWaitMs = 5000;
            while (jeh.numCommitCompletedEvents != 2 && timeToWaitMs > 0)
            {
                Sharpen.Thread.Sleep(10);
                timeToWaitMs -= 10;
            }
            NUnit.Framework.Assert.AreEqual("committer did not commit", 2, jeh.numCommitCompletedEvents
                                            );
            Org.Mockito.Mockito.Verify(committer, Org.Mockito.Mockito.Times(2)).CommitJob(Matchers.Any
                                                                                          <JobContext>());
            ceh.Stop();
            dispatcher.Stop();
        }