Skip to content

[improve][test] Introduce shared Pulsar cluster for faster integration tests#25311

Open
merlimat wants to merge 1 commit intoapache:masterfrom
merlimat:claude/trusting-stonebraker
Open

[improve][test] Introduce shared Pulsar cluster for faster integration tests#25311
merlimat wants to merge 1 commit intoapache:masterfrom
merlimat:claude/trusting-stonebraker

Conversation

@merlimat
Copy link
Contributor

@merlimat merlimat commented Mar 11, 2026

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

…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)
@merlimat merlimat self-assigned this Mar 11, 2026
@apache apache deleted a comment from github-actions bot Mar 11, 2026
@github-actions github-actions bot added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Mar 11, 2026
@merlimat merlimat force-pushed the claude/trusting-stonebraker branch from af7d783 to 7ca8614 Compare March 11, 2026 16:41
@codecov-commenter
Copy link

Codecov Report

✅ 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

Impacted file tree graph

@@             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     
Flag Coverage Δ
inttests 25.59% <ø> (?)
systests 22.26% <ø> (-0.09%) ⬇️
unittests 73.63% <ø> (+0.04%) ⬆️

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.

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

Labels

area/test doc-not-needed Your PR changes do not impact docs ready-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants