Пример #1
0
            /// <exception cref="System.IO.IOException"/>
            protected override void Setup(Mapper.Context context)
            {
                Configuration conf = context.GetConfiguration();

                Path[] localFiles    = context.GetLocalCacheFiles();
                URI[]  files         = context.GetCacheFiles();
                Path[] localArchives = context.GetLocalCacheArchives();
                URI[]  archives      = context.GetCacheArchives();
                // Check that 4 (2 + appjar + DistrubutedCacheChecker jar) files
                // and 2 archives are present
                NUnit.Framework.Assert.AreEqual(4, localFiles.Length);
                NUnit.Framework.Assert.AreEqual(4, files.Length);
                NUnit.Framework.Assert.AreEqual(2, localArchives.Length);
                NUnit.Framework.Assert.AreEqual(2, archives.Length);
                // Check lengths of the files
                IDictionary <string, Path> filesMap = PathsToMap(localFiles);

                NUnit.Framework.Assert.IsTrue(filesMap.Contains("distributed.first.symlink"));
                NUnit.Framework.Assert.AreEqual(1, localFs.GetFileStatus(filesMap["distributed.first.symlink"
                                                                         ]).GetLen());
                NUnit.Framework.Assert.IsTrue(filesMap.Contains("distributed.second.jar"));
                NUnit.Framework.Assert.IsTrue(localFs.GetFileStatus(filesMap["distributed.second.jar"
                                                                    ]).GetLen() > 1);
                // Check extraction of the archive
                IDictionary <string, Path> archivesMap = PathsToMap(localArchives);

                NUnit.Framework.Assert.IsTrue(archivesMap.Contains("distributed.third.jar"));
                NUnit.Framework.Assert.IsTrue(localFs.Exists(new Path(archivesMap["distributed.third.jar"
                                                                      ], "distributed.jar.inside3")));
                NUnit.Framework.Assert.IsTrue(archivesMap.Contains("distributed.fourth.jar"));
                NUnit.Framework.Assert.IsTrue(localFs.Exists(new Path(archivesMap["distributed.fourth.jar"
                                                                      ], "distributed.jar.inside4")));
                // Check the class loaders
                Log.Info("Java Classpath: " + Runtime.GetProperty("java.class.path"));
                ClassLoader cl = Sharpen.Thread.CurrentThread().GetContextClassLoader();

                // Both the file and the archive should have been added to classpath, so
                // both should be reachable via the class loader.
                NUnit.Framework.Assert.IsNotNull(cl.GetResource("distributed.jar.inside2"));
                NUnit.Framework.Assert.IsNotNull(cl.GetResource("distributed.jar.inside3"));
                NUnit.Framework.Assert.IsNotNull(cl.GetResource("distributed.jar.inside4"));
                // The Job Jar should have been extracted to a folder named "job.jar" and
                // added to the classpath; the two jar files in the lib folder in the Job
                // Jar should have also been added to the classpath
                NUnit.Framework.Assert.IsNotNull(cl.GetResource("job.jar/"));
                NUnit.Framework.Assert.IsNotNull(cl.GetResource("job.jar/lib/lib1.jar"));
                NUnit.Framework.Assert.IsNotNull(cl.GetResource("job.jar/lib/lib2.jar"));
                // Check that the symlink for the renaming was created in the cwd;
                FilePath symlinkFile = new FilePath("distributed.first.symlink");

                NUnit.Framework.Assert.IsTrue(symlinkFile.Exists());
                NUnit.Framework.Assert.AreEqual(1, symlinkFile.Length());
                // Check that the symlink for the Job Jar was created in the cwd and
                // points to the extracted directory
                FilePath jobJarDir = new FilePath("job.jar");

                if (Shell.Windows)
                {
                    NUnit.Framework.Assert.IsTrue(IsWindowsSymlinkedDirectory(jobJarDir));
                }
                else
                {
                    NUnit.Framework.Assert.IsTrue(FileUtils.IsSymlink(jobJarDir));
                    NUnit.Framework.Assert.IsTrue(jobJarDir.IsDirectory());
                }
            }