From c79f9760039974fd48c4e5969239e3a29f5e1f6b Mon Sep 17 00:00:00 2001 From: Marek Czajkowski Date: Mon, 26 Aug 2024 08:46:03 +0200 Subject: [PATCH] Eliminate race condition and correct expected entries --- .../broker/service/CurrentLedgerRolloverIfFullTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/CurrentLedgerRolloverIfFullTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/CurrentLedgerRolloverIfFullTest.java index 375fe41f143cd..e0dae591c02c8 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/CurrentLedgerRolloverIfFullTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/CurrentLedgerRolloverIfFullTest.java @@ -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; @@ -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 msg = consumer.receive(2, TimeUnit.SECONDS); @@ -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); @@ -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);