Esempio n. 1
0
 /**
  * Tests adding jars one-by-one to a job's configuration.
  *
  * @throws IOException If there is a problem adding the jars.
  */
 @Test
 public void testAddJar() throws IOException {
   // Add each valid jar path to the distributed cache configuration, and verify each was
   // added correctly in turn.
   for (int i = 0; i < testFilePaths.length; i++) {
     DistCache.addJarToDistributedCache(testConf, testFilePaths[i]);
     assertEquals(
         "tmpjars configuration var does not contain expected value.",
         StringUtils.join(testFileQualifiedPaths, ",", 0, i + 1),
         testConf.get("tmpjars"));
   }
 }
Esempio n. 2
0
  /**
   * Tests that adding a directory of jars to the configuration works as expected. .jar files under
   * the added directory should be added to the configuration, and all other files should be
   * skipped.
   *
   * @throws IOException If there is a problem adding the jar directory to the configuration.
   */
  @Test
  public void testAddJarDirectory() throws IOException {
    DistCache.addJarDirToDistributedCache(testConf, testFolder.getRoot().getCanonicalPath());
    // Throw the added jar paths in a set to detect duplicates.
    String[] splitJarPaths = StringUtils.split(testConf.get("tmpjars"), ",");
    Set<String> addedJarPaths = new HashSet<String>();
    for (String path : splitJarPaths) {
      addedJarPaths.add(path);
    }
    assertEquals(
        "Incorrect number of jar paths added.", testFilePaths.length, addedJarPaths.size());

    // Ensure all expected paths were added.
    for (int i = 0; i < testFileQualifiedPaths.length; i++) {
      assertTrue(
          "Expected jar path missing from jar paths added to tmpjars: " + testFileQualifiedPaths[i],
          addedJarPaths.contains(testFileQualifiedPaths[i]));
    }
  }
Esempio n. 3
0
 /**
  * Tests that attempting to add the path to a jar that does not exist to the configuration throws
  * an exception.
  *
  * @throws IOException If the added jar path does not exist. This exception is expected.
  */
 @Test(expected = IOException.class)
 public void testAddJarThatDoesntExist() throws IOException {
   DistCache.addJarToDistributedCache(testConf, "/garbage/doesntexist.jar");
 }
Esempio n. 4
0
 /**
  * Tests that adding a jar directory that is not a directory to the configuration throws an
  * exception.
  *
  * @throws IOException If the added jar directory is not a directory. This exception is expected.
  */
 @Test(expected = IOException.class)
 public void testAddJarDirectoryNotDirectory() throws IOException {
   DistCache.addJarDirToDistributedCache(testConf, testFilePaths[0]);
 }