Skip to content

[fix][test] Fix flaky ReplicatorTest.testReplicatorClearBacklog NPE on inFlightTask#25691

Merged
merlimat merged 1 commit intoapache:masterfrom
merlimat:fix/flaky-replicator-test-clear-backlog
May 6, 2026
Merged

[fix][test] Fix flaky ReplicatorTest.testReplicatorClearBacklog NPE on inFlightTask#25691
merlimat merged 1 commit intoapache:masterfrom
merlimat:fix/flaky-replicator-test-clear-backlog

Conversation

@merlimat
Copy link
Copy Markdown
Contributor

@merlimat merlimat commented May 5, 2026

Motivation

After #25625 (Replication is stuck because failed to read entries), PersistentReplicator.readEntriesFailed now 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(java.util.List)" because "inFlightTask" is null
    at o.a.p.b.s.persistent.PersistentReplicator.readEntriesFailed(PersistentReplicator.java:518)
    at o.a.p.b.s.ReplicatorTest.testReplicatorClearBacklog(ReplicatorTest.java:666)

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 InFlightTask instance instead of null. InFlightTask is protected in PersistentReplicator and cannot be instantiated from the org.apache.pulsar.broker.service package directly, so the construction is routed through a new helper on BrokerServicePersistInternalMethodInvoker — 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.testReplicatorClearBacklog and testReplicatorExpireMsgAsync pass locally with the change.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API: no
  • The schema: no
  • The default values of configurations: no
  • The threading model: no
  • The binary protocol: no
  • The REST endpoints: no
  • The admin CLI options: no
  • The metrics: no
  • Anything that affects deployment: no

…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).
@merlimat merlimat merged commit 2618249 into apache:master May 6, 2026
44 checks passed
@merlimat merlimat deleted the fix/flaky-replicator-test-clear-backlog branch May 6, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants