コード例 #1
0
 @Test
 public void testIssetTArray() {
   Assert.assertFalse(TempletonUtils.isset((Long[]) null));
   Assert.assertFalse(TempletonUtils.isset(new String[0]));
   String[] parts = new String("hello.world").split("\\.");
   Assert.assertTrue(TempletonUtils.isset(parts));
 }
コード例 #2
0
 @Test
 public void testHadoopFsListAsString() {
   try {
     String tmpFileName1 = "/tmp/testHadoopFsListAsString1";
     String tmpFileName2 = "/tmp/testHadoopFsListAsString2";
     File tmpFile1 = new File(tmpFileName1);
     File tmpFile2 = new File(tmpFileName2);
     tmpFile1.createNewFile();
     tmpFile2.createNewFile();
     Assert.assertTrue(TempletonUtils.hadoopFsListAsString(null, null, null) == null);
     Assert.assertTrue(TempletonUtils.hadoopFsListAsString("/tmp,/usr", null, null) == null);
     Assert.assertEquals(
         "file:" + tmpFileName1 + ",file:" + tmpFileName2,
         TempletonUtils.hadoopFsListAsString(
             tmpFileName1 + "," + tmpFileName2, new Configuration(), null));
   } catch (FileNotFoundException e) {
     Assert.fail("Couldn't find name for " + tmpFile.toURI().toString());
   } catch (Exception e) {
     // Something else is wrong
     e.printStackTrace();
   }
   try {
     TempletonUtils.hadoopFsListAsString("/scoobydoo/teddybear,joe", new Configuration(), null);
     Assert.fail("Should not have found /scoobydoo/teddybear");
   } catch (FileNotFoundException e) {
     // Should go here.
   } catch (Exception e) {
     // Something else is wrong.
     e.printStackTrace();
   }
 }
コード例 #3
0
 @Test
 public void testHadoopFsPath() {
   try {
     TempletonUtils.hadoopFsPath(null, null, null);
     TempletonUtils.hadoopFsPath(tmpFile.toURI().toString(), null, null);
     TempletonUtils.hadoopFsPath(tmpFile.toURI().toString(), new Configuration(), null);
   } catch (FileNotFoundException e) {
     Assert.fail("Couldn't find " + tmpFile.toURI().toString());
   } catch (Exception e) {
     // This is our problem -- it means the configuration was wrong.
     e.printStackTrace();
   }
   try {
     TempletonUtils.hadoopFsPath("/scoobydoo/teddybear", new Configuration(), null);
     Assert.fail("Should not have found /scoobydoo/teddybear");
   } catch (FileNotFoundException e) {
     // Should go here.
   } catch (Exception e) {
     // This is our problem -- it means the configuration was wrong.
     e.printStackTrace();
   }
   try {
     TempletonUtils.hadoopFsPath("a", new Configuration(), "teddybear");
     Assert.fail("Should not have found /user/teddybear/a");
   } catch (FileNotFoundException e) {
     Assert.assertTrue(e.getMessage().contains("/user/teddybear/a"));
   } catch (Exception e) {
     // This is our problem -- it means the configuration was wrong.
     e.printStackTrace();
     Assert.fail("Get wrong exception: " + e.getMessage());
   }
 }
コード例 #4
0
  @Test
  public void testExtractPercentComplete() {
    Assert.assertNull(TempletonUtils.extractPercentComplete("fred"));
    for (String line : CONTROLLER_LINES) {
      Assert.assertNull(TempletonUtils.extractPercentComplete(line));
    }

    String fifty =
        "2011-12-15 18:12:36,333 [main] INFO  org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher - 50% complete";
    Assert.assertEquals("50% complete", TempletonUtils.extractPercentComplete(fifty));
  }
コード例 #5
0
 @Test
 public void testDecodeArray() {
   Assert.assertTrue(TempletonUtils.encodeArray((String[]) null) == null);
   String[] tmp = new String[3];
   tmp[0] = "fred";
   tmp[1] = null;
   tmp[2] = "peter,lisa,, barney";
   String[] tmp2 = TempletonUtils.decodeArray(TempletonUtils.encodeArray(tmp));
   try {
     for (int i = 0; i < tmp.length; i++) {
       Assert.assertEquals((String) tmp[i], (String) tmp2[i]);
     }
   } catch (Exception e) {
     Assert.fail("Arrays were not equal" + e.getMessage());
   }
 }
コード例 #6
0
 @Test
 public void testEncodeArray() {
   Assert.assertEquals(null, TempletonUtils.encodeArray((String[]) null));
   String[] tmp = new String[0];
   Assert.assertTrue(TempletonUtils.encodeArray(new String[0]).length() == 0);
   tmp = new String[3];
   tmp[0] = "fred";
   tmp[1] = null;
   tmp[2] = "peter,lisa,, barney";
   Assert.assertEquals(
       "fred,,peter"
           + StringUtils.ESCAPE_CHAR
           + ",lisa"
           + StringUtils.ESCAPE_CHAR
           + ","
           + StringUtils.ESCAPE_CHAR
           + ", barney",
       TempletonUtils.encodeArray(tmp));
 }
コード例 #7
0
  @Test
  public void testConstructingUserHomeDirectory() throws Exception {
    String[] sources =
        new String[] {
          "output+",
          "/user/hadoop/output",
          "hdfs://container",
          "hdfs://container/",
          "hdfs://container/path",
          "output#link",
          "hdfs://cointaner/output#link",
          "hdfs://container@acc/test"
        };
    String[] expectedResults =
        new String[] {
          "/user/webhcat/output+",
          "/user/hadoop/output",
          "hdfs://container/user/webhcat",
          "hdfs://container/",
          "hdfs://container/path",
          "/user/webhcat/output#link",
          "hdfs://cointaner/output#link",
          "hdfs://container@acc/test"
        };
    for (int i = 0; i < sources.length; i++) {
      String source = sources[i];
      String expectedResult = expectedResults[i];
      String result = TempletonUtils.addUserHomeDirectoryIfApplicable(source, "webhcat");
      Assert.assertEquals(result, expectedResult);
    }

    String badUri = "c:\\some\\path";
    try {
      TempletonUtils.addUserHomeDirectoryIfApplicable(badUri, "webhcat");
      Assert.fail("addUserHomeDirectoryIfApplicable should fail for bad URI: " + badUri);
    } catch (URISyntaxException ex) {
    }
  }
コード例 #8
0
 @Test
 public void testIssetString() {
   Assert.assertFalse(TempletonUtils.isset((String) null));
   Assert.assertFalse(TempletonUtils.isset(""));
   Assert.assertTrue(TempletonUtils.isset("hello"));
 }