ClientDistributedCacheManager.determineTimestamps(subConf);
ClientDistributedCacheManager.determineCacheVisibilities(subConf);
// ****** End of imitating JobClient code
// ****** Imitate TaskRunner code.
TaskDistributedCacheManager handle =
manager.newTaskDistributedCacheManager(subConf);
assertNull(null, DistributedCache.getLocalCacheFiles(subConf));
File workDir = new File(new Path(TEST_ROOT_DIR, "workdir").toString());
handle.setup(localDirAllocator, workDir, TaskTracker
.getPrivateDistributedCacheDir(userName),
TaskTracker.getPublicDistributedCacheDir());
// ****** End of imitating TaskRunner code
Path[] localCacheFiles = DistributedCache.getLocalCacheFiles(subConf);
assertNotNull(null, localCacheFiles);
assertEquals(1, localCacheFiles.length);
Path cachedFirstFile = localCacheFiles[0];
assertFileLengthEquals(firstCacheFile, cachedFirstFile);
assertFalse("Paths should be different.",
firstCacheFile.equals(cachedFirstFile));
// release
handle.release();
// change the file timestamp
FileSystem fs = FileSystem.get(myConf);
((FakeFileSystem)fs).advanceClock(1);
// running a task of the same job
Throwable th = null;
try {
handle.setup(localDirAllocator, workDir, TaskTracker
.getPrivateDistributedCacheDir(userName), TaskTracker.getPublicDistributedCacheDir());
} catch (IOException ie) {
th = ie;
}
assertNotNull("Throwable is null", th);
assertTrue("Exception message does not match",
th.getMessage().contains("has changed on HDFS since job started"));
// release
handle.release();
// running a task of the same job on another TaskTracker which has never
// initialized the cache
TrackerDistributedCacheManager manager2 =
new TrackerDistributedCacheManager(myConf, taskController);
TaskDistributedCacheManager handle2 =
manager2.newTaskDistributedCacheManager(subConf);
File workDir2 = new File(new Path(TEST_ROOT_DIR, "workdir2").toString());
th = null;
try {
handle2.setup(localDirAllocator, workDir2, TaskTracker
.getPrivateDistributedCacheDir(userName),
TaskTracker.getPublicDistributedCacheDir());
} catch (IOException ie) {
th = ie;
}