From c66ebb5aec9c2094fccb3c7332aa2282e4a1f05c Mon Sep 17 00:00:00 2001 From: fengyubiao Date: Thu, 27 Apr 2023 03:14:36 +0800 Subject: [PATCH] improve test --- .../apache/pulsar/broker/MetadataStoreStuckTest.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/MetadataStoreStuckTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/MetadataStoreStuckTest.java index 9e128325515832..0e0529d8581fef 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/MetadataStoreStuckTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/MetadataStoreStuckTest.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import lombok.extern.slf4j.Slf4j; import org.apache.bookkeeper.client.BookKeeper; import org.apache.pulsar.broker.namespace.NamespaceEphemeralData; @@ -187,12 +188,15 @@ public void testSchemaLedgerLost() throws Exception { final NamespaceBundle bundle0 = bundles.get(0); final NamespaceBundle bundle1 = bundles.get(1); + AtomicInteger finishedTaskCount = new AtomicInteger(0); + // task: lookup. final AtomicBoolean lookupTaskRunning = new AtomicBoolean(); final Thread lookupTask = new Thread(() -> { pulsarService.getPulsarResources().getNamespaceResources().getPartitionedTopicResources() .getPartitionedTopicMetadataAsync(TopicName.get(topicName), true).join(); lookupTaskRunning.set(true); + finishedTaskCount.incrementAndGet(); }); // task: create topic. @@ -210,14 +214,15 @@ public void testSchemaLedgerLost() throws Exception { List bundleList = pulsarService.getNamespaceService().getNamespaceBundleFactory() .getBundles(namespaceName).getBundles(); log.info("get bundle list: {}", bundleList); + finishedTaskCount.incrementAndGet(); return CompletableFuture.completedFuture(res); - }).join(); + }); }); // Verify all tasks will be finished in time. createTopicTask.start(); - createTopicTask.join(); - lookupTask.join(); + + Awaitility.await().untilAsserted(() -> Assert.assertEquals(finishedTaskCount.get(), 2)); } private CompletableFuture acquiringOwnership(OwnershipCache ownershipCache,