Skip to content

Conversation

@raju-balpande
Copy link
Contributor

@raju-balpande raju-balpande commented Feb 1, 2024

What changes were proposed in this pull request?

Replace usage of GenericTestUtils test/temp dir methods with @TempDir in hadoop-ozone except in integration tests.

(see parent task HDDS-9103 for details)

  • The change covered..
  • Introduced local @TempDir variable in some cases.
  • Introduced global @TempDir at one location because the directory was shared among directories.
  • Removed the deletion logic of manually created temp directories.
  • Removed setup methods if it has nothing else then initializing the temp dir.

What is the link to the Apache JIRA

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

How was this patch tested?

Tested in CI-CI pipeline and a few manually.

@adoroszlai
Copy link
Contributor

adoroszlai commented Feb 1, 2024

Thanks @raju-balpande for working on this.

There are some conflicts, please merge from master.

Also, one unit test failure looks related:

Error:  Tests run: 6, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.059 s <<< FAILURE! - in org.apache.hadoop.ozone.security.TestOzoneTokenIdentifier
Error:  org.apache.hadoop.ozone.security.TestOzoneTokenIdentifier.testReadWriteInProtobuf(Path)  Time elapsed: 0.064 s  <<< ERROR!
java.io.FileNotFoundException: /tokenFile (Permission denied)
	at java.io.FileOutputStream.open0(Native Method)
	at java.io.FileOutputStream.open(FileOutputStream.java:270)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:162)
	at org.apache.hadoop.ozone.security.TestOzoneTokenIdentifier.testReadWriteInProtobuf(TestOzoneTokenIdentifier.java:255)

(Please use code formatting (enclose in `) for @TempDir and other annotations. @... is used on GitHub to "mention" others (like @raju-balpande) and we don't want to bother random folks.)

Comment on lines 98 to 100
public void init(@TempDir Path pathTestDir) throws Exception {
OzoneConfiguration configuration = new OzoneConfiguration();
testDir = GenericTestUtils.getRandomizedTestDir();
testDir = pathTestDir.toFile();
Copy link
Contributor

Choose a reason for hiding this comment

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

testDir can be annotated directly, then we don't need the parameter and the assignment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. thanks.

private KeyManagerImpl keyManager;

private Instant startDate;
private File testDir;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can keep and annotate it, instead of adding parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not used anywhere else hence added as a parameter instead of keeping as instance variable. It is also removed from the method cleanup.

Comment on lines 66 to 67
@BeforeAll public static void setUp() throws Exception {
File base = new File(BASEDIR);
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we can minimize change by adding @TempDir File base as parameter, instead of adding a member variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. thanks.

public void testReadWriteInProtobuf(@TempDir Path baseDir) throws IOException {
OzoneTokenIdentifier id = getIdentifierInst();
File idFile = new File(BASEDIR + "/tokenFile");
File idFile = baseDir.resolve("/tokenFile").toFile();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think test failure is caused by /tokenFile being resolved as absolute path, not a child of baseDir.

Suggested change
File idFile = baseDir.resolve("/tokenFile").toFile();
File idFile = baseDir.resolve("tokenFile").toFile();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. thanks.

@adoroszlai
Copy link
Contributor

hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshotManager.java
 210: 'testDir' hides a field.
 361: 'testDir' hides a field.
 452: 'testDir' hides a field.
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/security/acl/TestVolumeOwner.java
 39: Unused import - org.apache.hadoop.security.authentication.client.AuthenticationException.
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/security/acl/TestParentAcl.java
 46: Unused import - org.apache.hadoop.security.authentication.client.AuthenticationException.

https://github.com/raju-balpande/apache_ozone/actions/runs/7741058283/job/21107319150

@adoroszlai adoroszlai merged commit d5742ef into apache:master Feb 1, 2024
@adoroszlai
Copy link
Contributor

Thanks @raju-balpande for the patch.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants