public _Answer_344(FileContext.Util mockUtil) { this.mockUtil = mockUtil; }
/// <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(); } }