Пример #1
0
 public LogDeleterRunnable(NonAggregatingLogHandler _enclosing, string user, ApplicationId
                           applicationId)
 {
     this._enclosing    = _enclosing;
     this.user          = user;
     this.applicationId = applicationId;
 }
        public virtual void TestFailedDirLogDeletion()
        {
            FilePath[]     localLogDirs     = GetLocalLogDirFiles(this.GetType().FullName, 7);
            IList <string> localLogDirPaths = new AList <string>(localLogDirs.Length);

            for (int i = 0; i < localLogDirs.Length; i++)
            {
                localLogDirPaths.AddItem(localLogDirs[i].GetAbsolutePath());
            }
            string localLogDirsString = StringUtils.Join(localLogDirPaths, ",");

            conf.Set(YarnConfiguration.NmLogDirs, localLogDirsString);
            conf.SetBoolean(YarnConfiguration.LogAggregationEnabled, false);
            conf.SetLong(YarnConfiguration.NmLogRetainSeconds, 0l);
            LocalDirsHandlerService mockDirsHandler = Org.Mockito.Mockito.Mock <LocalDirsHandlerService
                                                                                >();
            NonAggregatingLogHandler rawLogHandler = new NonAggregatingLogHandler(dispatcher,
                                                                                  mockDelService, mockDirsHandler, new NMNullStateStoreService());
            NonAggregatingLogHandler logHandler = Org.Mockito.Mockito.Spy(rawLogHandler);
            AbstractFileSystem       spylfs     = Org.Mockito.Mockito.Spy(FileContext.GetLocalFSFileContext
                                                                              ().GetDefaultFileSystem());
            FileContext lfs = FileContext.GetFileContext(spylfs, conf);

            Org.Mockito.Mockito.DoReturn(lfs).When(logHandler).GetLocalFileContext(Matchers.IsA
                                                                                   <Configuration>());
            logHandler.Init(conf);
            logHandler.Start();
            RunMockedFailedDirs(logHandler, appId, user, mockDelService, mockDirsHandler, conf
                                , spylfs, lfs, localLogDirs);
            logHandler.Close();
        }
        public virtual void TestLogDeletion()
        {
            FilePath[] localLogDirs       = GetLocalLogDirFiles(this.GetType().FullName, 2);
            string     localLogDirsString = localLogDirs[0].GetAbsolutePath() + "," + localLogDirs
                                            [1].GetAbsolutePath();

            conf.Set(YarnConfiguration.NmLogDirs, localLogDirsString);
            conf.SetBoolean(YarnConfiguration.LogAggregationEnabled, false);
            conf.SetLong(YarnConfiguration.NmLogRetainSeconds, 0l);
            dirsHandler.Init(conf);
            NonAggregatingLogHandler rawLogHandler = new NonAggregatingLogHandler(dispatcher,
                                                                                  mockDelService, dirsHandler, new NMNullStateStoreService());
            NonAggregatingLogHandler logHandler = Org.Mockito.Mockito.Spy(rawLogHandler);
            AbstractFileSystem       spylfs     = Org.Mockito.Mockito.Spy(FileContext.GetLocalFSFileContext
                                                                              ().GetDefaultFileSystem());
            FileContext lfs = FileContext.GetFileContext(spylfs, conf);

            Org.Mockito.Mockito.DoReturn(lfs).When(logHandler).GetLocalFileContext(Matchers.IsA
                                                                                   <Configuration>());
            FsPermission defaultPermission = FsPermission.GetDirDefault().ApplyUMask(lfs.GetUMask
                                                                                         ());
            FileStatus fs = new FileStatus(0, true, 1, 0, Runtime.CurrentTimeMillis(), 0, defaultPermission
                                           , string.Empty, string.Empty, new Path(localLogDirs[0].GetAbsolutePath()));

            Org.Mockito.Mockito.DoReturn(fs).When(spylfs).GetFileStatus(Matchers.IsA <Path>());
            logHandler.Init(conf);
            logHandler.Start();
            logHandler.Handle(new LogHandlerAppStartedEvent(appId, user, null, ContainerLogsRetentionPolicy
                                                            .AllContainers, null));
            logHandler.Handle(new LogHandlerContainerFinishedEvent(container11, 0));
            logHandler.Handle(new LogHandlerAppFinishedEvent(appId));
            Path[] localAppLogDirs = new Path[2];
            localAppLogDirs[0] = new Path(localLogDirs[0].GetAbsolutePath(), appId.ToString()
                                          );
            localAppLogDirs[1] = new Path(localLogDirs[1].GetAbsolutePath(), appId.ToString()
                                          );
            TestDeletionServiceCall(mockDelService, user, 5000, localAppLogDirs);
            logHandler.Close();
            for (int i = 0; i < localLogDirs.Length; i++)
            {
                FileUtils.DeleteDirectory(localLogDirs[i]);
            }
        }
        public virtual void TestStop()
        {
            NonAggregatingLogHandler aggregatingLogHandler = new NonAggregatingLogHandler(null
                                                                                          , null, null, new NMNullStateStoreService());

            // It should not throw NullPointerException
            aggregatingLogHandler.Stop();
            TestNonAggregatingLogHandler.NonAggregatingLogHandlerWithMockExecutor logHandler =
                new TestNonAggregatingLogHandler.NonAggregatingLogHandlerWithMockExecutor(this,
                                                                                          null, null, null);
            logHandler.Init(new Configuration());
            logHandler.Stop();
            Org.Mockito.Mockito.Verify(logHandler.mockSched).Shutdown();
            Org.Mockito.Mockito.Verify(logHandler.mockSched).AwaitTermination(Matchers.Eq(10l
                                                                                          ), Matchers.Eq(TimeUnit.Seconds));
            Org.Mockito.Mockito.Verify(logHandler.mockSched).ShutdownNow();
            logHandler.Close();
            aggregatingLogHandler.Close();
        }
        public virtual void TestHandlingApplicationFinishedEvent()
        {
            DeletionService          delService            = new DeletionService(null);
            NonAggregatingLogHandler aggregatingLogHandler = new NonAggregatingLogHandler(new
                                                                                          InlineDispatcher(), delService, dirsHandler, new NMNullStateStoreService());

            dirsHandler.Init(conf);
            dirsHandler.Start();
            delService.Init(conf);
            delService.Start();
            aggregatingLogHandler.Init(conf);
            aggregatingLogHandler.Start();
            // It should NOT throw RejectedExecutionException
            aggregatingLogHandler.Handle(new LogHandlerAppFinishedEvent(appId));
            aggregatingLogHandler.Stop();
            // It should NOT throw RejectedExecutionException after stopping
            // handler service.
            aggregatingLogHandler.Handle(new LogHandlerAppFinishedEvent(appId));
            aggregatingLogHandler.Close();
        }