You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2017/04/21 07:55:35 UTC

[1/2] flink git commit: [FLINK-6103] [core] Fix conditions and add tests for rename() on LocalFileSystem

Repository: flink
Updated Branches:
  refs/heads/master a0249d993 -> f9eac3afd


[FLINK-6103] [core] Fix conditions and add tests for rename() on LocalFileSystem


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/f9eac3af
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/f9eac3af
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/f9eac3af

Branch: refs/heads/master
Commit: f9eac3afd4c613df8bc577c080e71230d98df87a
Parents: a4f9a54
Author: Stephan Ewen <se...@apache.org>
Authored: Thu Apr 20 16:00:22 2017 +0200
Committer: Stephan Ewen <se...@apache.org>
Committed: Fri Apr 21 09:55:11 2017 +0200

----------------------------------------------------------------------
 .../flink/core/fs/local/LocalFileSystem.java    |  17 +-
 .../core/fs/local/LocalFileSystemTest.java      | 260 +++++++++++--------
 2 files changed, 167 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/f9eac3af/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java b/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java
index 0a168de..0e3e9f3 100644
--- a/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java
+++ b/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java
@@ -43,9 +43,11 @@ import java.io.IOException;
 import java.net.InetAddress;
 import java.net.URI;
 import java.net.UnknownHostException;
+import java.nio.file.AccessDeniedException;
 import java.nio.file.DirectoryNotEmptyException;
 import java.nio.file.FileAlreadyExistsException;
 import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
 import java.nio.file.StandardCopyOption;
 
 import static org.apache.flink.util.Preconditions.checkNotNull;
