Skip to content

Commit d4ee776

Browse files
authored
HDDS-14698. Abstract testCreateDoesNotAddParentDirKeys and testListStatusIteratorOnRoot/InBucket (#9809)
1 parent 21d15bf commit d4ee776

3 files changed

Lines changed: 73 additions & 88 deletions

File tree

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

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -412,23 +412,12 @@ private void checkInvalidPath(Path path) {
412412
@Test
413413
public void testCreateDoesNotAddParentDirKeys() throws Exception {
414414
Path grandparent = new Path("/testCreateDoesNotAddParentDirKeys");
415-
Path parent = new Path(grandparent, "parent");
416-
Path child = new Path(parent, "child");
417-
ContractTestUtils.touch(fs, child);
418-
419-
OzoneKeyDetails key = getKey(child, false);
420-
assertEquals(key.getName(), fs.pathToKey(child));
421-
422-
// Creating a child should not add parent keys to the bucket
423-
try {
424-
getKey(parent, true);
425-
} catch (OMException ome) {
426-
assertEquals(KEY_NOT_FOUND, ome.getResult());
427-
}
415+
createDoesNotAddParentDirKeys(grandparent);
416+
}
428417

429-
// List status on the parent should show the child file
430-
assertEquals(1L, fs.listStatus(parent).length, "List status of parent should include the 1 child file");
431-
assertTrue(fs.getFileStatus(parent).isDirectory(), "Parent directory does not appear to be a directory");
418+
@Override
419+
String getChildKeyName(Path child) {
420+
return fs.pathToKey(child);
432421
}
433422

434423
@Test
@@ -968,32 +957,7 @@ public void testListStatusIteratorWithDir() throws Exception {
968957
*/
969958
@Test
970959
public void testListStatusIteratorOnRoot() throws Exception {
971-
Path dir1 = new Path(ROOT, "dir1");
972-
Path dir12 = new Path(dir1, "dir12");
973-
Path dir2 = new Path(ROOT, "dir2");
974-
try {
975-
fs.mkdirs(dir12);
976-
fs.mkdirs(dir2);
977-
978-
// ListStatusIterator on root should return dir1
979-
// (even though /dir1 key does not exist)and dir2 only.
980-
// dir12 is not an immediate child of root and hence should not be listed.
981-
RemoteIterator<FileStatus> it = fs.listStatusIterator(ROOT);
982-
int iCount = 0;
983-
while (it.hasNext()) {
984-
iCount++;
985-
FileStatus fileStatus = it.next();
986-
assertNotNull(fileStatus);
987-
// Verify that dir12 is not included in the result
988-
// of the listStatusIterator on root.
989-
assertNotEquals(fileStatus.getPath().toUri().getPath(), dir12.toString());
990-
}
991-
assertEquals(2, iCount, "FileStatus should return only the immediate children");
992-
} finally {
993-
// Cleanup
994-
fs.delete(dir2, true);
995-
fs.delete(dir1, true);
996-
}
960+
listStatusIteratorOnRoot(ROOT);
997961
}
998962

999963
@Test

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

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -286,27 +286,13 @@ void testUserHomeDirectory() {
286286
void testCreateDoesNotAddParentDirKeys() throws Exception {
287287
Path grandparent = new Path(bucketPath,
288288
"testCreateDoesNotAddParentDirKeys");
289-
Path parent = new Path(grandparent, "parent");
290-
Path child = new Path(parent, "child");
291-
ContractTestUtils.touch(fs, child);
289+
createDoesNotAddParentDirKeys(grandparent);
290+
}
292291

293-
OzoneKeyDetails key = getKey(child, false);
292+
@Override
293+
String getChildKeyName(Path child) {
294294
OFSPath childOFSPath = new OFSPath(child, conf);
295-
assertEquals(key.getName(), childOFSPath.getKeyName());
296-
297-
// Creating a child should not add parent keys to the bucket
298-
try {
299-
getKey(parent, true);
300-
} catch (OMException ome) {
301-
assertEquals(KEY_NOT_FOUND, ome.getResult());
302-
}
303-
304-
// List status on the parent should show the child file
305-
assertEquals(1L, fs.listStatus(parent).length, "List status of parent should include the 1 child file");
306-
assertTrue(fs.getFileStatus(parent).isDirectory(), "Parent directory does not appear to be a directory");
307-
308-
// Cleanup
309-
fs.delete(grandparent, true);
295+
return childOFSPath.getKeyName();
310296
}
311297

312298
@Test
@@ -446,33 +432,7 @@ void testListStatusIteratorWithDir() throws Exception {
446432
@Test
447433
void testListStatusIteratorInBucket() throws Exception {
448434
Path root = new Path("/" + volumeName + "/" + bucketName);
449-
Path dir1 = new Path(root, "dir1");
450-
Path dir12 = new Path(dir1, "dir12");
451-
Path dir2 = new Path(root, "dir2");
452-
try {
453-
fs.mkdirs(dir12);
454-
fs.mkdirs(dir2);
455-
456-
// ListStatus on root should return dir1 (even though /dir1 key does not
457-
// exist) and dir2 only. dir12 is not an immediate child of root and
458-
// hence should not be listed.
459-
RemoteIterator<FileStatus> it = fs.listStatusIterator(root);
460-
// Verify that dir12 is not included in the result of the listStatus on
461-
// root
462-
int iCount = 0;
463-
while (it.hasNext()) {
464-
iCount++;
465-
FileStatus fileStatus = it.next();
466-
assertNotNull(fileStatus);
467-
assertNotEquals(fileStatus, dir12.toString());
468-
}
469-
assertEquals(2, iCount, "FileStatus should return only the immediate children");
470-
471-
} finally {
472-
// cleanup
473-
fs.delete(dir1, true);
474-
fs.delete(dir2, true);
475-
}
435+
listStatusIteratorOnRoot(root);
476436
}
477437

478438
@Test

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919

2020
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION;
2121
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION_TYPE;
22+
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
2223
import static org.assertj.core.api.Assertions.assertThat;
2324
import static org.junit.jupiter.api.Assertions.assertEquals;
2425
import static org.junit.jupiter.api.Assertions.assertFalse;
26+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2527
import static org.junit.jupiter.api.Assertions.assertNotNull;
28+
import static org.junit.jupiter.api.Assertions.assertTrue;
2629

2730
import java.io.IOException;
2831
import java.net.URI;
@@ -39,6 +42,7 @@
3942
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
4043
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
4144
import org.apache.hadoop.ozone.client.OzoneKeyDetails;
45+
import org.apache.hadoop.ozone.om.exceptions.OMException;
4246

4347
/**
4448
* Common test cases for Ozone file systems.
@@ -207,6 +211,63 @@ void listStatusIteratorWithDir(Path root) throws Exception {
207211
}
208212
}
209213

214+
void createDoesNotAddParentDirKeys(Path grandparent) throws Exception {
215+
Path parent = new Path(grandparent, "parent");
216+
Path child = new Path(parent, "child");
217+
FileSystem fs = getFs();
218+
ContractTestUtils.touch(fs, child);
219+
220+
OzoneKeyDetails key = getKey(child, false);
221+
String expectedKeyName = getChildKeyName(child);
222+
assertEquals(key.getName(), expectedKeyName);
223+
224+
// Creating a child should not add parent keys to the bucket
225+
try {
226+
getKey(parent, true);
227+
} catch (OMException ome) {
228+
assertEquals(KEY_NOT_FOUND, ome.getResult());
229+
}
230+
231+
// List status on the parent should show the child file
232+
assertEquals(1L, fs.listStatus(parent).length, "List status of parent should include the 1 child file");
233+
assertTrue(fs.getFileStatus(parent).isDirectory(), "Parent directory does not appear to be a directory");
234+
235+
// Cleanup
236+
fs.delete(grandparent, true);
237+
}
238+
239+
abstract String getChildKeyName(Path child);
240+
241+
void listStatusIteratorOnRoot(Path root) throws Exception {
242+
Path dir1 = new Path(root, "dir1");
243+
Path dir12 = new Path(dir1, "dir12");
244+
Path dir2 = new Path(root, "dir2");
245+
FileSystem fs = getFs();
246+
try {
247+
fs.mkdirs(dir12);
248+
fs.mkdirs(dir2);
249+
250+
// ListStatusIterator on root should return dir1
251+
// (even though /dir1 key does not exist)and dir2 only.
252+
// dir12 is not an immediate child of root and hence should not be listed.
253+
RemoteIterator<FileStatus> it = fs.listStatusIterator(root);
254+
int iCount = 0;
255+
while (it.hasNext()) {
256+
iCount++;
257+
FileStatus fileStatus = it.next();
258+
assertNotNull(fileStatus);
259+
// Verify that dir12 is not included in the result
260+
// of the listStatusIterator on root.
261+
assertNotEquals(fileStatus, dir12.toString());
262+
}
263+
assertEquals(2, iCount, "FileStatus should return only the immediate children");
264+
} finally {
265+
// Cleanup
266+
fs.delete(dir2, true);
267+
fs.delete(dir1, true);
268+
}
269+
}
270+
210271
abstract OzoneKeyDetails getKey(Path keyPath, boolean isDirectory) throws IOException;
211272

212273
abstract FileSystem getFs();

0 commit comments

Comments
 (0)