GeezerVison is showing github.com — [improve][test] Introduce shared Pulsar cluster for faster integration tests by merlimat · Pull Request #25311 · apache/pulsar
Conversation
merlimat
commented
Mar 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Motivation
Many broker integration tests start a full Pulsar service (broker + bookie + metadata store) per test class — or even per test method. This is extremely slow and resource-intensive. For example, NullValueTest previously took ~31 seconds, with almost all of that time spent on service startup and shutdown rather than the actual test logic.
Modifications
Introduces two new test infrastructure classes:
SharedPulsarCluster
A JVM-wide singleton that manages a lightweight Pulsar cluster:
- Single bookie with
DbLedgerStorage, no journal sync/writes, minimal RocksDB cache, and UnpooledHeap allocator for low memory footprint
- Single broker with in-memory metadata store (no ZooKeeper dependency)
- JVM shutdown hook that closes everything and deletes all temporary bookie data directories
- Default
test-cluster and test-tenant pre-created at startup
SharedPulsarBaseTest
Base class for tests that use the shared cluster:
@BeforeClass initializes admin and pulsarClient from the singleton (once per class)
@BeforeMethod creates a unique namespace per test method for full isolation
@AfterMethod force-deletes the namespace (cascading to all topics)
newTopicName() helper generates unique topic names within the test namespace
Converted test
- NullValueTest — first proof-of-concept conversion, replacing
BrokerTestBase with SharedPulsarBaseTest
Test Timing
With the shared cluster, NullValueTest runs in ~4 seconds (including ~3s singleton init on first use), compared to ~31 seconds when it started its own service.
Verifying this change
All 8 test invocations pass (4 test methods × 2 data provider params):
mvn test -pl pulsar-broker -Dtest=NullValueSharedTest -DfailIfNoTests=false
-
doc
-
doc-required
-
doc-not-needed
-
doc-complete
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…integration tests
Many broker integration tests start a full Pulsar service (broker + bookie +
metadata store) per test class or even per test method. This is extremely
slow and resource-intensive — for example, NullValueTest previously took
~31 seconds, with almost all of that time spent on service startup/shutdown.
This change introduces SharedPulsarCluster, a JVM-wide singleton that
starts a single lightweight Pulsar cluster (one bookie, one broker, in-memory
metadata store) and reuses it across all tests that extend SharedPulsarBaseTest.
Each test method gets its own namespace (created in @BeforeMethod, force-deleted
in @AfterMethod) for full isolation without the startup overhead.
Key design decisions:
- In-memory metadata store (no ZooKeeper dependency)
- Single bookie with DbLedgerStorage, no journal sync/writes, minimal
RocksDB cache, and UnpooledHeap allocator for low memory footprint
- JVM shutdown hook deletes all temporary bookie data directories
- Per-test namespace isolation with force-delete cleanup
- PulsarAdmin and PulsarClient initialized once per test class
NullValueTest is converted as the first proof-of-concept:
- Before: ~31s (full service start/stop per class)
- After: ~4s (~3s for singleton init on first use, amortized across classes)
|
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.66%. Comparing base (6c357f6) to head (7ca8614).
Additional details and impacted files

@@ Coverage Diff @@
## master #25311 +/- ##
============================================
+ Coverage 72.54% 72.66% +0.12%
+ Complexity 34627 34242 -385
============================================
Files 1967 1967
Lines 156326 156326
Branches 17812 17812
============================================
+ Hits 113409 113598 +189
+ Misses 33814 33652 -162
+ Partials 9103 9076 -27
Flags with carried forward coverage won't be shown. Click here to find out more.
see 89 files with indirect coverage changes
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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. Just added a comment of later reuse in Junit Jupiter tests
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Add convenience methods to SharedPulsarBaseTest for accessing broker internals
(getConfig, getBrokerServiceUrl, getWebServiceUrl, newPulsarClient, getSchemaStorage,
getTopicReference, getTopic, getTopicIfExists) needed by converted test classes.
Tune SharedPulsarCluster: increase BK cache/write-buffer sizes to avoid
flaky failures under load and disable inactive topic deletion.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
lhotari
lhotari approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|