|
@@ -35,6 +35,7 @@ import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.Future;
|
|
|
+import java.util.concurrent.atomic.AtomicLong;
|
|
|
import java.util.jar.JarOutputStream;
|
|
|
import java.util.jar.Manifest;
|
|
|
|
|
@@ -66,6 +67,8 @@ import org.junit.Test;
|
|
|
public class TestFSDownload {
|
|
|
|
|
|
private static final Log LOG = LogFactory.getLog(TestFSDownload.class);
|
|
|
+ private static AtomicLong uniqueNumberGenerator =
|
|
|
+ new AtomicLong(System.currentTimeMillis());
|
|
|
|
|
|
@AfterClass
|
|
|
public static void deleteTestDir() throws IOException {
|
|
@@ -267,9 +270,11 @@ public class TestFSDownload {
|
|
|
rsrcVis.put(rsrc, vis);
|
|
|
Path destPath = dirs.getLocalPathForWrite(
|
|
|
basedir.toString(), size, conf);
|
|
|
+ destPath = new Path (destPath,
|
|
|
+ Long.toString(uniqueNumberGenerator.incrementAndGet()));
|
|
|
FSDownload fsd =
|
|
|
new FSDownload(files, UserGroupInformation.getCurrentUser(), conf,
|
|
|
- destPath, rsrc, new Random(sharedSeed));
|
|
|
+ destPath, rsrc);
|
|
|
pending.put(rsrc, exec.submit(fsd));
|
|
|
|
|
|
try {
|
|
@@ -320,9 +325,11 @@ public class TestFSDownload {
|
|
|
rsrcVis.put(rsrc, vis);
|
|
|
Path destPath = dirs.getLocalPathForWrite(
|
|
|
basedir.toString(), sizes[i], conf);
|
|
|
+ destPath = new Path (destPath,
|
|
|
+ Long.toString(uniqueNumberGenerator.incrementAndGet()));
|
|
|
FSDownload fsd =
|
|
|
new FSDownload(files, UserGroupInformation.getCurrentUser(), conf,
|
|
|
- destPath, rsrc, new Random(sharedSeed));
|
|
|
+ destPath, rsrc);
|
|
|
pending.put(rsrc, exec.submit(fsd));
|
|
|
}
|
|
|
|
|
@@ -380,9 +387,10 @@ public class TestFSDownload {
|
|
|
Path p = new Path(basedir, "" + 1);
|
|
|
LocalResource rsrc = createTarFile(files, p, size, rand, vis);
|
|
|
Path destPath = dirs.getLocalPathForWrite(basedir.toString(), size, conf);
|
|
|
+ destPath = new Path (destPath,
|
|
|
+ Long.toString(uniqueNumberGenerator.incrementAndGet()));
|
|
|
FSDownload fsd = new FSDownload(files,
|
|
|
- UserGroupInformation.getCurrentUser(), conf, destPath, rsrc,
|
|
|
- new Random(sharedSeed));
|
|
|
+ UserGroupInformation.getCurrentUser(), conf, destPath, rsrc);
|
|
|
pending.put(rsrc, exec.submit(fsd));
|
|
|
|
|
|
try {
|
|
@@ -437,9 +445,10 @@ public class TestFSDownload {
|
|
|
LocalResource rsrcjar = createJarFile(files, p, size, rand, vis);
|
|
|
rsrcjar.setType(LocalResourceType.PATTERN);
|
|
|
Path destPathjar = dirs.getLocalPathForWrite(basedir.toString(), size, conf);
|
|
|
+ destPathjar = new Path (destPathjar,
|
|
|
+ Long.toString(uniqueNumberGenerator.incrementAndGet()));
|
|
|
FSDownload fsdjar = new FSDownload(files,
|
|
|
- UserGroupInformation.getCurrentUser(), conf, destPathjar, rsrcjar,
|
|
|
- new Random(sharedSeed));
|
|
|
+ UserGroupInformation.getCurrentUser(), conf, destPathjar, rsrcjar);
|
|
|
pending.put(rsrcjar, exec.submit(fsdjar));
|
|
|
|
|
|
try {
|
|
@@ -493,9 +502,10 @@ public class TestFSDownload {
|
|
|
Path p = new Path(basedir, "" + 1);
|
|
|
LocalResource rsrczip = createZipFile(files, p, size, rand, vis);
|
|
|
Path destPathjar = dirs.getLocalPathForWrite(basedir.toString(), size, conf);
|
|
|
+ destPathjar = new Path (destPathjar,
|
|
|
+ Long.toString(uniqueNumberGenerator.incrementAndGet()));
|
|
|
FSDownload fsdzip = new FSDownload(files,
|
|
|
- UserGroupInformation.getCurrentUser(), conf, destPathjar, rsrczip,
|
|
|
- new Random(sharedSeed));
|
|
|
+ UserGroupInformation.getCurrentUser(), conf, destPathjar, rsrczip);
|
|
|
pending.put(rsrczip, exec.submit(fsdzip));
|
|
|
|
|
|
try {
|
|
@@ -586,9 +596,11 @@ public class TestFSDownload {
|
|
|
rsrcVis.put(rsrc, vis);
|
|
|
Path destPath = dirs.getLocalPathForWrite(
|
|
|
basedir.toString(), conf);
|
|
|
+ destPath = new Path (destPath,
|
|
|
+ Long.toString(uniqueNumberGenerator.incrementAndGet()));
|
|
|
FSDownload fsd =
|
|
|
new FSDownload(files, UserGroupInformation.getCurrentUser(), conf,
|
|
|
- destPath, rsrc, new Random(sharedSeed));
|
|
|
+ destPath, rsrc);
|
|
|
pending.put(rsrc, exec.submit(fsd));
|
|
|
}
|
|
|
|
|
@@ -614,4 +626,38 @@ public class TestFSDownload {
|
|
|
|
|
|
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ @Test(timeout = 1000)
|
|
|
+ public void testUniqueDestinationPath() throws Exception {
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ FileContext files = FileContext.getLocalFSFileContext(conf);
|
|
|
+ final Path basedir = files.makeQualified(new Path("target",
|
|
|
+ TestFSDownload.class.getSimpleName()));
|
|
|
+ files.mkdir(basedir, null, true);
|
|
|
+ conf.setStrings(TestFSDownload.class.getName(), basedir.toString());
|
|
|
+
|
|
|
+ ExecutorService singleThreadedExec = Executors.newSingleThreadExecutor();
|
|
|
+
|
|
|
+ LocalDirAllocator dirs =
|
|
|
+ new LocalDirAllocator(TestFSDownload.class.getName());
|
|
|
+ Path destPath = dirs.getLocalPathForWrite(basedir.toString(), conf);
|
|
|
+ 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<Path> 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|