Пример #1
0
  /** 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);
  }