[ Issues 10786 ] Fixed flaky test testTransactionMetaStoreAssignAndFailover
Fixes
Master Issue:
Motivation
Fixed flaky test.
Modifications
Replaced check after sleep to `untilAsserted` and extended `atMost` time to 10 seconds(default of Awaitility)
@@ -20,6 +20,7 @@ package org.apache.pulsar.broker.transaction.coordinator;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.apache.pulsar.broker.PulsarService;
import org.awaitility.Awaitility;
@@ -32,12 +33,13 @@ public class TransactionMetaStoreAssignmentTest extends TransactionMetaStoreTest
@Test(groups = "broker")
public void testTransactionMetaStoreAssignAndFailover() throws IOException {
- int transactionMetaStoreCount = 0;
- for (PulsarService pulsarService : pulsarServices) {
- transactionMetaStoreCount += pulsarService.getTransactionMetadataStoreService().getStores().size();
- }
-
+ Awaitility.await()
+ .untilAsserted(() -> {
+ int transactionMetaStoreCount = Arrays.stream(pulsarServices)
+ .mapToInt(pulsarService -> pulsarService.getTransactionMetadataStoreService().getStores().size())
+ .sum();
Assert.assertEquals(transactionMetaStoreCount, 16);
+ });
PulsarService crashedMetaStore = null;
for (int i = pulsarServices.length - 1; i >= 0; i--) {
@@ -62,16 +64,11 @@ public class TransactionMetaStoreAssignmentTest extends TransactionMetaStoreTest
Awaitility.await()
.untilAsserted(() -> {
-
- int transactionMetaStoreCount2 = 0;
- for (PulsarService pulsarService : pulsarServices) {
- transactionMetaStoreCount2 += pulsarService.getTransactionMetadataStoreService().getStores()
- .size();
- }
-
+ int transactionMetaStoreCount2 = Arrays.stream(pulsarServices)
+ .mapToInt(pulsarService -> pulsarService.getTransactionMetadataStoreService().getStores().size())
+ .sum();
Assert.assertEquals(transactionMetaStoreCount2, 16);
});
-
transactionCoordinatorClient.close();
}
}
