-
Notifications
You must be signed in to change notification settings - Fork 5k
[Improvement][Test] Fully remove the usage of powermock from the whole project #12244
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
Conversation
| import org.junit.After; | ||
| import org.junit.Test; | ||
| import org.powermock.reflect.Whitebox; | ||
| import org.springframework.test.util.ReflectionTestUtils; |
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.
@kezhenxu94 @ruanwenjun @caishunfeng @SbloodyS Currently springframework.test.util.ReflectionTestUtils is the only thing I find that could replace powermock.reflect.Whitebox. However, it could not modify final field. That's why I remove final keyword of KUBERNETES_MODE in Constant.java. I'm not sure whether there is a better way.
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.
You don't need to set that field. You can use https://github.com/stefanbirkner/system-rules to mock the system env used here
Line 800 in 66958b9
| public static final boolean KUBERNETES_MODE = !StringUtils.isEmpty(System.getenv("KUBERNETES_SERVICE_HOST")) |
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.
You don't need to set that field. You can use https://github.com/stefanbirkner/system-rules to mock the system env used here
Line 800 in 66958b9
public static final boolean KUBERNETES_MODE = !StringUtils.isEmpty(System.getenv("KUBERNETES_SERVICE_HOST")) .
Thanks for the help. I will take a look into it : )
| jamon-runtime-2.3.1.jar | ||
| janino-3.0.16.jar | ||
| javassist-3.27.0-GA.jar | ||
| javassist-3.26.0-GA.jar |
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.
Can we keep the newer version of this.
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.
A bit wired that I didn't touch anything related to this dependency, but somehow CI detected we have both javassist-3.27.0-GA.jar
and javassist-3.26.0-GA.jar and failed. I checked the dependency tree and found org.reflections depends on javassist-3.26.0-GA.jar but com.cronutils depends on javassist-3.27.0-GA.jar.
At first, I made them both depend on javassist-3.27.0-GA.jar but RpcTest.java failed with message like :
java.lang.RuntimeException: Timeout exception. Request id: 1. Request class name: IUserService. Request method: hi
at org.apache.dolphinscheduler.rpc.future.RpcFuture.get(RpcFuture.java:67)
at org.apache.dolphinscheduler.rpc.remote.NettyClient.sendMsg(NettyClient.java:220)
at org.apache.dolphinscheduler.rpc.client.ConsumerInterceptor.intercept(ConsumerInterceptor.java:72)
at org.apache.dolphinscheduler.rpc.IUserService$ByteBuddy$YDGonXwq.hi(Unknown Source)
at org.apache.dolphinscheduler.rpc.RpcTest.sendTest(RpcTest.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
After that, I made them depend on javassist-3.26.0-GA.jar and things looked fine.
Just now I checked the changes in https://github.com/ronmamo/reflections repo and found they skipped javassist-3.27.0-GA.jar, I assume that there could be some incompatibilities between reflections and javassist-3.27.0-GA.jar, see: ronmamo/reflections@0.9.12...0.10
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.
The latest version of org.reflections is 0.10.2, which depends on javassist-3.28.0-GA.jar. I'm going to upgrade it and rerun the CI to see if things work.
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.
Still not working. Seems we have 3 methods to solve this:
-
Method 1: Downgrade javassist to
3.26.0-GA.jar, this version works well as I have tested. -
Method 2: Keep things the way it was, which means
org.reflectionsdepends onjavassist-3.26.0-GA.jarandcom.cronutilsdepends onjavassist-3.27.0-GA.jarand we add both versions totools/dependencies/known-dependencies.txt -
Method 3: Upgrade
org.reflectionsto version0.10.2and make bothorg.reflectionsandcom.cronutilsdepend onjavassist-3.28.0-GA.jar. For this method, we need to solve the NullPointerException for this line of code:Line 84 in 165b9a5
Object object = serviceClass.newInstance();
@kezhenxu94 @ruanwenjun WDYT?
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'd always prefer newer versions of dependencies so method 3 is my preference. 😄
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'd always prefer newer versions of dependencies so method 3 is my preference. 😄
Got it.
Codecov Report
@@ Coverage Diff @@
## dev #12244 +/- ##
============================================
- Coverage 39.68% 38.54% -1.14%
+ Complexity 4207 4078 -129
============================================
Files 1021 1023 +2
Lines 38242 38267 +25
Branches 4394 4391 -3
============================================
- Hits 15175 14751 -424
- Misses 21315 21793 +478
+ Partials 1752 1723 -29
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
Pretty wired. I could not pass |
|
SonarCloud Quality Gate failed. |
@kezhenxu94 Fixed, thanks for the help : ) |
kezhenxu94
left a comment
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
…e project (apache#12244) * Fully remove the usage of powermock from the whole project * Upgrade org.reflections to 0.10.12
…e project (apache#12244) * Fully remove the usage of powermock from the whole project * Upgrade org.reflections to 0.10.12








Purpose of the pull request
Brief change log
Powermockfrom the whole project.Verify this pull request