From e7f9ccb0ec7bd8c444ad986fcdd493c4e06b4c6c Mon Sep 17 00:00:00 2001 From: thetumbled <843221020@qq.com> Date: Thu, 14 Nov 2024 14:20:26 +0800 Subject: [PATCH] test code. --- .../pulsar/client/impl/NegativeAcksTest.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/NegativeAcksTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/NegativeAcksTest.java index 56fe33b94dded..382e7e16f018e 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/NegativeAcksTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/NegativeAcksTest.java @@ -19,6 +19,7 @@ package org.apache.pulsar.client.impl; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; import java.util.HashSet; @@ -324,6 +325,11 @@ public void testNegativeAcksDeleteFromUnackedTracker() throws Exception { negativeAcksTracker.close(); } + /** + * If we nack multiple messages in the same batch with different redelivery delays, the messages should be redelivered + * with the correct delay. However, all messages are redelivered at the same time. + * @throws Exception + */ @Test public void testNegativeAcksWithBatch() throws Exception { cleanup(); @@ -356,17 +362,9 @@ public void testNegativeAcksWithBatch() throws Exception { Thread.sleep(2000); consumer.negativeAcknowledge(consumer.receive()); - // wait for redelivery - Message msg1 = consumer.receive(); - long time1 = System.currentTimeMillis(); - assertEquals(msg1.getValue(), "test-0"); - Message msg2 = consumer.receive(); - long time2 = System.currentTimeMillis(); - assertEquals(msg2.getValue(), "test-1"); - - // assert that the time duration between the two messages is greater than 1s, - // as the second nack is called 2s after the first nack - assertTrue(time2 - time1 >= 1000); + // now 2s has passed, the first message should be redelivered 1s later. + Message msg1 = consumer.receive(2, TimeUnit.SECONDS); + assertNotNull(msg1); } @Test