CalvinKirs commented on a change in pull request #6130:
URL: https://github.com/apache/dolphinscheduler/pull/6130#discussion_r706328826
##########
File path:
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HadoopUtils.java
##########
@@ -90,16 +90,27 @@ public HadoopUtils load(String key) throws Exception {
private Configuration configuration;
private FileSystem fs;
- private HadoopUtils() {
+ private HadoopUtils(boolean initial) {
+ if (!initial) {
+ return;
+ }
init();
initHdfsPath();
}
+ private HadoopUtils() {
+ this(true);
+ }
+
public static HadoopUtils getInstance() {
return cache.getUnchecked(HADOOP_UTILS_KEY);
}
+ public static HadoopUtils getInstanceForTest() {
+ return new HadoopUtils(false);
+ }
+
Review comment:
An important factor in unit testing is structuring your code so that it
is suitable for testing. code with excessive static initialization is not a
structure that's easily tested. Even you can see that the famous Mockito does
not support static method testing so far, my suggestion is You refactor the
code and give up the use of static methods. this scenario is not applicable. we
cannot use mocks to complete the mocks of external components.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]