Skip to content

Commit cf76290

Browse files
authored
HDDS-15109. Extract rename test cases to OzoneFileSystemTests (#10120)
1 parent debc8ab commit cf76290

3 files changed

Lines changed: 171 additions & 197 deletions

File tree

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java

Lines changed: 38 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,8 @@ public void testRenameWithNonExistentSource() throws Exception {
963963
final String root = "/root";
964964
final String dir1 = root + "/dir1";
965965
final String dir2 = root + "/dir2";
966-
final Path source = new Path(fs.getUri().toString() + dir1);
967-
final Path destin = new Path(fs.getUri().toString() + dir2);
966+
final Path source = pathUnderFsRoot(dir1);
967+
final Path destin = pathUnderFsRoot(dir2);
968968

969969
// creates destin
970970
fs.mkdirs(destin);
@@ -979,23 +979,7 @@ public void testRenameWithNonExistentSource() throws Exception {
979979
*/
980980
@Test
981981
public void testRenameDirToItsOwnSubDir() throws Exception {
982-
final String root = "/root";
983-
final String dir1 = root + "/dir1";
984-
final Path dir1Path = new Path(fs.getUri().toString() + dir1);
985-
// Add a sub-dir1 to the directory to be moved.
986-
final Path subDir1 = new Path(dir1Path, "sub_dir1");
987-
fs.mkdirs(subDir1);
988-
LOG.info("Created dir1 {}", subDir1);
989-
990-
final Path sourceRoot = new Path(fs.getUri().toString() + root);
991-
LOG.info("Rename op-> source:{} to destin:{}", sourceRoot, subDir1);
992-
try {
993-
fs.rename(sourceRoot, subDir1);
994-
fail("Should throw exception : Cannot rename a directory to" +
995-
" its own subdirectory");
996-
} catch (IllegalArgumentException iae) {
997-
// expected
998-
}
982+
renameDirToItsOwnSubDir();
999983
}
1000984

1001985
/**
@@ -1006,11 +990,11 @@ public void testRenameSourceAndDestinAreSame() throws Exception {
1006990
final String root = "/root";
1007991
final String dir1 = root + "/dir1";
1008992
final String dir2 = dir1 + "/dir2";
1009-
final Path dir2Path = new Path(fs.getUri().toString() + dir2);
993+
final Path dir2Path = pathUnderFsRoot(dir2);
1010994
fs.mkdirs(dir2Path);
1011995

1012996
// File rename
1013-
Path file1 = new Path(fs.getUri().toString() + dir2 + "/file1");
997+
Path file1 = pathUnderFsRoot(dir2 + "/file1");
1014998
ContractTestUtils.touch(fs, file1);
1015999

10161000
assertTrue(fs.rename(file1, file1));
@@ -1025,23 +1009,23 @@ public void testRenameSourceAndDestinAreSame() throws Exception {
10251009
@Test
10261010
public void testRenameToExistingDir() throws Exception {
10271011
// created /a
1028-
final Path aSourcePath = new Path(fs.getUri().toString() + "/a");
1012+
final Path aSourcePath = pathUnderFsRoot("/a");
10291013
fs.mkdirs(aSourcePath);
10301014

10311015
// created /b
1032-
final Path bDestinPath = new Path(fs.getUri().toString() + "/b");
1016+
final Path bDestinPath = pathUnderFsRoot("/b");
10331017
fs.mkdirs(bDestinPath);
10341018

10351019
// Add a sub-directory '/a/c' to '/a'. This is to verify that after
10361020
// rename sub-directory also be moved.
1037-
final Path acPath = new Path(fs.getUri().toString() + "/a/c");
1021+
final Path acPath = pathUnderFsRoot("/a/c");
10381022
fs.mkdirs(acPath);
10391023

10401024
// Rename from /a to /b.
10411025
assertTrue(fs.rename(aSourcePath, bDestinPath), "Rename failed");
10421026

1043-
final Path baPath = new Path(fs.getUri().toString() + "/b/a");
1044-
final Path bacPath = new Path(fs.getUri().toString() + "/b/a/c");
1027+
final Path baPath = pathUnderFsRoot("/b/a");
1028+
final Path bacPath = pathUnderFsRoot("/b/a/c");
10451029
assertTrue(fs.exists(baPath), "Rename failed");
10461030
assertTrue(fs.exists(bacPath), "Rename failed");
10471031
}
@@ -1057,31 +1041,31 @@ public void testRenameToExistingDir() throws Exception {
10571041
public void testRenameToNewSubDirShouldNotExist() throws Exception {
10581042
// Case-5.a) Rename directory from /a to /b.
10591043
// created /a
1060-
final Path aSourcePath = new Path(fs.getUri().toString() + "/a");
1044+
final Path aSourcePath = pathUnderFsRoot("/a");
10611045
fs.mkdirs(aSourcePath);
10621046

10631047
// created /b
1064-
final Path bDestinPath = new Path(fs.getUri().toString() + "/b");
1048+
final Path bDestinPath = pathUnderFsRoot("/b");
10651049
fs.mkdirs(bDestinPath);
10661050

10671051
// Add a sub-directory '/b/a' to '/b'. This is to verify that rename
10681052
// throws exception as new destin /b/a already exists.
1069-
final Path baPath = new Path(fs.getUri().toString() + "/b/a/c");
1053+
final Path baPath = pathUnderFsRoot("/b/a/c");
10701054
fs.mkdirs(baPath);
10711055

10721056
assertFalse(fs.rename(aSourcePath, bDestinPath), "New destin sub-path /b/a already exists");
10731057

10741058
// Case-5.b) Rename file from /a/b/c/file1 to /a.
10751059
// Should be failed since /a/file1 exists.
1076-
final Path abcPath = new Path(fs.getUri().toString() + "/a/b/c");
1060+
final Path abcPath = pathUnderFsRoot("/a/b/c");
10771061
fs.mkdirs(abcPath);
10781062
Path abcFile1 = new Path(abcPath, "/file1");
10791063
ContractTestUtils.touch(fs, abcFile1);
10801064

1081-
final Path aFile1 = new Path(fs.getUri().toString() + "/a/file1");
1065+
final Path aFile1 = pathUnderFsRoot("/a/file1");
10821066
ContractTestUtils.touch(fs, aFile1);
10831067

1084-
final Path aDestinPath = new Path(fs.getUri().toString() + "/a");
1068+
final Path aDestinPath = pathUnderFsRoot("/a");
10851069

10861070
assertFalse(fs.rename(abcFile1, aDestinPath), "New destin sub-path /b/a already exists");
10871071
}
@@ -1092,12 +1076,12 @@ public void testRenameToNewSubDirShouldNotExist() throws Exception {
10921076
@Test
10931077
public void testRenameDirToFile() throws Exception {
10941078
final String root = "/root";
1095-
Path rootPath = new Path(fs.getUri().toString() + root);
1079+
Path rootPath = pathUnderFsRoot(root);
10961080
fs.mkdirs(rootPath);
10971081

1098-
Path file1Destin = new Path(fs.getUri().toString() + root + "/file1");
1082+
Path file1Destin = pathUnderFsRoot(root + "/file1");
10991083
ContractTestUtils.touch(fs, file1Destin);
1100-
Path abcRootPath = new Path(fs.getUri().toString() + "/a/b/c");
1084+
Path abcRootPath = pathUnderFsRoot("/a/b/c");
11011085
fs.mkdirs(abcRootPath);
11021086
assertFalse(fs.rename(abcRootPath, file1Destin), "key already exists /root_dir/file1");
11031087
}
@@ -1108,25 +1092,20 @@ public void testRenameDirToFile() throws Exception {
11081092
@Test
11091093
public void testRenameFile() throws Exception {
11101094
final String root = "/root";
1111-
Path rootPath = new Path(fs.getUri().toString() + root);
1112-
fs.mkdirs(rootPath);
1113-
1114-
Path file1Source = new Path(fs.getUri().toString() + root
1115-
+ "/file1_Copy");
1116-
ContractTestUtils.touch(fs, file1Source);
1117-
Path file1Destin = new Path(fs.getUri().toString() + root + "/file1");
1118-
assertTrue(fs.rename(file1Source, file1Destin), "Renamed failed");
1119-
assertTrue(fs.exists(file1Destin), "Renamed failed: /root/file1");
1095+
renameFile(root);
1096+
}
11201097

1098+
@Override
1099+
public void verifyRenameFile(Path workDir, Path expectedDest) throws IOException {
11211100
/*
11221101
* Reading several times, this is to verify that OmKeyInfo#keyName cached
11231102
* entry is not modified. While reading back, OmKeyInfo#keyName will be
11241103
* prepared and assigned to fullkeyPath name.
11251104
*/
11261105
for (int i = 0; i < 10; i++) {
1127-
FileStatus[] fStatus = fs.listStatus(rootPath);
1106+
FileStatus[] fStatus = fs.listStatus(workDir);
11281107
assertEquals(1, fStatus.length, "Renamed failed");
1129-
assertEquals(file1Destin, fStatus[0].getPath(), "Wrong path name!");
1108+
assertEquals(expectedDest, fStatus[0].getPath(), "Wrong path name!");
11301109
}
11311110
}
11321111

@@ -1136,16 +1115,12 @@ public void testRenameFile() throws Exception {
11361115
@Test
11371116
public void testRenameFileToDir() throws Exception {
11381117
final String root = "/root";
1139-
Path rootPath = new Path(fs.getUri().toString() + root);
1140-
fs.mkdirs(rootPath);
1118+
renameFileToDir(root);
1119+
}
11411120

1142-
Path file1Destin = new Path(fs.getUri().toString() + root + "/file1");
1143-
ContractTestUtils.touch(fs, file1Destin);
1144-
Path abcRootPath = new Path(fs.getUri().toString() + "/a/b/c");
1145-
fs.mkdirs(abcRootPath);
1146-
assertTrue(fs.rename(file1Destin, abcRootPath), "Renamed failed");
1147-
assertTrue(fs.exists(new Path(abcRootPath,
1148-
"file1")), "Renamed filed: /a/b/c/file1");
1121+
@Override
1122+
protected Path pathUnderFsRoot(String relativePath) {
1123+
return new Path(getFs().getUri().toString() + relativePath);
11491124
}
11501125

11511126
@Test
@@ -1156,8 +1131,8 @@ public void testRenameContainDelimiterFile() throws Exception {
11561131
String targetKeyName = fakeParentKey + "/key2";
11571132
TestDataUtil.createKey(ozoneBucket, sourceKeyName, new byte[0]);
11581133

1159-
Path sourcePath = new Path(fs.getUri().toString() + "/" + sourceKeyName);
1160-
Path targetPath = new Path(fs.getUri().toString() + "/" + targetKeyName);
1134+
Path sourcePath = pathUnderFsRoot("/" + sourceKeyName);
1135+
Path targetPath = pathUnderFsRoot("/" + targetKeyName);
11611136
assertTrue(fs.rename(sourcePath, targetPath));
11621137
assertFalse(fs.exists(sourcePath));
11631138
assertTrue(fs.exists(targetPath));
@@ -1172,32 +1147,7 @@ public void testRenameContainDelimiterFile() throws Exception {
11721147
*/
11731148
@Test
11741149
public void testRenameDestinationParentDoesntExist() throws Exception {
1175-
final String root = "/root_dir";
1176-
final String dir1 = root + "/dir1";
1177-
final String dir2 = dir1 + "/dir2";
1178-
final Path dir2SourcePath = new Path(fs.getUri().toString() + dir2);
1179-
fs.mkdirs(dir2SourcePath);
1180-
1181-
// (a) parent of dst does not exist. /root_dir/b/c
1182-
final Path destinPath = new Path(fs.getUri().toString() + root + "/b/c");
1183-
try {
1184-
fs.rename(dir2SourcePath, destinPath);
1185-
fail("Should fail as parent of dst does not exist!");
1186-
} catch (FileNotFoundException fnfe) {
1187-
// expected
1188-
}
1189-
1190-
// (b) parent of dst is a file. /root_dir/file1/c
1191-
Path filePath = new Path(fs.getUri().toString() + root + "/file1");
1192-
ContractTestUtils.touch(fs, filePath);
1193-
1194-
Path newDestinPath = new Path(filePath, "c");
1195-
try {
1196-
fs.rename(dir2SourcePath, newDestinPath);
1197-
fail("Should fail as parent of dst is a file!");
1198-
} catch (IOException ioe) {
1199-
// expected
1200-
}
1150+
renameDestinationParentDoesNotExist();
12011151
}
12021152

12031153
/**
@@ -1210,33 +1160,13 @@ public void testRenameDestinationParentDoesntExist() throws Exception {
12101160
*/
12111161
@Test
12121162
public void testRenameToParentDir() throws Exception {
1213-
final String root = "/root_dir";
1214-
final String dir1 = root + "/dir1";
1215-
final String dir2 = dir1 + "/dir2";
1216-
final Path dir2SourcePath = new Path(fs.getUri().toString() + dir2);
1217-
fs.mkdirs(dir2SourcePath);
1218-
final Path destRootPath = new Path(fs.getUri().toString() + root);
1219-
1220-
Path file1Source = new Path(fs.getUri().toString() + dir1 + "/file2");
1221-
ContractTestUtils.touch(fs, file1Source);
1222-
1223-
// rename source directory to its parent directory(destination).
1224-
assertTrue(fs.rename(dir2SourcePath, destRootPath), "Rename failed");
1225-
final Path expectedPathAfterRename =
1226-
new Path(fs.getUri().toString() + root + "/dir2");
1227-
assertTrue(fs.exists(expectedPathAfterRename), "Rename failed");
1228-
1229-
// rename source file to its parent directory(destination).
1230-
assertTrue(fs.rename(file1Source, destRootPath), "Rename failed");
1231-
final Path expectedFilePathAfterRename =
1232-
new Path(fs.getUri().toString() + root + "/file2");
1233-
assertTrue(fs.exists(expectedFilePathAfterRename), "Rename failed");
1163+
renameToParentDir();
12341164
}
12351165

12361166
@Test
12371167
public void testRenameDir() throws Exception {
12381168
final String dir = "/root_dir/dir1";
1239-
final Path source = new Path(fs.getUri().toString() + dir);
1169+
final Path source = pathUnderFsRoot(dir);
12401170
final Path dest = new Path(source.toString() + ".renamed");
12411171
// Add a sub-dir to the directory to be moved.
12421172
final Path subdir = new Path(source, "sub_dir1");
@@ -1252,7 +1182,7 @@ public void testRenameDir() throws Exception {
12521182
// Test if one path belongs to other FileSystem.
12531183
IllegalArgumentException exception = assertThrows(
12541184
IllegalArgumentException.class,
1255-
() -> fs.rename(new Path(fs.getUri().toString() + "fake" + dir), dest));
1185+
() -> fs.rename(pathUnderFsRoot("fake" + dir), dest));
12561186
assertThat(exception.getMessage()).contains("Wrong FS");
12571187
}
12581188

@@ -2045,10 +1975,9 @@ void testFileSystemWithObjectStoreLayout() throws IOException {
20451975
@Test
20461976
public void testGetFileChecksumWithInvalidCombineMode() throws IOException {
20471977
final String root = "/root";
2048-
Path rootPath = new Path(fs.getUri().toString() + root);
1978+
Path rootPath = pathUnderFsRoot(root);
20491979
fs.mkdirs(rootPath);
2050-
Path file = new Path(fs.getUri().toString() + root
2051-
+ "/dummy");
1980+
Path file = pathUnderFsRoot(root + "/dummy");
20521981
ContractTestUtils.touch(fs, file);
20531982
OzoneClientConfig clientConfig = cluster.getConf().getObject(OzoneClientConfig.class);
20541983
clientConfig.setChecksumCombineMode("NONE");

0 commit comments

Comments
 (0)