question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get rid of powermock

See original GitHub issue

In this comment https://github.com/apache/pulsar/pull/16884#issuecomment-1201512995 I wrote:

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.

WDTY @merlimat @lhotari @codelipenghui @nicoloboschi?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tisonkuncommented, 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 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.

0reactions
tisonkuncommented, Sep 2, 2022

I draft an incompleted patch on #16997.

However, I notice that there’s some code we hack in “set final” field, like:

https://github.com/apache/pulsar/blob/21634edd30bbe33d231ec73e8045d7666a8ad366/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java#L1071-L1072

… or even “set static final” field, like:

https://github.com/apache/pulsar/blob/21634edd30bbe33d231ec73e8045d7666a8ad366/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/thread/ThreadRuntimeFactoryTest.java#L111

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.

cc @Shoothzj @eolivelli @nicoloboschi

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to mock static method without powermock - Stack Overflow
So: if you can get rid of the static call (even when just using the workaround suggested in the other answer) - all...
Read more >
Remove powermock · Issue #6439 - GitHub
If that isn't acceptable, the next best thing is to completely isolate powermock tests to their own class(es) but this probably won't solve...
Read more >
Mockito Mock Static Method - PowerMock - DigitalOcean
Hello Pankaj , For mocking static methods , if we use PowerMockito , it will increse the memory consumption and soon we will...
Read more >
Mocking Static Methods With Mockito - Baeldung
In this tutorial, we'll take a look at how we can now mock static methods using the latest version of Mockito. To learn...
Read more >
[powermock] Using PowerMock for mocking static properties ...
If I remove @InjectMocks, remove the TestController instantiation on definition, and do controllerUT = new TestController() in the test function, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found