This is an automated email from the ASF dual-hosted git repository.

penghui pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new 9c70771fcac Fix the test for cherry-picking #24825
9c70771fcac is described below

commit 9c70771fcac165d771777d7dee178d96c8dd28cc
Author: Penghui Li <[email protected]>
AuthorDate: Tue Dec 9 11:22:57 2025 -0800

    Fix the test for cherry-picking #24825
---
 .../pulsar/broker/service/PersistentTopicTest.java | 23 +++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java
 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java
index 1efc3b5c524..16dad41ba93 100644
--- 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java
@@ -135,6 +135,7 @@ import org.apache.pulsar.common.policies.data.Policies;
 import org.apache.pulsar.common.policies.data.TopicPolicies;
 import org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl;
 import org.apache.pulsar.common.protocol.ByteBufPair;
+import org.apache.pulsar.common.protocol.Commands;
 import org.apache.pulsar.common.protocol.schema.SchemaVersion;
 import org.apache.pulsar.common.semaphore.AsyncDualMemoryLimiter;
 import org.apache.pulsar.common.util.Codec;
@@ -2334,14 +2335,22 @@ public class PersistentTopicTest extends 
MockedBookKeeperTestCase {
         when(ledgerMock.getLedgersInfo()).thenReturn(new 
java.util.TreeMap<>(Map.of(1L,
                 
mock(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo.class))));
 
-        // Mock the last entry to return a timestamp
-        Entry entryMock = mock(Entry.class);
-        MessageMetadata metadata = new MessageMetadata();
-        metadata.setPublishTime(timestampFromStorage);
-        when(entryMock.getMessageMetadata()).thenReturn(metadata);
-
-        // Mock asyncReadEntry to invoke callback with the mocked entry
+        // Mock asyncReadEntry to invoke callback with a fresh entry each time
         doAnswer(invocation -> {
+            // Create a fresh entry with metadata each time this is called
+            Entry entryMock = mock(Entry.class);
+            MessageMetadata metadata = new MessageMetadata();
+            metadata.setProducerName("test-producer");
+            metadata.setSequenceId(0);
+            metadata.setPublishTime(timestampFromStorage);
+
+            // Serialize using the existing utility method
+            ByteBuf payload = Unpooled.wrappedBuffer(new byte[0]);
+            ByteBuf entryData = Commands.serializeMetadataAndPayload(
+                    Commands.ChecksumType.None, metadata, payload);
+
+            when(entryMock.getDataBuffer()).thenReturn(entryData);
+
             AsyncCallbacks.ReadEntryCallback callback = 
invocation.getArgument(1);
             callback.readEntryComplete(entryMock, null);
             return null;

Reply via email to