private static <T extends DeepCompare> void jsonFileMatchesGold( Configuration conf, Path result, Path gold, Class<? extends T> clazz, String fileDescription) throws IOException { JsonObjectMapperParser<T> goldParser = new JsonObjectMapperParser<T>(gold, clazz, conf); JsonObjectMapperParser<T> resultParser = new JsonObjectMapperParser<T>(result, clazz, conf); try { while (true) { DeepCompare goldJob = goldParser.getNext(); DeepCompare resultJob = resultParser.getNext(); if ((goldJob == null) || (resultJob == null)) { assertTrue(goldJob == resultJob); break; } try { resultJob.deepCompare(goldJob, new TreePath(null, "<root>")); } catch (DeepInequalityException e) { String error = e.path.toString(); assertFalse(fileDescription + " mismatches: " + error, true); } } } finally { IOUtils.cleanup(null, goldParser, resultParser); } }
/** Testing {@link ResourceUsageMetrics} using {@link HadoopLogsAnalyzer}. */ @Test @SuppressWarnings("deprecation") public void testResourceUsageMetricsWithHadoopLogsAnalyzer() throws IOException { Configuration conf = new Configuration(); // get the input trace file Path rootInputDir = new Path(System.getProperty("test.tools.input.dir", "")); Path rootInputSubFolder = new Path(rootInputDir, "rumen/small-trace-test"); Path traceFile = new Path(rootInputSubFolder, "v20-resource-usage-log.gz"); FileSystem lfs = FileSystem.getLocal(conf); // define the root test directory Path rootTempDir = new Path(System.getProperty("test.build.data", "/tmp")); // define output directory Path outputDir = new Path(rootTempDir, "testResourceUsageMetricsWithHadoopLogsAnalyzer"); lfs.delete(outputDir, true); lfs.deleteOnExit(outputDir); // run HadoopLogsAnalyzer HadoopLogsAnalyzer analyzer = new HadoopLogsAnalyzer(); analyzer.setConf(conf); Path traceOutput = new Path(outputDir, "trace.json"); analyzer.run( new String[] { "-write-job-trace", traceOutput.toString(), "-v1", traceFile.toString() }); // test HadoopLogsAnalyzer's output w.r.t ResourceUsageMetrics // get the logged job JsonObjectMapperParser<LoggedJob> traceParser = new JsonObjectMapperParser<LoggedJob>(traceOutput, LoggedJob.class, conf); // get the logged job from the output trace file LoggedJob job = traceParser.getNext(); LoggedTaskAttempt attempt = job.getMapTasks().get(0).getAttempts().get(0); ResourceUsageMetrics metrics = attempt.getResourceUsageMetrics(); // test via deepCompare() testResourceUsageMetricViaDeepCompare(metrics, 200, 100, 75, 50, true); }