DistCp extends Configured implements Tool { private synchronized void cleanup() { try { if (metaFolder == null) return; jobFS.delete(metaFolder, true); metaFolder = null; } catch (IOException e) { LOG.error("Unable to cleanup meta folder: " + metaFolder, e); } } DistCp(Configuration configuration, DistCpOptions inputOptions); private  DistCp(); int run(String[] argv); Job execute(); long getJobTimeInNanos(); static void main(String argv[]); static final Random rand; }
@Test public void testCleanup() { try { clearState(); Path sourcePath = new Path("noscheme: List<Path> sources = new ArrayList<Path>(); sources.add(sourcePath); Path targetPath = new Path(TARGET_PATH) .makeQualified(cluster.getFileSystem()); DistCpOptions options = new DistCpOptions(sources, targetPath); options.setOutPutDirectory(counterOutputPath); Path stagingDir = null; boolean hadoop1 = false; try { LOG.info("Trying to get staging path using hadoop-2"); Class clusterClass = DistCp.class.getClassLoader().loadClass( "org.apache.hadoop.mapreduce.Cluster"); Method method = JobSubmissionFiles.class.getMethod("getStagingDir", clusterClass, Configuration.class); Constructor constructor = clusterClass.getConstructor(Configuration.class); stagingDir = (Path) method.invoke(null, constructor.newInstance(configuration), configuration); } catch (Exception ignored) { hadoop1= true; } if (hadoop1) { try { LOG.info("Trying to get staging path using hadoop-1"); Method method = JobSubmissionFiles.class.getMethod("getStagingDir", JobClient.class, Configuration.class); stagingDir = (Path) method.invoke(null, new JobClient(new JobConf(configuration)), configuration); } catch (Exception ignored) { } } stagingDir.getFileSystem(configuration).mkdirs(stagingDir); try { new DistCp(configuration, options).execute(); } catch (Throwable t) { Assert.assertEquals(stagingDir.getFileSystem(configuration). listStatus(stagingDir).length, 0); } } catch (Exception e) { LOG.error("Exception encountered ", e); Assert.fail("testCleanup failed " + e.getMessage()); } }