[fix][test] Fix flaky ReplicatorTest.testReplicatorClearBacklog NPE on inFlightTask#25691
Merged
merlimat merged 1 commit intoapache:masterfrom May 6, 2026
Merged
Conversation
…n inFlightTask After apache#25625 (`Replication is stuck because failed to read entries`), `PersistentReplicator.readEntriesFailed` casts the `ctx` argument to `InFlightTask` and calls `setEntries(Collections.emptyList())` on it. `ReplicatorTest.testReplicatorClearBacklog` and `testReplicatorExpireMsgAsync` were calling that method directly with a `null` context as a shortcut, which now NPEs: ``` java.lang.NullPointerException: Cannot invoke ".InFlightTask.setEntries(...)" because "inFlightTask" is null at o.a.p.b.s.persistent.PersistentReplicator.readEntriesFailed(...) at o.a.p.b.s.ReplicatorTest.testReplicatorClearBacklog(ReplicatorTest.java:666) ``` Pass a real `InFlightTask` instead. `InFlightTask` is `protected` in `PersistentReplicator` and cannot be instantiated from the `o.a.p.b.s` package, so route construction through a new helper on `BrokerServicePersistInternalMethodInvoker` (which is already used to expose package-private replicator internals to tests).
dao-jun
approved these changes
May 6, 2026
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
After #25625 (
Replication is stuck because failed to read entries),PersistentReplicator.readEntriesFailednow casts thectxargument toInFlightTaskand callssetEntries(Collections.emptyList())on it.ReplicatorTest.testReplicatorClearBacklogandtestReplicatorExpireMsgAsyncwere calling that method directly with a `null` context as a shortcut, which now NPEs:Failing test scan: https://scans.gradle.com/s/lg3litw5ckegw/tests/task/:pulsar-broker:test/details/org.apache.pulsar.broker.service.ReplicatorTest/testReplicatorClearBacklog/2/output
Modifications
Pass a real
InFlightTaskinstance instead ofnull.InFlightTaskisprotectedinPersistentReplicatorand cannot be instantiated from theorg.apache.pulsar.broker.servicepackage directly, so the construction is routed through a new helper onBrokerServicePersistInternalMethodInvoker— which is already used to expose other package-private replicator internals to tests.Same fix is applied to
testReplicatorExpireMsgAsync, which uses the identical pattern.Verifying this change
ReplicatorTest.testReplicatorClearBacklogandtestReplicatorExpireMsgAsyncpass locally with the change.Does this pull request potentially affect one of the following parts: