コード例 #1
0
ファイル: HDFSTest.java プロジェクト: lizhiyong/flink
  @Test
  public void testHDFS() {

    Path file = new Path(hdfsURI + hdPath);
    org.apache.hadoop.fs.Path result = new org.apache.hadoop.fs.Path(hdfsURI + "/result");
    try {
      FileSystem fs = file.getFileSystem();
      Assert.assertTrue("Must be HadoopFileSystem", fs instanceof HadoopFileSystem);

      DopOneTestEnvironment.setAsContext();
      try {
        WordCount.main(new String[] {file.toString(), result.toString()});
      } catch (Throwable t) {
        t.printStackTrace();
        Assert.fail("Test failed with " + t.getMessage());
      } finally {
        DopOneTestEnvironment.unsetAsContext();
      }

      Assert.assertTrue("No result file present", hdfs.exists(result));

      // validate output:
      org.apache.hadoop.fs.FSDataInputStream inStream = hdfs.open(result);
      StringWriter writer = new StringWriter();
      IOUtils.copy(inStream, writer);
      String resultString = writer.toString();

      Assert.assertEquals("hdfs 10\n" + "hello 10\n", resultString);
      inStream.close();

    } catch (IOException e) {
      e.printStackTrace();
      Assert.fail("Error in test: " + e.getMessage());
    }
  }
コード例 #2
0
 public CompletedFuture(Path entry) {
   try {
     LocalFileSystem fs = (LocalFileSystem) entry.getFileSystem();
     result =
         entry.isAbsolute()
             ? new Path(entry.toUri().getPath())
             : new Path(fs.getWorkingDirectory(), entry);
   } catch (Exception e) {
     throw new RuntimeException(
         "DistributedCache supports only local files for Collection Environments");
   }
 }