/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> public virtual void TestStartLocalizer() { IPEndPoint localizationServerAddress; Path firstDir = new Path(BaseTmpPath, "localDir1"); IList <string> localDirs = new AList <string>(); Path secondDir = new Path(BaseTmpPath, "localDir2"); IList <string> logDirs = new AList <string>(); Path logDir = new Path(BaseTmpPath, "logDir"); Path tokenDir = new Path(BaseTmpPath, "tokenDir"); FsPermission perms = new FsPermission((short)0x1f8); Configuration conf = new Configuration(); localizationServerAddress = conf.GetSocketAddr(YarnConfiguration.NmBindHost, YarnConfiguration .NmLocalizerAddress, YarnConfiguration.DefaultNmLocalizerAddress, YarnConfiguration .DefaultNmLocalizerPort); FileContext mockLfs = Org.Mockito.Mockito.Spy(FileContext.GetLocalFSFileContext(conf )); FileContext.Util mockUtil = Org.Mockito.Mockito.Spy(mockLfs.Util()); Org.Mockito.Mockito.DoAnswer(new _Answer_344(mockUtil)).When(mockLfs).Util(); Org.Mockito.Mockito.DoAnswer(new _Answer_351(firstDir, mockLfs)).When(mockUtil).Copy (Matchers.Any <Path>(), Matchers.Any <Path>()); // throw an Exception when copy token to the first local dir // to simulate no space on the first drive // copy token to the second local dir Org.Mockito.Mockito.DoAnswer(new _Answer_378(firstDir)).When(mockLfs).GetFsStatus (Matchers.Any <Path>()); // let second local directory return more free space than // first local directory DefaultContainerExecutor mockExec = Org.Mockito.Mockito.Spy(new DefaultContainerExecutor (mockLfs)); mockExec.SetConf(conf); localDirs.AddItem(mockLfs.MakeQualified(firstDir).ToString()); localDirs.AddItem(mockLfs.MakeQualified(secondDir).ToString()); logDirs.AddItem(mockLfs.MakeQualified(logDir).ToString()); conf.SetStrings(YarnConfiguration.NmLocalDirs, Sharpen.Collections.ToArray(localDirs , new string[localDirs.Count])); conf.Set(YarnConfiguration.NmLogDirs, logDir.ToString()); mockLfs.Mkdir(tokenDir, perms, true); Path nmPrivateCTokensPath = new Path(tokenDir, "test.tokens"); string appSubmitter = "nobody"; string appId = "APP_ID"; string locId = "LOC_ID"; LocalDirsHandlerService dirsHandler = Org.Mockito.Mockito.Mock <LocalDirsHandlerService >(); Org.Mockito.Mockito.When(dirsHandler.GetLocalDirs()).ThenReturn(localDirs); Org.Mockito.Mockito.When(dirsHandler.GetLogDirs()).ThenReturn(logDirs); try { mockExec.StartLocalizer(nmPrivateCTokensPath, localizationServerAddress, appSubmitter , appId, locId, dirsHandler); } catch (IOException e) { NUnit.Framework.Assert.Fail("StartLocalizer failed to copy token file " + e); } finally { mockExec.DeleteAsUser(appSubmitter, firstDir); mockExec.DeleteAsUser(appSubmitter, secondDir); mockExec.DeleteAsUser(appSubmitter, logDir); DeleteTmpFiles(); } }
public virtual void TestContainerLaunchError() { if (Shell.Windows) { BaseTmpPath = new Path(new FilePath("target").GetAbsolutePath(), typeof(TestDefaultContainerExecutor ).Name); } Path localDir = new Path(BaseTmpPath, "localDir"); IList <string> localDirs = new AList <string>(); localDirs.AddItem(localDir.ToString()); IList <string> logDirs = new AList <string>(); Path logDir = new Path(BaseTmpPath, "logDir"); logDirs.AddItem(logDir.ToString()); Configuration conf = new Configuration(); conf.Set(CommonConfigurationKeys.FsPermissionsUmaskKey, "077"); conf.Set(YarnConfiguration.NmLocalDirs, localDir.ToString()); conf.Set(YarnConfiguration.NmLogDirs, logDir.ToString()); FileContext lfs = FileContext.GetLocalFSFileContext(conf); DefaultContainerExecutor mockExec = Org.Mockito.Mockito.Spy(new DefaultContainerExecutor (lfs)); mockExec.SetConf(conf); Org.Mockito.Mockito.DoAnswer(new _Answer_245()).When(mockExec).LogOutput(Matchers.Any <string>()); string appSubmitter = "nobody"; string appId = "APP_ID"; string containerId = "CONTAINER_ID"; Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container container = Org.Mockito.Mockito.Mock <Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container >(); ContainerId cId = Org.Mockito.Mockito.Mock <ContainerId>(); ContainerLaunchContext context = Org.Mockito.Mockito.Mock <ContainerLaunchContext> (); Dictionary <string, string> env = new Dictionary <string, string>(); Org.Mockito.Mockito.When(container.GetContainerId()).ThenReturn(cId); Org.Mockito.Mockito.When(container.GetLaunchContext()).ThenReturn(context); try { Org.Mockito.Mockito.DoAnswer(new _Answer_268()).When(container).Handle(Matchers.Any <ContainerDiagnosticsUpdateEvent>()); Org.Mockito.Mockito.When(cId.ToString()).ThenReturn(containerId); Org.Mockito.Mockito.When(cId.GetApplicationAttemptId()).ThenReturn(ApplicationAttemptId .NewInstance(ApplicationId.NewInstance(0, 1), 0)); Org.Mockito.Mockito.When(context.GetEnvironment()).ThenReturn(env); mockExec.CreateUserLocalDirs(localDirs, appSubmitter); mockExec.CreateUserCacheDirs(localDirs, appSubmitter); mockExec.CreateAppDirs(localDirs, appSubmitter, appId); mockExec.CreateAppLogDirs(appId, logDirs, appSubmitter); Path scriptPath = new Path("file:///bin/echo"); Path tokensPath = new Path("file:///dev/null"); if (Shell.Windows) { FilePath tmp = new FilePath(BaseTmpPath.ToString(), "test_echo.cmd"); BufferedWriter output = new BufferedWriter(new FileWriter(tmp)); output.Write("Exit 1"); output.Write("Echo No such file or directory 1>&2"); output.Close(); scriptPath = new Path(tmp.GetAbsolutePath()); tmp = new FilePath(BaseTmpPath.ToString(), "tokens"); tmp.CreateNewFile(); tokensPath = new Path(tmp.GetAbsolutePath()); } Path workDir = localDir; Path pidFile = new Path(workDir, "pid.txt"); mockExec.Init(); mockExec.ActivateContainer(cId, pidFile); int ret = mockExec.LaunchContainer(container, scriptPath, tokensPath, appSubmitter , appId, workDir, localDirs, localDirs); NUnit.Framework.Assert.AreNotSame(0, ret); } finally { mockExec.DeleteAsUser(appSubmitter, localDir); mockExec.DeleteAsUser(appSubmitter, logDir); } }