-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[test] Replace PowerMockito#mockStatic usages with mockito-inline #14098
[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
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.
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
pulsar-common/src/main/java/org/apache/pulsar/common/nar/NarClassLoader.java
Outdated
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.
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 |
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.
Really good work @nicoloboschi ! Awesome
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.
Great work!
+1
/pulsarbot rerun-failure-checks |
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
pulsar-common/src/main/java/org/apache/pulsar/common/protocol/Commands.java
Outdated
Show resolved
Hide resolved
pulsar-common/src/main/java/org/apache/pulsar/common/protocol/Commands.java
Outdated
Show resolved
Hide resolved
/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-opens
to 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
ClassLoader
classes 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