Пример #1
0
  /**
   * Test if the {@link JobConfigurationParser} can correctly extract out key-value pairs from the
   * job configuration.
   */
  @Test
  public void testJobConfigurationParsing() throws Exception {
    final FileSystem lfs = FileSystem.getLocal(new Configuration());

    final Path rootTempDir =
        new Path(System.getProperty("test.build.data", "/tmp"))
            .makeQualified(lfs.getUri(), lfs.getWorkingDirectory());

    final Path tempDir = new Path(rootTempDir, "TestJobConfigurationParser");
    lfs.delete(tempDir, true);

    // Add some configuration parameters to the conf
    JobConf jConf = new JobConf(false);
    String key = "test.data";
    String value = "hello world";
    jConf.set(key, value);

    // create the job conf file
    Path jobConfPath = new Path(tempDir.toString(), "job.xml");
    lfs.delete(jobConfPath, false);
    DataOutputStream jobConfStream = lfs.create(jobConfPath);
    jConf.writeXml(jobConfStream);
    jobConfStream.close();

    // now read the job conf file using the job configuration parser
    Properties properties = JobConfigurationParser.parse(lfs.open(jobConfPath));

    // check if the required parameter is loaded
    assertEquals(
        "Total number of extracted properties ("
            + properties.size()
            + ") doesn't match the expected size of 1 ["
            + "JobConfigurationParser]",
        1,
        properties.size());
    // check if the key is present in the extracted configuration
    assertTrue(
        "Key " + key + " is missing in the configuration extracted " + "[JobConfigurationParser]",
        properties.keySet().contains(key));
    // check if the desired property has the correct value
    assertEquals(
        "JobConfigurationParser couldn't recover the parameters" + " correctly",
        value,
        properties.get(key));

    // Test ZombieJob
    LoggedJob job = new LoggedJob();
    job.setJobProperties(properties);

    ZombieJob zjob = new ZombieJob(job, null);
    Configuration zconf = zjob.getJobConf();
    // check if the required parameter is loaded
    assertEquals("ZombieJob couldn't recover the parameters correctly", value, zconf.get(key));
  }