Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZOOKEEPER-4780: Delegate temp directory creation to Junit in tests. #2100

Merged
merged 6 commits into from
Feb 9, 2024

Conversation

muthu90tech
Copy link
Contributor

@muthu90tech muthu90tech commented Dec 22, 2023

Jira: https://issues.apache.org/jira/browse/ZOOKEEPER-4780

Use Junit @tempdir annotation to manage temp directory for tests.
Junit creates the tempDir automatically and cleans them after test. Which does not clutter the src/test directories.

Use Junit @tempdir annotation to manage temp directory for tests.
There is a test which fails on the CI, but when I reran it local it passes. test=TruncateTest
Copy link
Member

@ctubbsii ctubbsii left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ztzg ztzg left a comment

Choose a reason for hiding this comment

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

LGTM, in general. A nice cleanup, indeed!

@TempDir is marked STABLE starting in JUnit 5.10, so depending on it sounds reasonable.

Some specific call sites might be worth another round of review, or perhaps even an update, though; see my individual comments.

@@ -44,11 +44,11 @@ public class QuorumAuthTestBase extends ZKTestCase {

protected static final Logger LOG = LoggerFactory.getLogger(QuorumAuthTestBase.class);
protected List<MainThread> mt = new ArrayList<>();
@TempDir
protected static File jaasConfigDir;
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. Unless I am missing something, this value is used by a static method, which is itself called by static { } blocks in derived classes. How do we know the JUnit "engine" is going to be able to initialize the field before such blocks are executed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats a great, question. I dont know.. This will need some investigation. I will look into this. Meantime I am going to revert this and avoid using the annotation only for this. But its a good deep dive I think..

Copy link
Member

Choose a reason for hiding this comment

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

Should avoid static initializer blocks in general... they make for hard-to-test code, not to mention the potential bootstrapping issue mentioned here. Should use JUnit @BeforeAll annotation to initialize static fields in test case classes, if possible, to make sure JUnit does the right thing automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created this https://issues.apache.org/jira/browse/ZOOKEEPER-4789 to work on cleaning the QuorumAuth tests.

@muthu90tech
Copy link
Contributor Author

LGTM, in general. A nice cleanup, indeed!

@TempDir is marked STABLE starting in JUnit 5.10, so depending on it sounds reasonable.

Some specific call sites might be worth another round of review, or perhaps even an update, though; see my individual comments.

Thank you, will take a look and get back on this.

Make sure the temp directory scope is not affected.
@muthu90tech muthu90tech requested a review from ztzg January 21, 2024 16:37
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

I hae left one comment about the Zab01 test, apart from that LGTM

@muthu90tech muthu90tech requested a review from eolivelli February 3, 2024 18:35
@eolivelli eolivelli requested a review from ctubbsii February 5, 2024 07:42
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

thanks for your contribution

@anmolnar anmolnar merged commit e10bf86 into apache:master Feb 9, 2024
13 checks passed
@anmolnar
Copy link
Contributor

anmolnar commented Feb 9, 2024

Thanks @muthu90tech , what's your jira id?
I'd like to add you as contributor.

@muthu90tech
Copy link
Contributor Author

Thanks @muthu90tech , what's your jira id? I'd like to add you as contributor.

Thanks @anmolnar , JiraID: muthu90tech

@anmolnar
Copy link
Contributor

anmolnar commented Feb 9, 2024

@muthu90tech Great. Now you're a ZooKeeper contributor. ;)

@muthu90tech
Copy link
Contributor Author

@muthu90tech Great. Now you're a ZooKeeper contributor. ;)

Awesome, looking forward to this!

AlphaCanisMajoris pushed a commit to AlphaCanisMajoris/zookeeper that referenced this pull request Mar 28, 2024
ZOOKEEPER-4780: Delegate temp directory creation to Junit in tests.
Use Junit @tempdir annotation to manage temp directory for tests.
Use TempDir annotation for few more tests.
Remove unusedimports
There is a test which fails on the CI, but when I reran it local it passes. test=TruncateTest
Revert TruncateTest
Address comments
Make sure the temp directory scope is not affected.
fix for ZKClientConfigTest
Reviewers: ctubbsii, eolivelli
Author: muthu90tech
Closes apache#2100 from muthu90tech/ZOOKEEPER-4780
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.

6 participants