You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't like powermock as it lacks maintenance. It seems all usage of powermock is Whitebox. We can get rid of it with simple reflections. This can be a separate issue, though.
Thus I file this issue to investigate whether we can remove powermock from our testing framework.
@shoothzj thank you. I'll consider this approach when protptyping. There're some cases we try to hijack third-party lib's field, like eventLoopGroup in bookkeeper code. In those situations, we should still use reflections. (... or patching upstream, or change testing logics)
But yes, we can use multiple alternatives properly in each concrete case.
It seems powermock-reflect is the best library existing to handle these cases since JDK12+ it's banned changing final field instead you have to use Unsafe. I tend not to maintain such unsafe hacks within Pulsar codebase. And perhaps we should gradually refactor code to avoid depending on such manners.
Activity
hezhangjian commentedon Aug 2, 2022
I think we can simply modify the access modifiers, and mark
@VisableForTesting.We have used this in many codes.tisonkun commentedon Aug 2, 2022
@shoothzj IIUC do you suggest a replacement of powermock here?
hezhangjian commentedon Aug 2, 2022
@tisonkun Yes, I suggest to replace powermock. Using
@VisableForTestinginstead of reflectionstisonkun commentedon Aug 2, 2022
@shoothzj thank you. I'll consider this approach when protptyping. There're some cases we try to hijack third-party lib's field, like
eventLoopGroupin bookkeeper code. In those situations, we should still use reflections. (... or patching upstream, or change testing logics)But yes, we can use multiple alternatives properly in each concrete case.
tisonkun commentedon Aug 9, 2022
I draft an incompleted patch on #16997.
However, I notice that there's some code we hack in "set final" field, like:
pulsar/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java
Lines 1071 to 1072 in 21634ed
.. or even "set static final" field, like:
pulsar/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/thread/ThreadRuntimeFactoryTest.java
Line 111 in 21634ed
It seems
powermock-reflectis the best library existing to handle these cases since JDK12+ it's banned changingfinalfield instead you have to useUnsafe. I tend not to maintain such unsafe hacks within Pulsar codebase. And perhaps we should gradually refactor code to avoid depending on such manners.cc @shoothzj @eolivelli @nicoloboschi
[improve][test] force initialize field to avoid polluted by mocks (#1…
[improve][test] replace Whitebox with testing elements (#17334)
[improve][test] replace Whitebox with testing elements (apache#17334)
[improve][misc] reduce WhiteBox usage (#17578)
[improve][test] Remove WhiteBox for ElasticSearchSinkTests (#17582)
[improve][test] force initialize field to avoid polluted by mocks (#1…
[improve][test] Remove WhiteBox for ElasticSearchSinkTests (apache#17582
[improve][test] Remove WhiteBox for ElasticSearchSinkTests (apache#17582
[improve][test] force initialize field to avoid polluted by mocks (#1…
[improve][test] force initialize field to avoid polluted by mocks (ap…
[improve][test] force initialize field to avoid polluted by mocks (ap…
[improve][test] Remove WhiteBox for ElasticSearchSinkTests (#17582)