poorbarcode commented on code in PR #22245:
URL: https://github.com/apache/pulsar/pull/22245#discussion_r1543416791


##########
pulsar-broker/src/test/java/org/apache/pulsar/client/api/KeySharedSubscriptionTest.java:
##########
@@ -1630,4 +1637,263 @@ public void 
testContinueDispatchMessagesWhenMessageDelayed() throws Exception {
         log.info("Got {} other messages...", sum);
         Assert.assertEquals(sum, delayedMessages + messages);
     }
+
+    private AtomicInteger injectReplayReadCounter(String topicName, String 
cursorName) throws Exception {
+        PersistentTopic persistentTopic =
+                (PersistentTopic) 
pulsar.getBrokerService().getTopic(topicName, false).join().get();
+        ManagedLedgerImpl managedLedger = (ManagedLedgerImpl) 
persistentTopic.getManagedLedger();
+        ManagedCursorImpl cursor = (ManagedCursorImpl) 
managedLedger.openCursor(cursorName);
+        managedLedger.getCursors().removeCursor(cursor.getName());
+        managedLedger.getActiveCursors().removeCursor(cursor.getName());
+        ManagedCursorImpl spyCursor = Mockito.spy(cursor);
+        managedLedger.getCursors().add(spyCursor, PositionImpl.EARLIEST);
+        managedLedger.getActiveCursors().add(spyCursor, PositionImpl.EARLIEST);
+        AtomicInteger replyReadCounter = new AtomicInteger();
+        Mockito.doAnswer(invocation -> {
+            if 
(!String.valueOf(invocation.getArguments()[2]).equals("Normal")) {
+                replyReadCounter.incrementAndGet();
+            }
+            return invocation.callRealMethod();
+        }).when(spyCursor).asyncReplayEntries(Mockito.anySet(), Mockito.any(), 
Mockito.any());
+        Mockito.doAnswer(invocation -> {
+            if 
(!String.valueOf(invocation.getArguments()[2]).equals("Normal")) {
+                replyReadCounter.incrementAndGet();
+            }
+            return invocation.callRealMethod();
+        }).when(spyCursor).asyncReplayEntries(Mockito.anySet(), Mockito.any(), 
Mockito.any(), Mockito.anyBoolean());
+        admin.topics().createSubscription(topicName, cursorName, 
MessageId.earliest);
+        return replyReadCounter;
+    }
+
+    @Test
+    public void testNoRepeatedReadAndDiscard() throws Exception {
+        int delayedMessages = 100;
+        final String topic = 
BrokerTestUtil.newUniqueName("persistent://public/default/tp");
+        final String subName = "my-sub";
+        admin.topics().createNonPartitionedTopic(topic);
+        AtomicInteger replyReadCounter = injectReplayReadCounter(topic, 
subName);
+
+        // Send messages.
+        @Cleanup
+        Producer<Integer> producer = 
pulsarClient.newProducer(Schema.INT32).topic(topic).enableBatching(false).create();
+        for (int i = 0; i < delayedMessages; i++) {
+            MessageId messageId = producer.newMessage()
+                    .key(String.valueOf(random.nextInt(NUMBER_OF_KEYS)))
+                    .value(100 + i)
+                    .send();
+            log.info("Published delayed message :{}", messageId);

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to