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();
        }
Exemplo n.º 2
0
        public virtual void TestContainerLocalizerClosesFilesystems()
        {
            // mocked generics
            // verify filesystems are closed when localizer doesn't fail
            FileContext fs = FileContext.GetLocalFSFileContext();

            spylfs = Org.Mockito.Mockito.Spy(fs.GetDefaultFileSystem());
            ContainerLocalizer localizer = SetupContainerLocalizerForTest();

            Org.Mockito.Mockito.DoNothing().When(localizer).LocalizeFiles(Matchers.Any <LocalizationProtocol
                                                                                        >(), Matchers.Any <CompletionService>(), Matchers.Any <UserGroupInformation>());
            Org.Mockito.Mockito.Verify(localizer, Org.Mockito.Mockito.Never()).CloseFileSystems
                (Matchers.Any <UserGroupInformation>());
            localizer.RunLocalization(nmAddr);
            Org.Mockito.Mockito.Verify(localizer).CloseFileSystems(Matchers.Any <UserGroupInformation
                                                                                 >());
            spylfs = Org.Mockito.Mockito.Spy(fs.GetDefaultFileSystem());
            // verify filesystems are closed when localizer fails
            localizer = SetupContainerLocalizerForTest();
            Org.Mockito.Mockito.DoThrow(new YarnRuntimeException("Forced Failure")).When(localizer
                                                                                         ).LocalizeFiles(Matchers.Any <LocalizationProtocol>(), Matchers.Any <CompletionService
                                                                                                                                                              >(), Matchers.Any <UserGroupInformation>());
            Org.Mockito.Mockito.Verify(localizer, Org.Mockito.Mockito.Never()).CloseFileSystems
                (Matchers.Any <UserGroupInformation>());
            localizer.RunLocalization(nmAddr);
            Org.Mockito.Mockito.Verify(localizer).CloseFileSystems(Matchers.Any <UserGroupInformation
                                                                                 >());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load the KeyPair from the file, or generate a new one.
        /// </summary>
        /// <param name="fileSystem">FileSystem implementation</param>
        public void Load(AbstractFileSystem fileSystem)
        {
            var exists = fileSystem.FileExists(_path);

            if (exists)
            {
                var data = fileSystem.ReadFileAsString(_path);

                if (data != null)
                {
                    var split = data.Split(' ');
                    if (split.Length != 2)
                    {
                        throw new FormatException("Keys file doesn't contain proper data.");
                    }

                    var ecp = GetParams();

                    var q         = Convert.FromBase64String(split[1]);
                    var point     = ecp.Curve.DecodePoint(q);
                    var pubParams = new ECPublicKeyParameters(point, ecp);

                    var d          = new BigInteger(Convert.FromBase64String(split[0]));
                    var privParams = new ECPrivateKeyParameters(d, ecp);

                    BcKeyPair = new AsymmetricCipherKeyPair(pubParams, privParams);
                }
            }
            else
            {
                var key = Generate();
                Save(fileSystem, key);
                BcKeyPair = key;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Save the specified KeyPair.
        /// </summary>
        /// <param name="fileSystem">FileSystem implementation</param>
        /// <param name="keyPair">BouncyCastle Asymmetric KeyPair</param>
        private void Save(AbstractFileSystem fileSystem, AsymmetricCipherKeyPair keyPair)
        {
            var privateBytes = ((ECPrivateKeyParameters)keyPair.Private).D.ToByteArray();
            var publicBytes  = ((ECPublicKeyParameters)keyPair.Public).Q.GetEncoded();
            var data         = Convert.ToBase64String(privateBytes) + " " + Convert.ToBase64String(publicBytes);

            fileSystem.WriteFileFromString(_path, data);
        }
        /// <exception cref="Org.Apache.Hadoop.FS.UnsupportedFileSystemException"/>
        private void TestDefaultUriInternal(string defaultUri)
        {
            Configuration conf = new Configuration();

            FileSystem.SetDefaultUri(conf, defaultUri);
            AbstractFileSystem ftpFs = AbstractFileSystem.Get(FtpUriNoPort, conf);

            Assert.Equal(FtpUriWithPort, ftpFs.GetUri());
        }
        /// <summary>
        /// Function to run a log handler with directories failing the getFileStatus
        /// call.
        /// </summary>
        /// <remarks>
        /// Function to run a log handler with directories failing the getFileStatus
        /// call. The function accepts the log handler, setup the mocks to fail with
        /// specific exceptions and ensures the deletion service has the correct calls.
        /// </remarks>
        /// <param name="logHandler">the logHandler implementation to test</param>
        /// <param name="appId">
        /// the application id that we wish when sending events to the log
        /// handler
        /// </param>
        /// <param name="user">the user name to use</param>
        /// <param name="mockDelService">
        /// a mock of the DeletionService which we will verify
        /// the delete calls against
        /// </param>
        /// <param name="dirsHandler">
        /// a spy or mock on the LocalDirsHandler service used to
        /// when creating the logHandler. It needs to be a spy so that we can intercept
        /// the getAllLogDirs() call.
        /// </param>
        /// <param name="conf">the configuration used</param>
        /// <param name="spylfs">a spy on the AbstractFileSystem object used when creating lfs
        ///     </param>
        /// <param name="lfs">
        /// the FileContext object to be used to mock the getFileStatus()
        /// calls
        /// </param>
        /// <param name="localLogDirs">
        /// list of the log dirs to run the test against, must have
        /// at least 7 entries
        /// </param>
        /// <exception cref="System.Exception"/>
        public static void RunMockedFailedDirs(LogHandler logHandler, ApplicationId appId
                                               , string user, DeletionService mockDelService, LocalDirsHandlerService dirsHandler
                                               , Configuration conf, AbstractFileSystem spylfs, FileContext lfs, FilePath[] localLogDirs
                                               )
        {
            IDictionary <ApplicationAccessType, string> appAcls = new Dictionary <ApplicationAccessType
                                                                                  , string>();

            if (localLogDirs.Length < 7)
            {
                throw new ArgumentException("Argument localLogDirs must be at least of length 7");
            }
            Path[] localAppLogDirPaths = new Path[localLogDirs.Length];
            for (int i = 0; i < localAppLogDirPaths.Length; i++)
            {
                localAppLogDirPaths[i] = new Path(localLogDirs[i].GetAbsolutePath(), appId.ToString
                                                      ());
            }
            IList <string> localLogDirPaths = new AList <string>(localLogDirs.Length);

            for (int i_1 = 0; i_1 < localLogDirs.Length; i_1++)
            {
                localLogDirPaths.AddItem(localLogDirs[i_1].GetAbsolutePath());
            }
            // setup mocks
            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>());
            Org.Mockito.Mockito.DoReturn(localLogDirPaths).When(dirsHandler).GetLogDirsForCleanup
                ();
            logHandler.Handle(new LogHandlerAppStartedEvent(appId, user, null, ContainerLogsRetentionPolicy
                                                            .AllContainers, appAcls));
            // test case where some dirs have the log dir to delete
            // mock some dirs throwing various exceptions
            // verify deletion happens only on the others
            Org.Mockito.Mockito.DoThrow(new FileNotFoundException()).When(spylfs).GetFileStatus
                (Matchers.Eq(localAppLogDirPaths[0]));
            Org.Mockito.Mockito.DoReturn(fs).When(spylfs).GetFileStatus(Matchers.Eq(localAppLogDirPaths
                                                                                    [1]));
            Org.Mockito.Mockito.DoThrow(new AccessControlException()).When(spylfs).GetFileStatus
                (Matchers.Eq(localAppLogDirPaths[2]));
            Org.Mockito.Mockito.DoReturn(fs).When(spylfs).GetFileStatus(Matchers.Eq(localAppLogDirPaths
                                                                                    [3]));
            Org.Mockito.Mockito.DoThrow(new IOException()).When(spylfs).GetFileStatus(Matchers.Eq
                                                                                          (localAppLogDirPaths[4]));
            Org.Mockito.Mockito.DoThrow(new UnsupportedFileSystemException("test")).When(spylfs
                                                                                         ).GetFileStatus(Matchers.Eq(localAppLogDirPaths[5]));
            Org.Mockito.Mockito.DoReturn(fs).When(spylfs).GetFileStatus(Matchers.Eq(localAppLogDirPaths
                                                                                    [6]));
            logHandler.Handle(new LogHandlerAppFinishedEvent(appId));
            TestDeletionServiceCall(mockDelService, user, 5000, localAppLogDirPaths[1], localAppLogDirPaths
                                    [3], localAppLogDirPaths[6]);
            return;
        }
Exemplo n.º 7
0
        public virtual void TestIsValidNameInvalidInBaseFs()
        {
            AbstractFileSystem baseFs     = Org.Mockito.Mockito.Spy(fc.GetDefaultFileSystem());
            ChRootedFs         chRootedFs = new ChRootedFs(baseFs, new Path("/chroot"));

            Org.Mockito.Mockito.DoReturn(false).When(baseFs).IsValidName(Org.Mockito.Mockito.
                                                                         AnyString());
            NUnit.Framework.Assert.IsFalse(chRootedFs.IsValidName("/test"));
            Org.Mockito.Mockito.Verify(baseFs).IsValidName("/chroot/test");
        }
Exemplo n.º 8
0
        public virtual void TestFcDelegationToken()
        {
            FileContext        fcHdfs = FileContext.GetFileContext(cluster.GetFileSystem().GetUri());
            AbstractFileSystem afs    = fcHdfs.GetDefaultFileSystem();
            IList <Org.Apache.Hadoop.Security.Token.Token <object> > tokenList = afs.GetDelegationTokens
                                                                                     (UserGroupInformation.GetCurrentUser().GetUserName());

            ((Org.Apache.Hadoop.FS.Hdfs)afs).RenewDelegationToken((Org.Apache.Hadoop.Security.Token.Token
                                                                   <DelegationTokenIdentifier>)tokenList[0]);
            ((Org.Apache.Hadoop.FS.Hdfs)afs).CancelDelegationToken((Org.Apache.Hadoop.Security.Token.Token
                                                                    <AbstractDelegationTokenIdentifier>)tokenList[0]);
        }
Exemplo n.º 9
0
        public virtual void TestLocalizerTokenIsGettingRemoved()
        {
            FileContext fs = FileContext.GetLocalFSFileContext();

            spylfs = Org.Mockito.Mockito.Spy(fs.GetDefaultFileSystem());
            ContainerLocalizer localizer = SetupContainerLocalizerForTest();

            Org.Mockito.Mockito.DoNothing().When(localizer).LocalizeFiles(Matchers.Any <LocalizationProtocol
                                                                                        >(), Matchers.Any <CompletionService>(), Matchers.Any <UserGroupInformation>());
            localizer.RunLocalization(nmAddr);
            Org.Mockito.Mockito.Verify(spylfs, Org.Mockito.Mockito.Times(1)).Delete(tokenPath
                                                                                    , false);
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestHdfsGetCanonicalServiceName()
        {
            Configuration      conf      = dfs.GetConf();
            URI                haUri     = HATestUtil.GetLogicalUri(cluster);
            AbstractFileSystem afs       = AbstractFileSystem.CreateFileSystem(haUri, conf);
            string             haService = HAUtil.BuildTokenServiceForLogicalUri(haUri, HdfsConstants.HdfsUriScheme
                                                                                 ).ToString();

            NUnit.Framework.Assert.AreEqual(haService, afs.GetCanonicalServiceName());
            Org.Apache.Hadoop.Security.Token.Token <object> token = afs.GetDelegationTokens(UserGroupInformation
                                                                                            .GetCurrentUser().GetShortUserName())[0];
            NUnit.Framework.Assert.AreEqual(haService, token.GetService().ToString());
            // make sure the logical uri is handled correctly
            token.Renew(conf);
            token.Cancel(conf);
        }
Exemplo n.º 11
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestAccessLinkFromAbstractFileSystem()
        {
            Path file = new Path(TestBaseDir1(), "file");
            Path link = new Path(TestBaseDir1(), "linkToFile");

            CreateAndWriteFile(file);
            wrapper.CreateSymlink(file, link, false);
            try
            {
                AbstractFileSystem afs = fc.GetDefaultFileSystem();
                afs.Open(link);
                NUnit.Framework.Assert.Fail("Opened a link using AFS");
            }
            catch (UnresolvedLinkException)
            {
            }
        }
Exemplo n.º 12
0
        public virtual void TestGetFileChecksum()
        {
            AbstractFileSystem mockAFS = Org.Mockito.Mockito.Mock <AbstractFileSystem>();

            InodeTree.ResolveResult <AbstractFileSystem> res = new InodeTree.ResolveResult <AbstractFileSystem
                                                                                            >(null, mockAFS, null, new Path("someFile"));
            InodeTree <AbstractFileSystem> fsState = Org.Mockito.Mockito.Mock <InodeTree>();

            Org.Mockito.Mockito.When(fsState.Resolve(Org.Mockito.Mockito.AnyString(), Org.Mockito.Mockito
                                                     .AnyBoolean())).ThenReturn(res);
            ViewFs vfs = Org.Mockito.Mockito.Mock <ViewFs>();

            vfs.fsState = fsState;
            Org.Mockito.Mockito.When(vfs.GetFileChecksum(new Path("/tmp/someFile"))).ThenCallRealMethod
                ();
            vfs.GetFileChecksum(new Path("/tmp/someFile"));
            Org.Mockito.Mockito.Verify(mockAFS).GetFileChecksum(new Path("someFile"));
        }
        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]);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Performs the operation specified by the next function, calling it
        /// repeatedly until all symlinks in the given path are resolved.
        /// </summary>
        /// <param name="fc">FileContext used to access file systems.</param>
        /// <param name="path">The path to resolve symlinks on.</param>
        /// <returns>Generic type determined by the implementation of next.</returns>
        /// <exception cref="System.IO.IOException"/>
        public virtual T Resolve(FileContext fc, Path path)
        {
            int  count = 0;
            T    @in   = null;
            Path p     = path;
            // NB: More than one AbstractFileSystem can match a scheme, eg
            // "file" resolves to LocalFs but could have come by RawLocalFs.
            AbstractFileSystem fs = fc.GetFSofPath(p);

            // Loop until all symlinks are resolved or the limit is reached
            for (bool isLink = true; isLink;)
            {
                try
                {
                    @in    = Next(fs, p);
                    isLink = false;
                }
                catch (UnresolvedLinkException e)
                {
                    if (!fc.resolveSymlinks)
                    {
                        throw new IOException("Path " + path + " contains a symlink" + " and symlink resolution is disabled ("
                                              + CommonConfigurationKeys.FsClientResolveRemoteSymlinksKey + ").", e);
                    }
                    if (!FileSystem.AreSymlinksEnabled())
                    {
                        throw new IOException("Symlink resolution is disabled in" + " this version of Hadoop."
                                              );
                    }
                    if (count++ > FsConstants.MaxPathLinks)
                    {
                        throw new IOException("Possible cyclic loop while " + "following symbolic link "
                                              + path);
                    }
                    // Resolve the first unresolved path component
                    p  = QualifySymlinkTarget(fs.GetUri(), p, fs.GetLinkTarget(p));
                    fs = fc.GetFSofPath(p);
                }
            }
            return(@in);
        }
Exemplo n.º 15
0
        /// <exception cref="URISyntaxException"/>
        public ChRootedFs(AbstractFileSystem fs, Path theRoot)
            : base(fs.GetUri(), fs.GetUri().GetScheme(), fs.GetUri().GetAuthority() != null,
                   fs.GetUriDefaultPort())
        {
            myFs = fs;
            myFs.CheckPath(theRoot);
            chRootPathPart       = new Path(myFs.GetUriPath(theRoot));
            chRootPathPartString = chRootPathPart.ToUri().GetPath();

            /*
             * We are making URI include the chrootedPath: e.g. file:///chrootedPath.
             * This is questionable since Path#makeQualified(uri, path) ignores
             * the pathPart of a uri. Since this class is internal we can ignore
             * this issue but if we were to make it external then this needs
             * to be resolved.
             */
            // Handle the two cases:
            //              scheme:/// and scheme://authority/
            myUri = new URI(myFs.GetUri().ToString() + (myFs.GetUri().GetAuthority() == null ?
                                                        string.Empty : Path.Separator) + Runtime.Substring(chRootPathPart.ToUri(
                                                                                                               ).GetPath(), 1));
            base.CheckPath(theRoot);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Generic helper function overridden on instantiation to perform a
 /// specific operation on the given file system using the given path
 /// which may result in an UnresolvedLinkException.
 /// </summary>
 /// <param name="fs">AbstractFileSystem to perform the operation on.</param>
 /// <param name="p">Path given the file system.</param>
 /// <returns>Generic type determined by the specific implementation.</returns>
 /// <exception cref="UnresolvedLinkException">
 /// If symbolic link <code>path</code> could
 /// not be resolved
 /// </exception>
 /// <exception cref="System.IO.IOException">an I/O error occurred</exception>
 /// <exception cref="Org.Apache.Hadoop.FS.UnresolvedLinkException"/>
 public abstract T Next(AbstractFileSystem fs, Path p);
Exemplo n.º 17
0
 protected AbstractPlatform(AbstractFileSystem fileSystem = null)
 {
     FileSystem = fileSystem;
 }
Exemplo n.º 18
0
 /// <exception cref="URISyntaxException"/>
 protected internal FilterFs(AbstractFileSystem fs)
     : base(fs.GetUri(), fs.GetUri().GetScheme(), fs.GetUri().GetAuthority() != null,
            fs.GetUriDefaultPort())
 {
     myFs = fs;
 }
Exemplo n.º 19
0
        public virtual void TestContainerLocalizerMain()
        {
            FileContext fs = FileContext.GetLocalFSFileContext();

            spylfs = Org.Mockito.Mockito.Spy(fs.GetDefaultFileSystem());
            ContainerLocalizer localizer = SetupContainerLocalizerForTest();
            // verify created cache
            IList <Path> privCacheList = new AList <Path>();
            IList <Path> appCacheList  = new AList <Path>();

            foreach (Path p in localDirs)
            {
                Path @base     = new Path(new Path(p, ContainerLocalizer.Usercache), appUser);
                Path privcache = new Path(@base, ContainerLocalizer.Filecache);
                privCacheList.AddItem(privcache);
                Path appDir   = new Path(@base, new Path(ContainerLocalizer.Appcache, appId));
                Path appcache = new Path(appDir, ContainerLocalizer.Filecache);
                appCacheList.AddItem(appcache);
            }
            // mock heartbeat responses from NM
            ResourceLocalizationSpec rsrcA = GetMockRsrc(random, LocalResourceVisibility.Private
                                                         , privCacheList[0]);
            ResourceLocalizationSpec rsrcB = GetMockRsrc(random, LocalResourceVisibility.Private
                                                         , privCacheList[0]);
            ResourceLocalizationSpec rsrcC = GetMockRsrc(random, LocalResourceVisibility.Application
                                                         , appCacheList[0]);
            ResourceLocalizationSpec rsrcD = GetMockRsrc(random, LocalResourceVisibility.Private
                                                         , privCacheList[0]);

            Org.Mockito.Mockito.When(nmProxy.Heartbeat(Matchers.IsA <LocalizerStatus>())).ThenReturn
                (new MockLocalizerHeartbeatResponse(LocalizerAction.Live, Sharpen.Collections.SingletonList
                                                        (rsrcA))).ThenReturn(new MockLocalizerHeartbeatResponse(LocalizerAction.Live, Sharpen.Collections
                                                                                                                .SingletonList(rsrcB))).ThenReturn(new MockLocalizerHeartbeatResponse(LocalizerAction
                                                                                                                                                                                      .Live, Sharpen.Collections.SingletonList(rsrcC))).ThenReturn(new MockLocalizerHeartbeatResponse
                                                                                                                                                                                                                                                       (LocalizerAction.Live, Sharpen.Collections.SingletonList(rsrcD))).ThenReturn(new
                                                                                                                                                                                                                                                                                                                                    MockLocalizerHeartbeatResponse(LocalizerAction.Live, Sharpen.Collections.EmptyList
                                                                                                                                                                                                                                                                                                                                                                   <ResourceLocalizationSpec>())).ThenReturn(new MockLocalizerHeartbeatResponse(LocalizerAction
                                                                                                                                                                                                                                                                                                                                                                                                                                                .Die, null));
            LocalResource tRsrcA = rsrcA.GetResource();
            LocalResource tRsrcB = rsrcB.GetResource();
            LocalResource tRsrcC = rsrcC.GetResource();
            LocalResource tRsrcD = rsrcD.GetResource();

            Org.Mockito.Mockito.DoReturn(new TestContainerLocalizer.FakeDownload(rsrcA.GetResource
                                                                                     ().GetResource().GetFile(), true)).When(localizer).Download(Matchers.IsA <Path>()
                                                                                                                                                 , Matchers.Eq(tRsrcA), Matchers.IsA <UserGroupInformation>());
            Org.Mockito.Mockito.DoReturn(new TestContainerLocalizer.FakeDownload(rsrcB.GetResource
                                                                                     ().GetResource().GetFile(), true)).When(localizer).Download(Matchers.IsA <Path>()
                                                                                                                                                 , Matchers.Eq(tRsrcB), Matchers.IsA <UserGroupInformation>());
            Org.Mockito.Mockito.DoReturn(new TestContainerLocalizer.FakeDownload(rsrcC.GetResource
                                                                                     ().GetResource().GetFile(), true)).When(localizer).Download(Matchers.IsA <Path>()
                                                                                                                                                 , Matchers.Eq(tRsrcC), Matchers.IsA <UserGroupInformation>());
            Org.Mockito.Mockito.DoReturn(new TestContainerLocalizer.FakeDownload(rsrcD.GetResource
                                                                                     ().GetResource().GetFile(), true)).When(localizer).Download(Matchers.IsA <Path>()
                                                                                                                                                 , Matchers.Eq(tRsrcD), Matchers.IsA <UserGroupInformation>());
            // run localization
            NUnit.Framework.Assert.AreEqual(0, localizer.RunLocalization(nmAddr));
            foreach (Path p_1 in localDirs)
            {
                Path @base     = new Path(new Path(p_1, ContainerLocalizer.Usercache), appUser);
                Path privcache = new Path(@base, ContainerLocalizer.Filecache);
                // $x/usercache/$user/filecache
                Org.Mockito.Mockito.Verify(spylfs).Mkdir(Matchers.Eq(privcache), Matchers.Eq(CacheDirPerm
                                                                                             ), Matchers.Eq(false));
                Path appDir = new Path(@base, new Path(ContainerLocalizer.Appcache, appId));
                // $x/usercache/$user/appcache/$appId/filecache
                Path appcache = new Path(appDir, ContainerLocalizer.Filecache);
                Org.Mockito.Mockito.Verify(spylfs).Mkdir(Matchers.Eq(appcache), Matchers.Eq(CacheDirPerm
                                                                                            ), Matchers.Eq(false));
            }
            // verify tokens read at expected location
            Org.Mockito.Mockito.Verify(spylfs).Open(tokenPath);
            // verify downloaded resources reported to NM
            Org.Mockito.Mockito.Verify(nmProxy).Heartbeat(Matchers.ArgThat(new TestContainerLocalizer.HBMatches
                                                                               (rsrcA.GetResource())));
            Org.Mockito.Mockito.Verify(nmProxy).Heartbeat(Matchers.ArgThat(new TestContainerLocalizer.HBMatches
                                                                               (rsrcB.GetResource())));
            Org.Mockito.Mockito.Verify(nmProxy).Heartbeat(Matchers.ArgThat(new TestContainerLocalizer.HBMatches
                                                                               (rsrcC.GetResource())));
            Org.Mockito.Mockito.Verify(nmProxy).Heartbeat(Matchers.ArgThat(new TestContainerLocalizer.HBMatches
                                                                               (rsrcD.GetResource())));
            // verify all HB use localizerID provided
            Org.Mockito.Mockito.Verify(nmProxy, Org.Mockito.Mockito.Never()).Heartbeat(Matchers.ArgThat
                                                                                           (new _ArgumentMatcher_193()));
        }
Exemplo n.º 20
0
 /// <exception cref="System.IO.IOException"/>
 /// <exception cref="URISyntaxException"/>
 public ChecksumFs(AbstractFileSystem theFs)
     : base(theFs)
 {
     defaultBytesPerChecksum = GetMyFs().GetServerDefaults().GetBytesPerChecksum();
 }