[test] Replace PowerMockito#mockStatic usages with mockito-inline - #14098
Conversation
|
/pulsarbot rerun-failure-checks |
3 similar comments
|
/pulsarbot rerun-failure-checks |
|
/pulsarbot rerun-failure-checks |
|
/pulsarbot rerun-failure-checks |
f64c3bd to
e5cd5c2
Compare
eolivelli
left a comment
There was a problem hiding this comment.
Great work.
I believe we have to rework that Factory class. I found it a bit unusual. I understand that it is for Mockito but we can probably organise it better
lhotari
left a comment
There was a problem hiding this comment.
did you try Mockito.mockStatic(NarClassLoader.class, Mockito.CALLS_REAL_METHODS) ? does that help address the limitation that you were describing about not being able to mock static methods on a classloader class?
|
@lhotari thanks for the suggestion. Unfortunately it doesn't help. I inspected the |
lhotari
left a comment
There was a problem hiding this comment.
Really good work @nicoloboschi ! Awesome
|
/pulsarbot rerun-failure-checks |
|
/pulsarbot rerun-failure-checks |
3 similar comments
|
/pulsarbot rerun-failure-checks |
|
/pulsarbot rerun-failure-checks |
|
/pulsarbot rerun-failure-checks |
|
/pulsarbot rerun-failure-checks |
1 similar comment
|
/pulsarbot rerun-failure-checks |
|
/pulsarbot rerun-failure-checks |
|
@nicoloboschi - it looks like the broker test is failing with the below stack trace. I'm wondering if it is a legitimate failure and not just a flaky test. |
|
@michaeljmarshall yes you're right. I've found a couple of other tests that can't simply pass for the same reason ( |
…est - don't know how they passed before
|
/pulsarbot rerun-failure-checks |
2 similar comments
|
/pulsarbot rerun-failure-checks |
|
/pulsarbot rerun-failure-checks |
…ache#14098) * introduce NarClassLoaderBuilder since Mockito Inline cannot mock classloader classes * fix spyWithClassAndConstructorArgs(PulsarService.class, svcConfig) tests
Motivation
PowerMockito static mocks don't work well with the latest JDK class encapsulation mechanisms. The main problem is that PowerMockito, in order to mock a single static method of a class, try to setAccessible a lot of other apparently related classes. This means, starting from JDK17, you need to add
--add-opensto the Java runtime options in order to avoid runtime errors.PowerMockito development isn't much active and they don't seem to be ready for the new JDK releases.
The best replacement is to use mockito-inline (additional part of
mockito-core), which uses a different algorithm in order to mock static methods - a lot less invasive.Modifications
ClassLoaderclasses in mockito-inline. The API for the NarClassLoader is internal so no problem changing it. See https://github.com/mockito/mockito/blob/main/src/main/java/org/mockito/internal/creation/bytebuddy/InlineDelegateByteBuddyMockMaker.java#L553Documentation
no-need-doc