Skip to content

HDDS-15109. Extract rename test cases to OzoneFileSystemTests#10120

Open
len548 wants to merge 2 commits intoapache:masterfrom
len548:HDDS-12355-5
Open

HDDS-15109. Extract rename test cases to OzoneFileSystemTests#10120
len548 wants to merge 2 commits intoapache:masterfrom
len548:HDDS-12355-5

Conversation

@len548
Copy link
Copy Markdown
Contributor

@len548 len548 commented Apr 24, 2026

What changes were proposed in this pull request?

There are duplicates of rename tests between AbstractOzoneFileSystemTest and AbstractRootedOzoneFileSystemTest.

  • testRenameFile
  • testRenameFileToDir
  • testRenameToParentDir
  • testRenameDirToItsOwnSubDir
  • testRenameDestinationParentDoesntExist (O3FS) / testRenameDestinationParentDoesNotExist (OFS) – same test, different spelling.

This PR moved shared logic of these tests to OzoneFileSystemTestBase and also introduced a helper method pathUnderFsRoot(String p) which centralizes the difference “fs.getUri().toString() + path” (O3FS) vs "getBucketPath() + path" (OFS) by template method pattern.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-15109

How was this patch tested?

CI pass: https://github.com/len548/ozone/actions/runs/24833798824

@adoroszlai adoroszlai added test code-cleanup Changes that aim to make code better, without changing functionality. labels Apr 24, 2026
@adoroszlai adoroszlai requested a review from sadanand48 April 25, 2026 04:45
Copy link
Copy Markdown
Contributor

@Russole Russole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @len548 for working on this. Overall, LGTM. I just left a few minor comments.

Path filePath = pathUnderFsRoot(root + "/file1");
ContractTestUtils.touch(getFs(), filePath);
Path newDestinPath = new Path(filePath, "c");
// rename shouldthrow exception
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: there is a small typo here. "shouldthrow" should be "should throw".

Suggested change
// rename shouldthrow exception
// rename should throw exception


abstract void verifyRenameFile(Path workDir, Path expectedDest) throws IOException;

abstract Path pathUnderFsRoot(String pathUnderFsRoot) throws IOException;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could we remove throws IOException from pathUnderFsRoot? The current implementations do not seem to throw IOException, so the simpler signature may be enough.

Comment on lines +1744 to +1747
void verifyRenameFile(Path workDir, Path expectedDest) throws IOException {
FileStatus[] fStatus = getFs().listStatus(workDir);
assertEquals(1, fStatus.length, "Renamed failed");
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also verify expectedDest here, or add a short comment explaining why RootedOzoneFileSystem only checks the number of entries? Since expectedDest is passed from the base helper, skipping the path assertion looks a bit unclear to me.

assertTrue(fs.exists(expectedFilePathAfterRename), "Rename failed");
}

public void renameDirToItsOwnSubDir() throws Exception {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: would it be better to keep this helper package-private, similar to the other rename helpers?

Suggested change
public void renameDirToItsOwnSubDir() throws Exception {
void renameDirToItsOwnSubDir() throws Exception {

Copy link
Copy Markdown
Contributor

@sreejasahithi sreejasahithi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @len548 , left few minor comments

Comment on lines +1759 to +1763
@Override
Path pathUnderFsRoot(String p) {
return new Path(getBucketPath() + p);
}

Copy link
Copy Markdown
Contributor

@sreejasahithi sreejasahithi Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: parameter name does not convey any meaning , could you please change this to a descriptive name like relativePath.

Comment on lines +1122 to +1123
protected Path pathUnderFsRoot(String p) {
return new Path(getFs().getUri().toString() + p);
Copy link
Copy Markdown
Contributor

@sreejasahithi sreejasahithi Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Comment on lines +556 to +572
void renameDestinationParentDoesNotExist() throws Exception {
final String root = "/root_dir";
final String dir1 = root + "/dir1";
final String dir2 = dir1 + "/dir2";
final Path dir2SourcePath = pathUnderFsRoot(dir2);
getFs().mkdirs(dir2SourcePath);
// (a) parent of dst does not exist. /root_dir/b/c
final Path destinPath = pathUnderFsRoot(root + "/b/c");

// rename should throw exception
try {
getFs().rename(dir2SourcePath, destinPath);
fail("Should fail as parent of dst does not exist!");
} catch (FileNotFoundException fnfe) {
//expected
}
// (b) parent of dst is a file. /root_dir/file1/c
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capture FileSystem fs = getFs() once and reuse it similar to how it is done in other methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-cleanup Changes that aim to make code better, without changing functionality. test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants