diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestFSDownload.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestFSDownload.java index af1e765..f3f9f7d 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestFSDownload.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestFSDownload.java @@ -34,6 +34,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; @@ -238,6 +239,9 @@ public void testDownloadBadPublic() throws IOException, URISyntaxException, new FSDownload(files, UserGroupInformation.getCurrentUser(), conf, destPath, rsrc); pending.put(rsrc, exec.submit(fsd)); + exec.shutdown(); + while (!exec.awaitTermination(1000, TimeUnit.MILLISECONDS)); + Assert.assertTrue(pending.get(rsrc).isDone()); try { for (Map.Entry> p : pending.entrySet()) { @@ -246,8 +250,6 @@ public void testDownloadBadPublic() throws IOException, URISyntaxException, } } catch (ExecutionException e) { Assert.assertTrue(e.getCause() instanceof IOException); - } finally { - exec.shutdown(); } } @@ -295,6 +297,12 @@ public void testDownload() throws IOException, URISyntaxException, pending.put(rsrc, exec.submit(fsd)); } + exec.shutdown(); + while (!exec.awaitTermination(1000, TimeUnit.MILLISECONDS)); + for (Future path: pending.values()) { + Assert.assertTrue(path.isDone()); + } + try { for (Map.Entry> p : pending.entrySet()) { Path localized = p.getValue().get(); @@ -316,12 +324,9 @@ public void testDownload() throws IOException, URISyntaxException, } } catch (ExecutionException e) { throw new IOException("Failed exec", e); - } finally { - exec.shutdown(); } } - @SuppressWarnings("deprecation") @Test (timeout=10000) public void testDownloadArchive() throws IOException, URISyntaxException, InterruptedException { @@ -354,12 +359,15 @@ public void testDownloadArchive() throws IOException, URISyntaxException, FSDownload fsd = new FSDownload(files, UserGroupInformation.getCurrentUser(), conf, destPath, rsrc); pending.put(rsrc, exec.submit(fsd)); + exec.shutdown(); + while (!exec.awaitTermination(1000, TimeUnit.MILLISECONDS)); + Assert.assertTrue(pending.get(rsrc).isDone()); try { FileStatus[] filesstatus = files.getDefaultFileSystem().listStatus( basedir); for (FileStatus filestatus : filesstatus) { - if (filestatus.isDir()) { + if (filestatus.isDirectory()) { FileStatus[] childFiles = files.getDefaultFileSystem().listStatus( filestatus.getPath()); for (FileStatus childfile : childFiles) { @@ -373,12 +381,8 @@ public void testDownloadArchive() throws IOException, URISyntaxException, }catch (Exception e) { throw new IOException("Failed exec", e); } - finally { - exec.shutdown(); - } } - - @SuppressWarnings("deprecation") + @Test (timeout=10000) public void testDownloadPatternJar() throws IOException, URISyntaxException, InterruptedException { @@ -412,12 +416,15 @@ public void testDownloadPatternJar() throws IOException, URISyntaxException, FSDownload fsdjar = new FSDownload(files, UserGroupInformation.getCurrentUser(), conf, destPathjar, rsrcjar); pending.put(rsrcjar, exec.submit(fsdjar)); + exec.shutdown(); + while (!exec.awaitTermination(1000, TimeUnit.MILLISECONDS)); + Assert.assertTrue(pending.get(rsrcjar).isDone()); try { FileStatus[] filesstatus = files.getDefaultFileSystem().listStatus( basedir); for (FileStatus filestatus : filesstatus) { - if (filestatus.isDir()) { + if (filestatus.isDirectory()) { FileStatus[] childFiles = files.getDefaultFileSystem().listStatus( filestatus.getPath()); for (FileStatus childfile : childFiles) { @@ -431,12 +438,8 @@ public void testDownloadPatternJar() throws IOException, URISyntaxException, }catch (Exception e) { throw new IOException("Failed exec", e); } - finally { - exec.shutdown(); - } } - @SuppressWarnings("deprecation") @Test (timeout=10000) public void testDownloadArchiveZip() throws IOException, URISyntaxException, InterruptedException { @@ -469,12 +472,15 @@ public void testDownloadArchiveZip() throws IOException, URISyntaxException, FSDownload fsdzip = new FSDownload(files, UserGroupInformation.getCurrentUser(), conf, destPathjar, rsrczip); pending.put(rsrczip, exec.submit(fsdzip)); + exec.shutdown(); + while (!exec.awaitTermination(1000, TimeUnit.MILLISECONDS)); + Assert.assertTrue(pending.get(rsrczip).isDone()); try { FileStatus[] filesstatus = files.getDefaultFileSystem().listStatus( basedir); for (FileStatus filestatus : filesstatus) { - if (filestatus.isDir()) { + if (filestatus.isDirectory()) { FileStatus[] childFiles = files.getDefaultFileSystem().listStatus( filestatus.getPath()); for (FileStatus childfile : childFiles) { @@ -488,9 +494,6 @@ public void testDownloadArchiveZip() throws IOException, URISyntaxException, }catch (Exception e) { throw new IOException("Failed exec", e); } - finally { - exec.shutdown(); - } } private void verifyPermsRecursively(FileSystem fs, @@ -565,7 +568,13 @@ public void testDirDownload() throws IOException, InterruptedException { destPath, rsrc); pending.put(rsrc, exec.submit(fsd)); } - + + exec.shutdown(); + while (!exec.awaitTermination(1000, TimeUnit.MILLISECONDS)); + for (Future path: pending.values()) { + Assert.assertTrue(path.isDone()); + } + try { for (Map.Entry> p : pending.entrySet()) { @@ -581,15 +590,10 @@ public void testDirDownload() throws IOException, InterruptedException { } } catch (ExecutionException e) { throw new IOException("Failed exec", e); - } finally { - exec.shutdown(); } - - - } - @Test(timeout = 1000) + @Test (timeout=10000) public void testUniqueDestinationPath() throws Exception { Configuration conf = new Configuration(); FileContext files = FileContext.getLocalFSFileContext(conf); @@ -606,20 +610,20 @@ public void testUniqueDestinationPath() throws Exception { destPath = new Path(destPath, Long.toString(uniqueNumberGenerator .incrementAndGet())); - try { - Path p = new Path(basedir, "dir" + 0 + ".jar"); - LocalResourceVisibility vis = LocalResourceVisibility.PRIVATE; - LocalResource rsrc = createJar(files, p, vis); - FSDownload fsd = - new FSDownload(files, UserGroupInformation.getCurrentUser(), conf, - destPath, rsrc); - Future rPath = singleThreadedExec.submit(fsd); - // Now FSDownload will not create a random directory to localize the - // resource. Therefore the final localizedPath for the resource should be - // destination directory (passed as an argument) + file name. - Assert.assertEquals(destPath, rPath.get().getParent()); - } finally { - singleThreadedExec.shutdown(); - } + + Path p = new Path(basedir, "dir" + 0 + ".jar"); + LocalResourceVisibility vis = LocalResourceVisibility.PRIVATE; + LocalResource rsrc = createJar(files, p, vis); + FSDownload fsd = + new FSDownload(files, UserGroupInformation.getCurrentUser(), conf, + destPath, rsrc); + Future rPath = singleThreadedExec.submit(fsd); + singleThreadedExec.shutdown(); + while (!singleThreadedExec.awaitTermination(1000, TimeUnit.MILLISECONDS)); + Assert.assertTrue(rPath.isDone()); + // Now FSDownload will not create a random directory to localize the + // resource. Therefore the final localizedPath for the resource should be + // destination directory (passed as an argument) + file name. + Assert.assertEquals(destPath, rPath.get().getParent()); } } \ No newline at end of file