Example usage for org.apache.hadoop.fs Path Path

List of usage examples for org.apache.hadoop.fs Path Path

Introduction

In this page you can find the example usage for org.apache.hadoop.fs Path Path.

Prototype

public Path(URI aUri) 

Source Link

Document

Construct a path from a URI

Usage

From source file:alluxio.client.hadoop.FileSystemAclIntegrationTest.java

License:Apache License

@Test
public void objectStoreSetOwner() throws Exception {
    Assume.assumeTrue(sUfs.isObjectStorage());

    Path fileA = new Path("/objectfileA");
    final String newOwner = "new-user1";
    final String newGroup = "new-group1";
    create(sTFS, fileA);/*w  w  w  . ja va  2 s . co m*/

    // Set owner to Alluxio files that are persisted in UFS will NOT propagate to underlying object.
    sTFS.setOwner(fileA, newOwner, newGroup);
    UfsStatus ufsStatus = sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileA));
    Assert.assertNotEquals("", ufsStatus.getOwner());
    Assert.assertNotEquals("", ufsStatus.getGroup());
}

From source file:alluxio.client.hadoop.FileSystemBlockLocationIntegrationTest.java

License:Apache License

/**
 * Test {@code BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len)}.
 * Test the different situations of different start and len.
 *///from  w  w  w .j  av  a2s  .c om
@Test
public void basicBlockLocation() throws Exception {
    FileStatus fStatus = sTFS.getFileStatus(new Path("/testFile1"));

    // block0.offset = start < start+len < block1.offset
    long start = 0;
    long len = BLOCK_SIZE - 1;
    Assert.assertEquals(1, sTFS.getFileBlockLocations(fStatus, start, len).length);

    // block0.offset < start < start+len < block1.offset
    start = 1;
    len = BLOCK_SIZE - 2;
    Assert.assertEquals(1, sTFS.getFileBlockLocations(fStatus, start, len).length);

    // block0.offset < start = start+len < block1.offset
    start = 1;
    len = 0;
    Assert.assertEquals(1, sTFS.getFileBlockLocations(fStatus, start, len).length);

    // block0.offset = start < start+len = block1.offset
    start = 0;
    len = BLOCK_SIZE;
    Assert.assertEquals(2, sTFS.getFileBlockLocations(fStatus, start, len).length);

    // block0.offset = start < block1.offset < start+len < block2.offset
    start = 0;
    len = BLOCK_SIZE + 1;
    Assert.assertEquals(2, sTFS.getFileBlockLocations(fStatus, start, len).length);

    // block0.offset < start < block1.offset < start+len < block2.offset
    start = 1;
    len = BLOCK_SIZE;
    Assert.assertEquals(2, sTFS.getFileBlockLocations(fStatus, start, len).length);

    // block0.offset = start < start+len = block2.offset
    start = 0;
    len = BLOCK_SIZE * 2;
    Assert.assertEquals(3, sTFS.getFileBlockLocations(fStatus, start, len).length);

    // block0.offset = start < start+len = file.len
    start = 0;
    len = FILE_LEN;
    Assert.assertEquals(3, sTFS.getFileBlockLocations(fStatus, start, len).length);

    // file.len < start < start+len
    start = FILE_LEN + 1;
    len = 1;
    Assert.assertEquals(0, sTFS.getFileBlockLocations(fStatus, start, len).length);
}

From source file:alluxio.client.hadoop.FileSystemIntegrationTest.java

License:Apache License

@Test
public void closeFileSystem() throws Exception {
    Path file = new Path("/createfile");
    FsPermission permission = FsPermission.createImmutable((short) 0666);
    FSDataOutputStream o = sTFS.create(file, permission, false /* ignored */, 10 /* ignored */,
            (short) 1 /* ignored */, 512 /* ignored */, null /* ignored */);
    o.writeBytes("Test Bytes");
    o.close();/*from   w  w  w  .j av  a  2 s .c  o  m*/
    // with mark of delete-on-exit, the close method will try to delete it
    sTFS.deleteOnExit(file);
    sTFS.close();
}

