Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.pulsar.broker.service;

import static org.awaitility.Awaitility.await;

import java.lang.reflect.Field;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -81,7 +83,8 @@ public void testCurrentLedgerRolloverIfFull() throws Exception {
}

ManagedLedgerImpl managedLedger = (ManagedLedgerImpl) persistentTopic.getManagedLedger();
Assert.assertEquals(managedLedger.getLedgersInfoAsList().size(), msgNum / 2);
// 10 msg, 2 entries per ledger. 5 is full, another one is created. Await to avoid race condition
await().until(() -> managedLedger.getLedgersInfoAsList().size() == 6); //

for (int i = 0; i < msgNum; i++) {
Message<byte[]> msg = consumer.receive(2, TimeUnit.SECONDS);
Expand All @@ -91,7 +94,7 @@ public void testCurrentLedgerRolloverIfFull() throws Exception {

// all the messages have been acknowledged
// and all the ledgers have been removed except the the last ledger
Awaitility.await()
await()
.pollInterval(Duration.ofMillis(500L))
.untilAsserted(() -> {
Assert.assertEquals(managedLedger.getLedgersInfoAsList().size(), 1);
Expand All @@ -105,7 +108,7 @@ public void testCurrentLedgerRolloverIfFull() throws Exception {
managedLedger.rollCurrentLedgerIfFull();

// the last ledger will be closed and removed and we have one ledger for empty
Awaitility.await()
await()
.pollInterval(Duration.ofMillis(1000L))
.untilAsserted(() -> {
Assert.assertEquals(managedLedger.getLedgersInfoAsList().size(), 1);
Expand Down