-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Conversation
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
zookeeper-server/src/test/java/org/apache/zookeeper/client/ZKClientConfigTest.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/test/java/org/apache/zookeeper/common/FileChangeWatcherTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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.
zookeeper-server/src/test/java/org/apache/zookeeper/server/PrepRequestProcessorTest.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/test/java/org/apache/zookeeper/server/admin/JettyAdminServerTest.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/test/java/org/apache/zookeeper/server/controller/ControllerTestBase.java
Show resolved
Hide resolved
zookeeper-server/src/test/java/org/apache/zookeeper/server/persistence/SnapStreamTest.java
Show resolved
Hide resolved
zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/CommitProcessorTest.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/Zab1_0Test.java
Outdated
Show resolved
Hide resolved
@@ -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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Thank you, will take a look and get back on this. |
Make sure the temp directory scope is not affected.
There was a problem hiding this 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
zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/Zab1_0Test.java
Show resolved
Hide resolved
There was a problem hiding this 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
Thanks @muthu90tech , what's your jira id? |
Thanks @anmolnar , JiraID: muthu90tech |
@muthu90tech Great. Now you're a ZooKeeper contributor. ;) |
Awesome, looking forward to this! |
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
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.