From source file:alluxio.client.hadoop.FileSystemRenameIntegrationTest.java

License:Apache License

@Test
public void basicRenameTest1() throws Exception {
    // Rename /fileA to /fileB
    Path fileA = new Path("/fileA");
    Path fileB = new Path("/fileB");

    create(sTFS, fileA);/*from   w  w  w  .  java 2s  .c o m*/

    Assert.assertTrue(sTFS.rename(fileA, fileB));

    Assert.assertFalse(sTFS.exists(fileA));
    Assert.assertTrue(sTFS.exists(fileB));
    Assert.assertFalse(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "fileA")));
    Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "fileB")));

    cleanup(sTFS);

    Assert.assertFalse(sTFS.exists(fileB));
    Assert.assertFalse(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "fileB")));
}

From source file:alluxio.client.hadoop.FileSystemRenameIntegrationTest.java

License:Apache License

@Test
public void basicRenameTest2() throws Exception {
    // Rename /fileA to /dirA/fileA
    Path fileA = new Path("/fileA");
    Path dirA = new Path("/dirA");
    Path finalDst = new Path("/dirA/fileA");

    create(sTFS, fileA);/*from w  ww.j  a  v  a  2 s  .com*/
    sTFS.mkdirs(dirA);

    Assert.assertTrue(sTFS.rename(fileA, finalDst));

    Assert.assertFalse(sTFS.exists(fileA));
    Assert.assertTrue(sTFS.exists(dirA));
    Assert.assertTrue(sTFS.exists(finalDst));
    Assert.assertFalse(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "fileA")));
    Assert.assertTrue(sUfs.isDirectory(PathUtils.concatPath(sUfsRoot, "dirA")));
    Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "dirA", "fileA")));

    cleanup(sTFS);

    Assert.assertFalse(sUfs.isDirectory(PathUtils.concatPath(sUfsRoot, "dirA")));
}

From source file:alluxio.client.hadoop.FileSystemRenameIntegrationTest.java

License:Apache License

@Test
public void basicRenameTest3() throws Exception {
    // Rename /fileA to /dirA/fileA without specifying the full path
    Path fileA = new Path("/fileA");
    Path dirA = new Path("/dirA");
    Path finalDst = new Path("/dirA/fileA");

    create(sTFS, fileA);//  w w w  .ja va  2s.  c  o  m
    sTFS.mkdirs(dirA);

    Assert.assertTrue(sTFS.rename(fileA, dirA));

    Assert.assertFalse(sTFS.exists(fileA));
    Assert.assertTrue(sTFS.exists(dirA));
    Assert.assertTrue(sTFS.exists(finalDst));
    Assert.assertFalse(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "fileA")));
    Assert.assertTrue(sUfs.isDirectory(PathUtils.concatPath(sUfsRoot, "dirA")));
    Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "dirA", "fileA")));

    cleanup(sTFS);

    Assert.assertFalse(sUfs.isDirectory(PathUtils.concatPath(sUfsRoot, "dirA")));
}

From source file:alluxio.client.hadoop.FileSystemRenameIntegrationTest.java

License:Apache License

@Test
public void basicRenameTest4() throws Exception {
    // Rename /fileA to /fileA
    Path fileA = new Path("/fileA");

    create(sTFS, fileA);//from w  ww .  j  av a2  s. c o  m

    Assert.assertTrue(sTFS.rename(fileA, fileA));

    Assert.assertTrue(sTFS.exists(fileA));
    Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "fileA")));

    cleanup(sTFS);

    Assert.assertFalse(sTFS.exists(fileA));
    Assert.assertFalse(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "fileA")));
}

From source file:alluxio.client.hadoop.FileSystemRenameIntegrationTest.java

License:Apache License