@@ -266,16 +268,19 @@ public class LocalFileSystem extends FileSystem {
 	public boolean rename(final Path src, final Path dst) throws IOException {
 		final File srcFile = pathToFile(src);
 		final File dstFile = pathToFile(dst);
-		//Files.move fails if the destination directory doesn't exist
-		if(dstFile.getParentFile()!= null && !dstFile.getParentFile().exists()){
-			dstFile.getParentFile().mkdirs();
-		}
+
+		final File dstParent = dstFile.getParentFile();
+
+		// Files.move fails if the destination directory doesn't exist
+		//noinspection ResultOfMethodCallIgnored -- we don't care if the directory existed or was created
+		dstParent.mkdirs();
+
 		try {
 			Files.move(srcFile.toPath(), dstFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
 			return true;
 		}
-		catch (FileAlreadyExistsException | DirectoryNotEmptyException | SecurityException ex) {
-			//Catch the errors that are regular "move failed" exceptions and return false
+		catch (NoSuchFileException | AccessDeniedException | DirectoryNotEmptyException | SecurityException ex) {
+			// catch the errors that are regular "move failed" exceptions and return false
 			return false;
 		}
 	}

http://git-wip-us.apache.org/repos/asf/flink/blob/f9eac3af/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java b/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
index 7b7d599..2312ee9 100644
--- a/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
+++ b/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
@@ -22,7 +22,6 @@ import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -37,9 +36,9 @@ import org.apache.flink.core.fs.FileStatus;
 import org.apache.flink.core.fs.FileSystem;
 import org.apache.flink.core.fs.Path;
 import org.apache.flink.core.fs.FileSystem.WriteMode;
-import org.apache.flink.core.testutils.CommonTestUtils;
-
 import org.apache.flink.util.FileUtils;
+
+import org.junit.Assume;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -51,14 +50,14 @@ import org.junit.rules.TemporaryFolder;
 public class LocalFileSystemTest {
 
 	@Rule
-	public TemporaryFolder temporaryFolder = new TemporaryFolder();
+	public final TemporaryFolder temporaryFolder = new TemporaryFolder();
 
 	/**
 	 * This test checks the functionality of the {@link LocalFileSystem} class.
 	 */
 	@Test
-	public void testLocalFilesystem() {
-		final File tempdir = new File(CommonTestUtils.getTempDir(), UUID.randomUUID().toString());
+	public void testLocalFilesystem() throws Exception {
+		final File tempdir = new File(temporaryFolder.getRoot(), UUID.randomUUID().toString());
 
 		final File testfile1 = new File(tempdir, UUID.randomUUID().toString());
 		final File testfile2 = new File(tempdir, UUID.randomUUID().toString());
@@ -66,113 +65,102 @@ public class LocalFileSystemTest {
 		final Path pathtotestfile1 = new Path(testfile1.toURI().getPath());
 		final Path pathtotestfile2 = new Path(testfile2.toURI().getPath());
 
-		try {
-			final LocalFileSystem lfs = new LocalFileSystem();
+		final LocalFileSystem lfs = new LocalFileSystem();
 
-			final Path pathtotmpdir = new Path(tempdir.toURI().getPath());
+		final Path pathtotmpdir = new Path(tempdir.toURI().getPath());
 
-			/*
-			 * check that lfs can see/create/delete/read directories
-			 */
+		/*
+		 * check that lfs can see/create/delete/read directories
+		 */
 
-			// check that dir is not existent yet
-			assertFalse(lfs.exists(pathtotmpdir));
-			assertTrue(tempdir.mkdirs());
+		// check that dir is not existent yet
+		assertFalse(lfs.exists(pathtotmpdir));
+		assertTrue(tempdir.mkdirs());
 
-			// check that local file system recognizes file..
-			assertTrue(lfs.exists(pathtotmpdir));
-			final FileStatus localstatus1 = lfs.getFileStatus(pathtotmpdir);
+		// check that local file system recognizes file..
+		assertTrue(lfs.exists(pathtotmpdir));
+		final FileStatus localstatus1 = lfs.getFileStatus(pathtotmpdir);
 
-			// check that lfs recognizes directory..
-			assertTrue(localstatus1.isDir());
+		// check that lfs recognizes directory..
+		assertTrue(localstatus1.isDir());
 
-			// get status for files in this (empty) directory..
-			final FileStatus[] statusforfiles = lfs.listStatus(pathtotmpdir);
+		// get status for files in this (empty) directory..
+		final FileStatus[] statusforfiles = lfs.listStatus(pathtotmpdir);
 
-			// no files in there.. hence, must be zero
-			assertTrue(statusforfiles.length == 0);
+		// no files in there.. hence, must be zero
+		assertTrue(statusforfiles.length == 0);
 
-			// check that lfs can delete directory..
-			lfs.delete(pathtotmpdir, true);
+		// check that lfs can delete directory..
+		lfs.delete(pathtotmpdir, true);
 
-			// double check that directory is not existent anymore..
-			assertFalse(lfs.exists(pathtotmpdir));
-			assertFalse(tempdir.exists());
+		// double check that directory is not existent anymore..
+		assertFalse(lfs.exists(pathtotmpdir));
+		assertFalse(tempdir.exists());
 
-			// re-create directory..
-			lfs.mkdirs(pathtotmpdir);
+		// re-create directory..
+		lfs.mkdirs(pathtotmpdir);
 
-			// creation successful?
-			assertTrue(tempdir.exists());
+		// creation successful?
+		assertTrue(tempdir.exists());
 
-			/*
-			 * check that lfs can create/read/write from/to files properly and read meta information..
-			 */
+		/*
+		 * check that lfs can create/read/write from/to files properly and read meta information..
+		 */
 
-			// create files.. one ""natively"", one using lfs
-			final FSDataOutputStream lfsoutput1 = lfs.create(pathtotestfile1, WriteMode.NO_OVERWRITE);
-			assertTrue(testfile2.createNewFile());
+		// create files.. one ""natively"", one using lfs
+		final FSDataOutputStream lfsoutput1 = lfs.create(pathtotestfile1, WriteMode.NO_OVERWRITE);
+		assertTrue(testfile2.createNewFile());
 
-			// does lfs create files? does lfs recognize created files?
-			assertTrue(testfile1.exists());
-			assertTrue(lfs.exists(pathtotestfile2));
+		// does lfs create files? does lfs recognize created files?
+		assertTrue(testfile1.exists());
+		assertTrue(lfs.exists(pathtotestfile2));
 
-			// test that lfs can write to files properly
-			final byte[] testbytes = { 1, 2, 3, 4, 5 };
-			lfsoutput1.write(testbytes);
-			lfsoutput1.close();
+		// test that lfs can write to files properly
+		final byte[] testbytes = { 1, 2, 3, 4, 5 };
+		lfsoutput1.write(testbytes);
+		lfsoutput1.close();
 
-			assertEquals(testfile1.length(), 5L);
+		assertEquals(testfile1.length(), 5L);
 
-			byte[] testbytestest = new byte[5];
-			try (FileInputStream fisfile1 = new FileInputStream(testfile1)) {
-				assertEquals(testbytestest.length, fisfile1.read(testbytestest));
-			}
-
-			assertArrayEquals(testbytes, testbytestest);
+		byte[] testbytestest = new byte[5];
+		try (FileInputStream fisfile1 = new FileInputStream(testfile1)) {
+			assertEquals(testbytestest.length, fisfile1.read(testbytestest));
+		}
 
-			// does lfs see the correct file length?
-			assertEquals(lfs.getFileStatus(pathtotestfile1).getLen(), testfile1.length());
+		assertArrayEquals(testbytes, testbytestest);
 
-			// as well, when we call the listStatus (that is intended for directories?)
-			assertEquals(lfs.listStatus(pathtotestfile1)[0].getLen(), testfile1.length());
+		// does lfs see the correct file length?
+		assertEquals(lfs.getFileStatus(pathtotestfile1).getLen(), testfile1.length());
 
-			// test that lfs can read files properly
-			final FileOutputStream fosfile2 = new FileOutputStream(testfile2);
-			fosfile2.write(testbytes);
-			fosfile2.close();
+		// as well, when we call the listStatus (that is intended for directories?)
+		assertEquals(lfs.listStatus(pathtotestfile1)[0].getLen(), testfile1.length());
 
-			testbytestest = new byte[5];
-			final FSDataInputStream lfsinput2 = lfs.open(pathtotestfile2);
-			assertEquals(lfsinput2.read(testbytestest), 5);
-			lfsinput2.close();
-			assertTrue(Arrays.equals(testbytes, testbytestest));
+		// test that lfs can read files properly
+		final FileOutputStream fosfile2 = new FileOutputStream(testfile2);
+		fosfile2.write(testbytes);
+		fosfile2.close();
 
-			// does lfs see two files?
-			assertEquals(lfs.listStatus(pathtotmpdir).length, 2);
+		testbytestest = new byte[5];
+		final FSDataInputStream lfsinput2 = lfs.open(pathtotestfile2);
+		assertEquals(lfsinput2.read(testbytestest), 5);
+		lfsinput2.close();
+		assertTrue(Arrays.equals(testbytes, testbytestest));
 
-			// do we get exactly one blocklocation per file? no matter what start and len we provide
-			assertEquals(lfs.getFileBlockLocations(lfs.getFileStatus(pathtotestfile1), 0, 0).length, 1);
+		// does lfs see two files?
+		assertEquals(lfs.listStatus(pathtotmpdir).length, 2);
 
-			/*
-			 * can lfs delete files / directories?
-			 */
-			assertTrue(lfs.delete(pathtotestfile1, false));
+		// do we get exactly one blocklocation per file? no matter what start and len we provide
+		assertEquals(lfs.getFileBlockLocations(lfs.getFileStatus(pathtotestfile1), 0, 0).length, 1);
 
-			// and can lfs also delete directories recursively?
-			assertTrue(lfs.delete(pathtotmpdir, true));
+		/*
+		 * can lfs delete files / directories?
+		 */
+		assertTrue(lfs.delete(pathtotestfile1, false));
 
-			assertTrue(!tempdir.exists());
+		// and can lfs also delete directories recursively?
+		assertTrue(lfs.delete(pathtotmpdir, true));
 
-		} catch (IOException e) {
-			fail(e.getMessage());
-		}
-		finally {
-			// clean up!
-			testfile1.delete();
-			testfile2.delete();
-			tempdir.delete();
-		}
+		assertTrue(!tempdir.exists());
 	}
 
 	/**
@@ -216,24 +204,23 @@ public class LocalFileSystemTest {
 
 	@Test
 	public void testRenamePath() throws IOException {
-		File rootDirectory = temporaryFolder.newFolder();
+		final File rootDirectory = temporaryFolder.newFolder();
 
 		//create a file /root/src/B/test.csv
-		File srcDirectory  = new File(rootDirectory, "src");
-		srcDirectory  = new File(srcDirectory, "B");
+		final File srcDirectory  = new File(new File(rootDirectory, "src"), "B");
 		assertTrue(srcDirectory.mkdirs());
-		File srcFile = new File(srcDirectory, "test.csv");
+
+		final File srcFile = new File(srcDirectory, "test.csv");
 		assertTrue(srcFile.createNewFile());
 
 		//Move/rename B and its content to /root/dst/A
-		File destDirectory  = new File(rootDirectory, "dst");
-		destDirectory  = new File(destDirectory, "B");
-		File destFile  = new File(destDirectory, "test.csv");
+		final File destDirectory  = new File(new File(rootDirectory, "dst"), "B");
+		final File destFile  = new File(destDirectory, "test.csv");
 
-		Path srcDirPath = new Path(srcDirectory.toURI());
-		Path srcFilePath = new Path(srcFile.toURI());
-		Path destDirPath = new Path(destDirectory.toURI());
-		Path destFilePath = new Path(destFile.toURI());
+		final Path srcDirPath = new Path(srcDirectory.toURI());
+		final Path srcFilePath = new Path(srcFile.toURI());
+		final Path destDirPath = new Path(destDirectory.toURI());
+		final Path destFilePath = new Path(destFile.toURI());
 
 		FileSystem fs = FileSystem.getLocalFileSystem();
 
@@ -243,21 +230,86 @@ public class LocalFileSystemTest {
 
 		// do the move/rename: /root/src/B -> /root/dst/
 		assertTrue(fs.rename(srcDirPath, destDirPath));
-		
-		// post-conditions: /root/src/B doens't exists, /root/dst/B/test.csv has been created
+
+		// post-conditions: /root/src/B doesn't exists, /root/dst/B/test.csv has been created
 		assertTrue(fs.exists(destFilePath));
 		assertFalse(fs.exists(srcDirPath));
-		
-		//re-create initial situation and test overwrite
-		assertTrue(fs.delete(destDirPath, true));
+
+		// re-create source file and test overwrite
 		assertTrue(srcDirectory.mkdirs());
 		assertTrue(srcFile.createNewFile());
-		//now use the file as dest: /root/src/B/test.csv -> /root/dst/B/test.csv
+
+		// overwrite the destination file
 		assertTrue(fs.rename(srcFilePath, destFilePath));
-		
+
 		// post-conditions: now only the src file has been moved
 		assertFalse(fs.exists(srcFilePath));
 		assertTrue(fs.exists(srcDirPath));
 		assertTrue(fs.exists(destFilePath));
 	}
+
+	@Test
+	public void testRenameNonExistingFile() throws IOException {
+		final FileSystem fs = FileSystem.getLocalFileSystem();
+
+		final File srcFile = new File(temporaryFolder.newFolder(), "someFile.txt");
+		final File destFile  = new File(temporaryFolder.newFolder(), "target");
+
+		final Path srcFilePath = new Path(srcFile.toURI());
+		final Path destFilePath = new Path(destFile.toURI());
+
+		// this cannot succeed because the source file does not exist
+		assertFalse(fs.rename(srcFilePath, destFilePath));
+	}
+
+	@Test
+	public void testRenameFileWithNoAccess() throws IOException {
+		final FileSystem fs = FileSystem.getLocalFileSystem();
+
+		final File srcFile = temporaryFolder.newFile("someFile.txt");
+		final File destFile = new File(temporaryFolder.newFolder(), "target");
+
+		// we need to make the file non-modifiable so that the rename fails
+		Assume.assumeTrue(srcFile.getParentFile().setWritable(false, false));
+		Assume.assumeTrue(srcFile.setWritable(false, false));
+
+		try {
+			final Path srcFilePath = new Path(srcFile.toURI());
+			final Path destFilePath = new Path(destFile.toURI());
+
+			// this cannot succeed because the source folder has no permission to remove the file
+			assertFalse(fs.rename(srcFilePath, destFilePath));
+		}
+		finally {
+			// make sure we give permission back to ensure proper cleanup
+
+			//noinspection ResultOfMethodCallIgnored
+			srcFile.getParentFile().setWritable(true, false);
+			//noinspection ResultOfMethodCallIgnored
+			srcFile.setWritable(true, false);
+		}
+	}
+
+	@Test
+	public void testRenameToNonEmptyTargetDir() throws IOException {
+		final FileSystem fs = FileSystem.getLocalFileSystem();
+
+		// a source folder with a file
+		final File srcFolder = temporaryFolder.newFolder();
+		final File srcFile = new File(srcFolder, "someFile.txt");
+		assertTrue(srcFile.createNewFile());
+
+		// a non-empty destination folder
+		final File dstFolder = temporaryFolder.newFolder();
+		final File dstFile  = new File(dstFolder, "target");
+		assertTrue(dstFile.createNewFile());
+
+		// this cannot succeed because the destination folder is not empty
+		assertFalse(fs.rename(new Path(srcFolder.toURI()), new Path(dstFolder.toURI())));
+
+		// retry after deleting the occupying target file
+		assertTrue(dstFile.delete());
+		assertTrue(fs.rename(new Path(srcFolder.toURI()), new Path(dstFolder.toURI())));
+		assertTrue(new File(dstFolder, srcFile.getName()).exists());
+	}
 }


[2/2] flink git commit: [FLINK-6103] [core] Improve rename() on LocalFileSystem

Posted by se...@apache.org.
[FLINK-6103] [core] Improve rename() on LocalFileSystem

This closes #3598


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/a4f9a549
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/a4f9a549
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/a4f9a549

Branch: refs/heads/master
Commit: a4f9a54953132fbd1a44888a403576c157649f1f
Parents: a0249d9
Author: Flavio Pompermaier <f....@gmail.com>
Authored: Wed Mar 22 00:05:25 2017 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Fri Apr 21 09:55:11 2017 +0200

----------------------------------------------------------------------
 .../flink/core/fs/local/LocalFileSystem.java    | 24 +++++++--
 .../core/fs/local/LocalFileSystemTest.java      | 52 +++++++++++++++++++-
 2 files changed, 69 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/a4f9a549/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java b/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java
index 12aeb7f..0a168de 100644
--- a/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java
+++ b/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java
@@ -20,7 +20,7 @@
 /**
  * This file is based on source code from the Hadoop Project (http://hadoop.apache.org/), licensed by the Apache
  * Software Foundation (ASF) under the Apache License, Version 2.0. See the NOTICE file distributed with this work for
- * additional information regarding copyright ownership. 
+ * additional information regarding copyright ownership.
  */
 
 package org.apache.flink.core.fs.local;
@@ -43,7 +43,10 @@ import java.io.IOException;
 import java.net.InetAddress;
 import java.net.URI;
 import java.net.UnknownHostException;
+import java.nio.file.DirectoryNotEmptyException;
 import java.nio.file.FileAlreadyExistsException;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
 
 import static org.apache.flink.util.Preconditions.checkNotNull;
 
@@ -190,7 +193,7 @@ public class LocalFileSystem extends FileSystem {
 
 	/**
 	 * Deletes the given file or directory.
-	 * 
+	 *
 	 * @param f
 	 *        the file to be deleted
 	 * @return <code>true</code> if all files were deleted successfully, <code>false</code> otherwise
@@ -217,12 +220,13 @@ public class LocalFileSystem extends FileSystem {
 
 	/**
 	 * Recursively creates the directory specified by the provided path.
-	 * 
+	 *
 	 * @return <code>true</code>if the directories either already existed or have been created successfully,
 	 *         <code>false</code> otherwise
 	 * @throws IOException
 	 *         thrown if an error occurred while creating the directory/directories
 	 */
+	@Override
 	public boolean mkdirs(final Path f) throws IOException {
 		final File p2f = pathToFile(f);
 
@@ -262,8 +266,18 @@ public class LocalFileSystem extends FileSystem {
 	public boolean rename(final Path src, final Path dst) throws IOException {
 		final File srcFile = pathToFile(src);
 		final File dstFile = pathToFile(dst);
-
-		return srcFile.renameTo(dstFile);
+		//Files.move fails if the destination directory doesn't exist
+		if(dstFile.getParentFile()!= null && !dstFile.getParentFile().exists()){
+			dstFile.getParentFile().mkdirs();
+		}
+		try {
+			Files.move(srcFile.toPath(), dstFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
+			return true;
+		}
+		catch (FileAlreadyExistsException | DirectoryNotEmptyException | SecurityException ex) {
+			//Catch the errors that are regular "move failed" exceptions and return false
+			return false;
+		}
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/flink/blob/a4f9a549/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java b/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
index ee1deef..7b7d599 100644
--- a/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
+++ b/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
@@ -36,6 +36,7 @@ import org.apache.flink.core.fs.FSDataOutputStream;
 import org.apache.flink.core.fs.FileStatus;
 import org.apache.flink.core.fs.FileSystem;
 import org.apache.flink.core.fs.Path;
+import org.apache.flink.core.fs.FileSystem.WriteMode;
 import org.apache.flink.core.testutils.CommonTestUtils;
 
 import org.apache.flink.util.FileUtils;
@@ -109,7 +110,7 @@ public class LocalFileSystemTest {
 			 */
 
 			// create files.. one ""natively"", one using lfs
-			final FSDataOutputStream lfsoutput1 = lfs.create(pathtotestfile1, false);
+			final FSDataOutputStream lfsoutput1 = lfs.create(pathtotestfile1, WriteMode.NO_OVERWRITE);
 			assertTrue(testfile2.createNewFile());
 
 			// does lfs create files? does lfs recognize created files?
@@ -127,7 +128,7 @@ public class LocalFileSystemTest {
 			try (FileInputStream fisfile1 = new FileInputStream(testfile1)) {
 				assertEquals(testbytestest.length, fisfile1.read(testbytestest));
 			}
-			
+
 			assertArrayEquals(testbytes, testbytestest);
 
 			// does lfs see the correct file length?
@@ -212,4 +213,51 @@ public class LocalFileSystemTest {
 		assertTrue(FileUtils.deletePathIfEmpty(fs, directoryPath));
 		assertFalse(fs.exists(directoryPath));
 	}
+
+	@Test
+	public void testRenamePath() throws IOException {
+		File rootDirectory = temporaryFolder.newFolder();
+
+		//create a file /root/src/B/test.csv
+		File srcDirectory  = new File(rootDirectory, "src");
+		srcDirectory  = new File(srcDirectory, "B");
+		assertTrue(srcDirectory.mkdirs());
+		File srcFile = new File(srcDirectory, "test.csv");
+		assertTrue(srcFile.createNewFile());
+
+		//Move/rename B and its content to /root/dst/A
+		File destDirectory  = new File(rootDirectory, "dst");
+		destDirectory  = new File(destDirectory, "B");
+		File destFile  = new File(destDirectory, "test.csv");
+
+		Path srcDirPath = new Path(srcDirectory.toURI());
+		Path srcFilePath = new Path(srcFile.toURI());
+		Path destDirPath = new Path(destDirectory.toURI());
+		Path destFilePath = new Path(destFile.toURI());
+
+		FileSystem fs = FileSystem.getLocalFileSystem();
+
+		// pre-conditions: /root/src/B exists but /root/dst/B does not
+		assertTrue(fs.exists(srcDirPath));
+		assertFalse(fs.exists(destDirPath));
+
+		// do the move/rename: /root/src/B -> /root/dst/
+		assertTrue(fs.rename(srcDirPath, destDirPath));
+		
+		// post-conditions: /root/src/B doens't exists, /root/dst/B/test.csv has been created
+		assertTrue(fs.exists(destFilePath));
+		assertFalse(fs.exists(srcDirPath));
+		
+		//re-create initial situation and test overwrite
+		assertTrue(fs.delete(destDirPath, true));
+		assertTrue(srcDirectory.mkdirs());
+		assertTrue(srcFile.createNewFile());
+		//now use the file as dest: /root/src/B/test.csv -> /root/dst/B/test.csv
+		assertTrue(fs.rename(srcFilePath, destFilePath));
+		
+		// post-conditions: now only the src file has been moved
+		assertFalse(fs.exists(srcFilePath));
+		assertTrue(fs.exists(srcDirPath));
+		assertTrue(fs.exists(destFilePath));
+	}
 }