dlg99 commented on code in PR #19153:
URL: https://github.com/apache/pulsar/pull/19153#discussion_r1087342514


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java:
##########
@@ -1033,17 +1047,33 @@ public CompletableFuture<Optional<Topic>> 
getTopic(final TopicName topicName, bo
                 });
             } else {
             return topics.computeIfAbsent(topicName.toString(), (name) -> {
+                topicEventsDispatcher.notify(topicName.toString(), 
TopicEvent.LOAD, EventStage.BEFORE);
                     if (topicName.isPartitioned()) {
                         final TopicName partitionedTopicName = 
TopicName.get(topicName.getPartitionedTopicName());
                         return 
this.fetchPartitionedTopicMetadataAsync(partitionedTopicName).thenCompose((metadata)
 -> {
                             if (topicName.getPartitionIndex() < 
metadata.partitions) {
-                                return createNonPersistentTopic(name);
+                                topicEventsDispatcher
+                                        .notify(topicName.toString(), 
TopicEvent.CREATE, EventStage.BEFORE);
+
+                                CompletableFuture<Optional<Topic>> res = 
createNonPersistentTopic(name);
+
+                                topicEventsDispatcher.notifyOnCompletion(res, 
topicName.toString(), TopicEvent.CREATE);
+                                topicEventsDispatcher.notifyOnCompletion(res, 
topicName.toString(), TopicEvent.LOAD);

Review Comment:
   The events come up in expected order.
   From TopicEventsListenerTest:
   ```java
       public void testEventsPersistentPartitionedTopic() throws Exception {
           String topicName = "persistent://" + namespace + "/P-NP";
           topicNameToWatch = topicName + "-partition-1";
           admin.topics().createPartitionedTopic(topicName, 2);
           triggerPartitionsCreation(topicName);
   
           Awaitility.waitAtMost(10, TimeUnit.SECONDS).untilAsserted(() ->
                   Assert.assertEquals(events.toArray(), new String[]{
                           "LOAD__BEFORE",
                           "CREATE__BEFORE",
                           "CREATE__SUCCESS",
                           "LOAD__SUCCESS"
                   })
           );
   ...
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to