Java Code Examples for org.apache.hadoop.hdfs.DFSClient#getLinkTarget()

The following examples show how to use org.apache.hadoop.hdfs.DFSClient#getLinkTarget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestResolveHdfsSymlink.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that attempting to resolve a non-symlink results in client
 * exception
 */
@Test
public void testLinkTargetNonSymlink() throws UnsupportedFileSystemException,
    IOException {
  FileContext fc = null;
  Path notSymlink = new Path("/notasymlink");
  try {
    fc = FileContext.getFileContext(cluster.getFileSystem().getUri());
    fc.create(notSymlink, EnumSet.of(CreateFlag.CREATE));
    DFSClient client = new DFSClient(cluster.getFileSystem().getUri(),
        cluster.getConfiguration(0));
    try {
      client.getLinkTarget(notSymlink.toString());
      fail("Expected exception for resolving non-symlink");
    } catch (IOException e) {
      GenericTestUtils.assertExceptionContains("is not a symbolic link", e);
    }
  } finally {
    if (fc != null) {
      fc.delete(notSymlink, false);
    }
  }
}
 
Example 2
Source File: TestResolveHdfsSymlink.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that attempting to resolve a non-symlink results in client
 * exception
 */
@Test
public void testLinkTargetNonSymlink() throws UnsupportedFileSystemException,
    IOException {
  FileContext fc = null;
  Path notSymlink = new Path("/notasymlink");
  try {
    fc = FileContext.getFileContext(cluster.getFileSystem().getUri());
    fc.create(notSymlink, EnumSet.of(CreateFlag.CREATE));
    DFSClient client = new DFSClient(cluster.getFileSystem().getUri(),
        cluster.getConfiguration(0));
    try {
      client.getLinkTarget(notSymlink.toString());
      fail("Expected exception for resolving non-symlink");
    } catch (IOException e) {
      GenericTestUtils.assertExceptionContains("is not a symbolic link", e);
    }
  } finally {
    if (fc != null) {
      fc.delete(notSymlink, false);
    }
  }
}
 
Example 3
Source File: TestResolveHdfsSymlink.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that attempting to resolve a non-existent-file
 */
@Test
public void testLinkTargetNonExistent() throws IOException {
  Path doesNotExist = new Path("/filethatdoesnotexist");
  DFSClient client = new DFSClient(cluster.getFileSystem().getUri(),
      cluster.getConfiguration(0));
  try {
    client.getLinkTarget(doesNotExist.toString());
    fail("Expected exception for resolving non-existent file");
  } catch (FileNotFoundException e) {
    GenericTestUtils.assertExceptionContains("File does not exist: "
        + doesNotExist.toString(), e);
  }
}
 
Example 4
Source File: TestResolveHdfsSymlink.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that attempting to resolve a non-existent-file
 */
@Test
public void testLinkTargetNonExistent() throws IOException {
  Path doesNotExist = new Path("/filethatdoesnotexist");
  DFSClient client = new DFSClient(cluster.getFileSystem().getUri(),
      cluster.getConfiguration(0));
  try {
    client.getLinkTarget(doesNotExist.toString());
    fail("Expected exception for resolving non-existent file");
  } catch (FileNotFoundException e) {
    GenericTestUtils.assertExceptionContains("File does not exist: "
        + doesNotExist.toString(), e);
  }
}