List of usage examples for org.apache.hadoop.fs Path Path
public Path(URI aUri)
From source file:alluxio.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);/* w ww . ja va 2 s . c om*/ Assert.assertTrue(sTFS.rename(fileA, finalDst)); Assert.assertFalse(sTFS.exists(fileA)); Assert.assertTrue(sTFS.exists(finalDst)); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "fileA"))); Assert.assertTrue(sUfs.exists(PathUtils.concatPath(sUfsRoot, "fileAfileA"))); cleanup(sTFS); Assert.assertFalse(sTFS.exists(finalDst)); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "fileAfileA"))); }
From source file:alluxio.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 a v a2s. com 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.exists(PathUtils.concatPath(sUfsRoot, "dirA"))); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "dirA", "fileA"))); Assert.assertTrue(sUfs.exists(PathUtils.concatPath(sUfsRoot, "dirB"))); Assert.assertTrue(sUfs.exists(PathUtils.concatPath(sUfsRoot, "dirB", "fileA"))); cleanup(sTFS); Assert.assertFalse(sTFS.exists(dirB)); Assert.assertFalse(sTFS.exists(finalDst)); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "dirB"))); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "dirB", "fileA"))); }
From source file:alluxio.hadoop.FileSystemRenameIntegrationTest.java
License:Apache License
@Test @Ignore/*from ww w . jav 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. o.sync(); 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); }
From source file:alluxio.hadoop.FileSystemRenameIntegrationTest.java
License:Apache License
@Test public void errorRenameTest1() throws Exception { // Rename /dirA to /dirA/dirB should fail Path dirA = new Path("/dirA"); Path finalDst = new Path("/dirA/dirB"); sTFS.mkdirs(dirA);/*from w ww . jav a 2 s . c o m*/ Assert.assertFalse(sTFS.rename(dirA, finalDst)); Assert.assertFalse(sTFS.exists(finalDst)); Assert.assertTrue(sTFS.exists(dirA)); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "dirA", "dirB"))); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "dirB"))); cleanup(sTFS); Assert.assertFalse(sTFS.exists(dirA)); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "dirB"))); }
From source file:alluxio.hadoop.FileSystemRenameIntegrationTest.java
License:Apache License
@Test public void errorRenameTest2() throws Exception { // Rename /fileA to /fileB should fail if /fileB exists Path fileA = new Path("/fileA"); Path fileB = new Path("/fileB"); create(sTFS, fileA);//from w ww . j a va 2s .c o m create(sTFS, fileB); Assert.assertFalse(sTFS.rename(fileA, fileB)); Assert.assertTrue(sTFS.exists(fileA)); Assert.assertTrue(sTFS.exists(fileB)); Assert.assertTrue(sUfs.exists(PathUtils.concatPath(sUfsRoot, "fileA"))); Assert.assertTrue(sUfs.exists(PathUtils.concatPath(sUfsRoot, "fileB"))); cleanup(sTFS); Assert.assertFalse(sTFS.exists(fileA)); Assert.assertFalse(sTFS.exists(fileB)); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "fileA"))); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "fileB"))); }
From source file:alluxio.hadoop.FileSystemRenameIntegrationTest.java
License:Apache License
@Test public void errorRenameTest3() throws Exception { // Rename /fileA to /dirA/fileA should fail if /dirA/fileA exists Path fileA = new Path("/fileA"); Path dirA = new Path("/dirA"); Path finalDst = new Path("/dirA/fileA"); create(sTFS, fileA);//from ww w. j a v a 2 s . co m create(sTFS, finalDst); Assert.assertFalse(sTFS.rename(fileA, dirA)); Assert.assertTrue(sTFS.exists(fileA)); Assert.assertTrue(sTFS.exists(dirA)); Assert.assertTrue(sTFS.exists(finalDst)); Assert.assertTrue(sUfs.exists(PathUtils.concatPath(sUfsRoot, "fileA"))); Assert.assertTrue(sUfs.exists(PathUtils.concatPath(sUfsRoot, "dirA"))); Assert.assertTrue(sUfs.exists(PathUtils.concatPath(sUfsRoot, "dirA", "fileA"))); cleanup(sTFS); Assert.assertFalse(sTFS.exists(fileA)); Assert.assertFalse(sTFS.exists(dirA)); Assert.assertFalse(sTFS.exists(finalDst)); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "fileA"))); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "dirA"))); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "dirA", "fileA"))); }
From source file:alluxio.hadoop.FileSystemRenameIntegrationTest.java
License:Apache License
@Test public void errorRenameTest4() throws Exception { // Rename /fileA to an nonexistent path should fail Path fileA = new Path("/fileA"); Path nonexistentPath = new Path("/doesNotExist/fileA"); create(sTFS, fileA);// w w w .j a v a 2 s. c o m Assert.assertFalse(sTFS.rename(fileA, nonexistentPath)); Assert.assertTrue(sTFS.exists(fileA)); Assert.assertTrue(sUfs.exists(PathUtils.concatPath(sUfsRoot, "fileA"))); cleanup(sTFS); Assert.assertFalse(sTFS.exists(fileA)); Assert.assertFalse(sUfs.exists(PathUtils.concatPath(sUfsRoot, "fileA"))); }
From source file:alluxio.hadoop.HadoopUtilsTest.java
License:Apache License
/** * Test for the {@link HadoopUtils#getPathWithoutScheme(Path)} method. *//*from w w w .j a v a 2s . c o m*/ @Test public void testGetPathWithoutSchema() { final Path path = new Path("/foo/bar/baz"); final String output = HadoopUtils.getPathWithoutScheme(path); Assert.assertEquals("/foo/bar/baz", output); }
From source file:alluxio.hadoop.HadoopUtilsTest.java
License:Apache License
/** * Test for the {@link HadoopUtils#getPathWithoutScheme(Path)} method that contains the schema. *//*from w w w . j a va 2 s . c om*/ @Test public void testGetPathWithoutSchemaThatContainsSchema() { final Path path = new Path("file:///foo/bar/baz"); final String output = HadoopUtils.getPathWithoutScheme(path); Assert.assertEquals("/foo/bar/baz", output); }
From source file:alluxio.hadoop.HadoopUtilsTest.java
License:Apache License
/** * This test doesn't work the way you might expect. * * If you take the URI.create("hdfs://localhost:1234/foo/bar/baz?please=dont&show=up").getPath * it will return /foo/bar/baz. If you go through Hadoop's Path using {@link Path#Path(String)} * then Hadoop injects the query params into the path, so when you call toURI it gives a different * response.//from w w w . ja v a 2 s .co m */ @Test public void testGetPathWithoutSchemaFromHDFS() { final Path path = new Path("hdfs://localhost:1234/foo/bar/baz?please=dont&show=up"); final String output = HadoopUtils.getPathWithoutScheme(path); Assert.assertFalse("/foo/bar/baz".equals(output)); }