Skip to content

Commit

Permalink
test code.
Browse files Browse the repository at this point in the history
  • Loading branch information
thetumbled committed Nov 14, 2024
1 parent fa42e8f commit e7f9ccb
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -356,17 +362,9 @@ public void testNegativeAcksWithBatch() throws Exception {
Thread.sleep(2000);
consumer.negativeAcknowledge(consumer.receive());

// wait for redelivery
Message<String> msg1 = consumer.receive();
long time1 = System.currentTimeMillis();
assertEquals(msg1.getValue(), "test-0");
Message<String> 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<String> msg1 = consumer.receive(2, TimeUnit.SECONDS);
assertNotNull(msg1);
}

@Test
Expand Down

0 comments on commit e7f9ccb

Please sign in to comment.