Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
poorbarcode committed Apr 26, 2023
1 parent 05e27e0 commit c66ebb5
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -210,14 +214,15 @@ public void testSchemaLedgerLost() throws Exception {
List<NamespaceBundle> 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<NamespaceEphemeralData> acquiringOwnership(OwnershipCache ownershipCache,
Expand Down

0 comments on commit c66ebb5

Please sign in to comment.