This is an automated email from the ASF dual-hosted git repository.
stevel pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.3 by this push:
new 47131cd HADOOP-17365. Contract test for renaming over existing file
is too lenient (#2447)
47131cd is described below
commit 47131cdf7c63e2266cecf26aba287b47cdd4dcb0
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Wed Nov 11 22:20:09 2020 +0100
HADOOP-17365. Contract test for renaming over existing file is too lenient
(#2447)
Contributed by Attila Doroszlai.
Change-Id: I21c29256b52449b7fea335704b3afa02e39c6a39
---
.../fs/contract/AbstractContractRenameTest.java | 40 +++++++++++++++-------
1 file changed, 27 insertions(+), 13 deletions(-)
diff --git
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractRenameTest.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractRenameTest.java
index 78ff254..e032604 100644
---
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractRenameTest.java
+++
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractRenameTest.java
@@ -104,29 +104,43 @@ public abstract class AbstractContractRenameTest extends
assertIsFile(destFile);
boolean renameOverwritesDest = isSupported(RENAME_OVERWRITES_DEST);
boolean renameReturnsFalseOnRenameDestExists =
- !isSupported(RENAME_RETURNS_FALSE_IF_DEST_EXISTS);
+ isSupported(RENAME_RETURNS_FALSE_IF_DEST_EXISTS);
+ assertFalse(RENAME_OVERWRITES_DEST + " and " +
+ RENAME_RETURNS_FALSE_IF_DEST_EXISTS + " cannot be both supported",
+ renameOverwritesDest && renameReturnsFalseOnRenameDestExists);
+ String expectedTo = "expected rename(" + srcFile + ", " + destFile + ") to
";
+
boolean destUnchanged = true;
try {
+ // rename is rejected by returning 'false' or throwing an exception
boolean renamed = rename(srcFile, destFile);
+ destUnchanged = !renamed;
if (renameOverwritesDest) {
- // the filesystem supports rename(file, file2) by overwriting file2
-
- assertTrue("Rename returned false", renamed);
- destUnchanged = false;
+ assertTrue(expectedTo + "overwrite destination, but got false",
+ renamed);
+ } else if (renameReturnsFalseOnRenameDestExists) {
+ assertFalse(expectedTo + "be rejected with false, but destination " +
+ "was overwritten", renamed);
+ } else if (renamed) {
+ String destDirLS = generateAndLogErrorListing(srcFile, destFile);
+ getLogger().error("dest dir {}", destDirLS);
+
+ fail(expectedTo + "be rejected with exception, but got overwritten");
} else {
- // rename is rejected by returning 'false' or throwing an exception
- if (renamed && !renameReturnsFalseOnRenameDestExists) {
- //expected an exception
- String destDirLS = generateAndLogErrorListing(srcFile, destFile);
- getLogger().error("dest dir {}", destDirLS);
- fail("expected rename(" + srcFile + ", " + destFile + " ) to fail," +
- " but got success and destination of " + destDirLS);
- }
+ fail(expectedTo + "be rejected with exception, but got false");
}
} catch (FileAlreadyExistsException e) {
+ // rename(file, file2) should throw exception iff
+ // it neither overwrites nor returns false
+ assertFalse(expectedTo + "overwrite destination, but got exception",
+ renameOverwritesDest);
+ assertFalse(expectedTo + "be rejected with false, but got exception",
+ renameReturnsFalseOnRenameDestExists);
+
handleExpectedException(e);
}
+
// verify that the destination file is as expected based on the expected
// outcome
verifyFileContents(getFileSystem(), destFile,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]