@Test
public void basicRenameTest5() throws Exception {
    // Rename /fileA to /fileAfileA
    Path fileA = new Path("/fileA");
    Path finalDst = new Path("/fileAfileA");

    create(sTFS, fileA);/* ww  w  . jav a2  s .  c o m*/

    Assert.assertTrue(sTFS.rename(fileA, finalDst));

    Assert.assertFalse(sTFS.exists(fileA));
    Assert.assertTrue(sTFS.exists(finalDst));
    Assert.assertFalse(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "fileA")));
    Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "fileAfileA")));

    cleanup(sTFS);

    Assert.assertFalse(sTFS.exists(finalDst));
    Assert.assertFalse(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "fileAfileA")));
}

From source file:alluxio.client.hadoop.FileSystemRenameIntegrationTest.java

License:Apache License

@Test
public void basicRenameTest6() throws Exception {
    // Rename /dirA to /dirB, /dirA/fileA should become /dirB/fileA
    Path dirA = new Path("/dirA");
    Path dirB = new Path("/dirB");
    Path fileA = new Path("/dirA/fileA");
    Path finalDst = new Path("/dirB/fileA");

    sTFS.mkdirs(dirA);/*from  w w  w.j  av a  2s  .c o  m*/
    create(sTFS, fileA);

    Assert.assertTrue(sTFS.rename(dirA, dirB));

    Assert.assertFalse(sTFS.exists(dirA));
    Assert.assertFalse(sTFS.exists(fileA));
    Assert.assertTrue(sTFS.exists(dirB));
    Assert.assertTrue(sTFS.exists(finalDst));
    Assert.assertFalse(sUfs.isDirectory(PathUtils.concatPath(sUfsRoot, "dirA")));
    Assert.assertFalse(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "dirA", "fileA")));
    Assert.assertTrue(sUfs.isDirectory(PathUtils.concatPath(sUfsRoot, "dirB")));
    Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "dirB", "fileA")));

    cleanup(sTFS);

    Assert.assertFalse(sTFS.exists(dirB));
    Assert.assertFalse(sTFS.exists(finalDst));
    Assert.assertFalse(sUfs.isDirectory(PathUtils.concatPath(sUfsRoot, "dirB")));
    Assert.assertFalse(sUfs.isFile(PathUtils.concatPath(sUfsRoot, "dirB", "fileA")));
}

From source file:alluxio.client.hadoop.FileSystemRenameIntegrationTest.java

License:Apache License

@Test
@Ignore//from  ww  w.j  a v a  2  s .  c o m
// TODO(jiri): The test logic below does not work in the presence of transparent naming.
// The current implementation renames files on UFS if they are marked as persisted. They are
// marked as persisted when they are closed. Thus, if the Alluxio path of the file being
// written to changes before it is closed, renaming the temporary underlying file to its final
// destination fails.
public void basicRenameTest7() throws Exception {
    // Rename /dirA to /dirB, /dirA/fileA should become /dirB/fileA even if it was not closed

    Path dirA = new Path("/dirA");
    Path dirB = new Path("/dirB");
    Path fileA = new Path("/dirA/fileA");
    Path finalDst = new Path("/dirB/fileA");

    sTFS.mkdirs(dirA);
    FSDataOutputStream o = sTFS.create(fileA);
    o.writeBytes("Test Bytes");
    // Due to Hadoop 1 support we stick with the deprecated version. If we drop support for it
    // FSDataOutputStream.hflush will be the new one.
    //#ifdef HADOOP1
    o.sync();
    //#else
    o.hflush();
    //#endif

    Assert.assertTrue(sTFS.rename(dirA, dirB));

    Assert.assertFalse(sTFS.exists(dirA));
    Assert.assertFalse(sTFS.exists(fileA));
    Assert.assertTrue(sTFS.exists(dirB));
    Assert.assertTrue(sTFS.exists(finalDst));

    o.close();

    Assert.assertFalse(sTFS.exists(dirA));
    Assert.assertFalse(sTFS.exists(fileA));
    Assert.assertTrue(sTFS.exists(dirB));
    Assert.assertTrue(sTFS.exists(finalDst));
    cleanup(sTFS);
}