nodece commented on PR #24939:
URL: https://github.com/apache/pulsar/pull/24939#issuecomment-3521102373

   > @coderzc Cherry-picking this test to branch-4.0 and branch-4.1 causes the 
test to fail. I had to do some modifications to make it pass.
   
   @lhotari @coderzc The same issue exists in the branch-3.0. Since the update 
and get operations has race issue, we need to use `Awaitility` to wait until 
the topic policies become available.
   
   ```java
       @Test
       public void testCreateNamespaceEventsSystemTopicFactoryException() 
throws Exception {
           final String namespace = "system-topic/namespace-6";
   
           admin.namespaces().createNamespace(namespace);
   
           TopicName topicName = TopicName.get("persistent", 
NamespaceName.get(namespace), "topic-1");
   
           SystemTopicBasedTopicPoliciesService service =
                   Mockito.spy((SystemTopicBasedTopicPoliciesService) 
pulsar.getTopicPoliciesService());
   
           // inject exception when create NamespaceEventsSystemTopicFactory
           Mockito.doThrow(new RuntimeException("test exception"))
                   .doCallRealMethod()
                   .when(service)
                   .getNamespaceEventsSystemTopicFactory();
   
           try {
               service.getTopicPoliciesAsync(topicName, false).join();
               Assert.fail();
           } catch (Exception e) {
               Assert.assertTrue(e.getCause().getMessage().contains("test 
exception"));
           }
   
           TopicPolicies updatedTopicPolicies = new TopicPolicies();
           updatedTopicPolicies.setMaxConsumerPerTopic(10);
           Awaitility.await().untilAsserted(() -> {
               assertThat(service.updateTopicPoliciesAsync(topicName, 
updatedTopicPolicies))
                       .succeedsWithin(Duration.ofSeconds(2));
           });
   
           Awaitility.await().untilAsserted(() -> {
               CompletableFuture<Optional<TopicPolicies>> topicPoliciesFuture =
                       service.getTopicPoliciesAsync(topicName, false);
               
assertThat(topicPoliciesFuture).succeedsWithin(Duration.ofSeconds(2))
                       .satisfies(n -> {
                           Assert.assertTrue(n.isPresent());
                           TopicPolicies topicPolicies = n.get();
                           Assert.assertNotNull(topicPolicies);
                           
Assert.assertEquals(topicPolicies.getMaxConsumerPerTopic(), 10);
                       });
           });
       }
   ```


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