eolivelli commented on a change in pull request #9565:
URL: https://github.com/apache/pulsar/pull/9565#discussion_r574562215



##########
File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java
##########
@@ -1005,4 +1005,33 @@ public void generate(SimpleTextOutputStream stream) {
         }
         Assert.assertTrue(sb.toString().contains("test_metrics"));
     }
+
+    @Test(timeOut = 20000L)
+    public void shouldNotPreventCreatingTopicWhenNonexistingTopicIsCached() 
throws Exception {
+        // run multiple iterations to increase the chance of reproducing a 
race condition in the topic cache
+        for (int i = 0; i < 100; i++) {
+            final String topicName = 
"persistent://prop/ns-abc/topic-caching-test-topic" + i;
+            CountDownLatch latch = new CountDownLatch(1);
+            Thread getStatsThread = new Thread(() -> {
+                try {
+                    latch.countDown();
+                    // create race condition with a short delay
+                    // the bug might not reproduce in all environments, this 
works at least on i7-10750H CPU
+                    Thread.sleep(1);
+                    admin.topics().getStats(topicName);
+                    fail("The topic should not exist yet.");
+                } catch (PulsarAdminException.NotFoundException e) {
+                    // expected exception
+                } catch (PulsarAdminException | InterruptedException e) {
+                    e.printStackTrace();

Review comment:
       Nit: use Logger?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to