GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [improve][test] Support decorating topic, subscription, dispatcher, ManagedLedger and ManagedCursors instances in tests by lhotari · Pull Request #23892 · apache/pulsar

Conversation

@lhotari

@lhotari lhotari commented Jan 24, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Motivation

In some Pulsar tests, there's a need to inject special behaviors such as delays, race conditions or failures.
The current solutions require using reflection and replacing instances, which results in hard to maintain test code.

Modifications

  • Add a solution for Pulsar broker tests that allows to decorate persistent topics, subscriptions, dispatchers
    managed ledger factory, managed ledger and managed cursor instances.
  • Refactor production code so that there are hooks for intercepting the instances in subclasses
  • Add a helper methods for creating a Mockito Spy decorator
    • for a dispatcher instance
    • for a ManagedCursorImpl instance

example usage for spying on a dispatcher and cursor instance:

    @Override
    protected void doInitConf() throws Exception {
        super.doInitConf();
        BrokerTestInterceptor.INSTANCE.configure(conf);
    }

    @AfterMethod(alwaysRun = true)
    protected void resetInterceptors() throws Exception {
        BrokerTestInterceptor.INSTANCE.reset();
    }

    @Test
    public void testSomething() throws Exception {
        BrokerTestInterceptor.INSTANCE.applyDispatcherSpyDecorator(PersistentDispatcherMultipleConsumers.class,
                spy -> {
                    doAnswer(invocation -> {
                        List<Entry> entries = invocation.getArgument(0);
                        log.info("intercepted readEntriesComplete with {} entries", entries.size());
                        return invocation.callRealMethod();
                    }).when(spy).readEntriesComplete(any(), any());
                }
        );

        BrokerTestInterceptor.INSTANCE.applyCursorSpyDecorator(spy -> {
            doAnswer(invocation -> {
                log.info("intercepted asyncReadEntriesWithSkipOrWait");
                return invocation.callRealMethod();
            }).when(spy).asyncReadEntriesWithSkipOrWait(anyInt(), anyLong(), any(), any(), any(), any());
            doAnswer(invocation -> {
                log.info("intercepted asyncReplayEntries");
                return invocation.callRealMethod();
            }).when(spy).asyncReplayEntries(any(), any(), any(), anyBoolean());
        });
   ...

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lhotari lhotari added area/test ready-to-test labels Jan 24, 2025
@lhotari lhotari added this to the 4.1.0 milestone Jan 24, 2025
@lhotari lhotari self-assigned this Jan 24, 2025
@lhotari
lhotari requested review from BewareMyPower, nodece and poorbarcode January 24, 2025 17:25
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Jan 24, 2025
@lhotari
lhotari requested review from Technoboy-, merlimat and nicoloboschi January 24, 2025 17:25
lhotari added 2 commits January 24, 2025 21:03
@lhotari
Add solution for intercepting topic, subscription and dispatcher inst…
92dc47f
…ances in tests
@lhotari
Add ManagedLedger and ManagedCursor intercepting support
c448596
@lhotari
lhotari force-pushed the lh-add-broker-test-interceptor branch from 4a80067 to c448596 Compare January 24, 2025 19:39
@lhotari lhotari changed the title [improve][test] Add solution for intercepting topic, subscription and dispatcher instances in tests [improve][test] Support decorating topic, subscription, dispatcher, ManagedLedger and ManagedCursors instances in tests Jan 24, 2025
@codecov-commenter

codecov-commenter commented Jan 24, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 86.66667% with 6 lines in your changes missing coverage. Please review.

Project coverage is 74.22%. Comparing base (bbc6224) to head (c448596).
Report is 868 commits behind head on master.

Files with missing lines Patch % Lines
...ker/service/persistent/PersistentSubscription.java 84.84% 3 Missing and 2 partials ⚠️
...org/apache/pulsar/broker/service/TopicFactory.java 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #23892      +/-   ##
============================================
+ Coverage     73.57%   74.22%   +0.65%     
+ Complexity    32624    32244     -380     
============================================
  Files          1877     1854      -23     
  Lines        139502   143640    +4138     
  Branches      15299    16318    +1019     
============================================
+ Hits         102638   106619    +3981     
+ Misses        28908    28648     -260     
- Partials       7956     8373     +417     
Flag Coverage Δ
inttests 26.64% <51.11%> (+2.06%) ⬆️
systests 23.17% <60.00%> (-1.15%) ⬇️
unittests 73.75% <86.66%> (+0.90%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...kkeeper/mledger/impl/ManagedLedgerFactoryImpl.java 59.04% <100.00%> (-22.34%) ⬇️
...che/bookkeeper/mledger/impl/ManagedLedgerImpl.java 82.11% <100.00%> (+1.45%) ⬆️
...ache/pulsar/broker/ManagedLedgerClientFactory.java 86.20% <100.00%> (+2.06%) ⬆️
...sar/broker/service/persistent/PersistentTopic.java 79.69% <ø> (+1.23%) ⬆️
...org/apache/pulsar/broker/service/TopicFactory.java 0.00% <0.00%> (ø)
...ker/service/persistent/PersistentSubscription.java 76.67% <84.84%> (-0.02%) ⬇️

... and 1021 files with indirect coverage changes

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lhotari lhotari mentioned this pull request Jan 24, 2025
[fix][broker] Apply dispatcherMaxReadSizeBytes also for replay reads for Shared and Key_Shared subscriptions #23894
Merged
1 of 4 tasks
@lhotari
lhotari requested a review from heesung-sohn January 24, 2025 22:04
@lhotari lhotari mentioned this pull request Jan 24, 2025
[fix][broker] Fix repeatedly acquired pending reads quota #23869
Merged
1 of 4 tasks
heesung-sohn
heesung-sohn approved these changes Jan 24, 2025
View reviewed changes
Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentSubscription.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@lhotari
lhotari merged commit 2a9d4ac into apache:master Jan 25, 2025
@lhotari lhotari added the release/4.0.3 label Jan 27, 2025
lhotari added a commit that referenced this pull request Jan 27, 2025
@lhotari
[improve][test] Support decorating topic, subscription, dispatcher, M…
5543857
…anagedLedger and ManagedCursors instances in tests (#23892)

(cherry picked from commit 2a9d4ac)
@lhotari lhotari added the cherry-picked/branch-4.0 label Jan 27, 2025
@lhotari lhotari mentioned this pull request Jan 28, 2025
[fix][broker Fix bug in RangeCache where different instance of the key wouldn't ever match #23903
Merged
1 of 4 tasks
hanmz pushed a commit to hanmz/pulsar that referenced this pull request Feb 12, 2025
@lhotari hanmz
[improve][test] Support decorating topic, subscription, dispatcher, M…
d403ba4
…anagedLedger and ManagedCursors instances in tests (apache#23892)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@heesung-sohn heesung-sohn heesung-sohn approved these changes
@nodece nodece Awaiting requested review from nodece
@BewareMyPower BewareMyPower Awaiting requested review from BewareMyPower
@poorbarcode poorbarcode Awaiting requested review from poorbarcode
@Technoboy- Technoboy- Awaiting requested review from Technoboy-
@merlimat merlimat Awaiting requested review from merlimat
@nicoloboschi nicoloboschi Awaiting requested review from nicoloboschi

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@lhotari lhotari

Labels

area/test cherry-picked/branch-4.0 doc-not-needed Your PR changes do not impact docs ready-to-test release/4.0.3

Projects

None yet

Milestone

4.1.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@lhotari @codecov-commenter @heesung-sohn
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.