Skip to content

Get rid of powermock #16912

Closed
Closed

Description

@tisonkun

In this comment #16884 (comment) 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?

Activity

  1. hezhangjian commented on Aug 2, 2022

    @hezhangjian
    Member

    I think we can simply modify the access modifiers, and mark @VisableForTesting .We have used this in many codes.

  2. tisonkun commented on Aug 2, 2022

    @tisonkun
    MemberAuthor

    @shoothzj IIUC do you suggest a replacement of powermock here?

  3. hezhangjian commented on Aug 2, 2022

    @hezhangjian
    Member

    @tisonkun Yes, I suggest to replace powermock. Using @VisableForTesting instead of reflections

  4. tisonkun commented on Aug 2, 2022

    @tisonkun
    MemberAuthor

    @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.

  5. tisonkun commented on Aug 9, 2022

    @tisonkun
    MemberAuthor

    I draft an incompleted patch on #16997.

    However, I notice that there's some code we hack in "set final" field, like:

    EntryCache entryCache = spy((EntryCache) Whitebox.getInternalState(ledger, "entryCache"));
    Whitebox.setInternalState(ledger, "entryCache", entryCache);

    .. or even "set static final" field, like:

    Whitebox.setInternalState(DirectMemoryUtils.class, "JVM_MAX_DIRECT_MEMORY", 1024L);

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions