[improve][test] Introduce shared Pulsar cluster for faster integration tests#25311
Open
merlimat wants to merge 1 commit intoapache:masterfrom
Open
[improve][test] Introduce shared Pulsar cluster for faster integration tests#25311merlimat wants to merge 1 commit intoapache:masterfrom
merlimat wants to merge 1 commit intoapache:masterfrom
Conversation
…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)
af7d783 to
7ca8614
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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,
NullValueTestpreviously 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:
SharedPulsarClusterA JVM-wide singleton that manages a lightweight Pulsar cluster:
DbLedgerStorage, no journal sync/writes, minimal RocksDB cache, andUnpooledHeapallocator for low memory footprinttest-clusterandtest-tenantpre-created at startupSharedPulsarBaseTestBase class for tests that use the shared cluster:
@BeforeClassinitializesadminandpulsarClientfrom the singleton (once per class)@BeforeMethodcreates a unique namespace per test method for full isolation@AfterMethodforce-deletes the namespace (cascading to all topics)newTopicName()helper generates unique topic names within the test namespaceConverted test
BrokerTestBasewithSharedPulsarBaseTestTest Timing
With the shared cluster,
NullValueTestruns 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):
docdoc-requireddoc-not-neededdoc-complete