|
25 | 25 | import java.util.HashSet; |
26 | 26 | import java.util.List; |
27 | 27 | import java.util.Map; |
| 28 | +import java.util.Optional; |
28 | 29 | import java.util.Set; |
29 | 30 | import java.util.UUID; |
30 | 31 | import java.util.concurrent.CompletableFuture; |
@@ -421,4 +422,47 @@ public void testPrepareInitPoliciesCacheAsyncWhenNamespaceBeingDeleted() throws |
421 | 422 | service.prepareInitPoliciesCacheAsync(namespaceName).get(); |
422 | 423 | admin.namespaces().deleteNamespace(NAMESPACE5); |
423 | 424 | } |
| 425 | + |
| 426 | + @Test |
| 427 | + public void testCreateNamespaceEventsSystemTopicFactoryException() throws Exception { |
| 428 | + final String namespace = "system-topic/namespace-6"; |
| 429 | + |
| 430 | + admin.namespaces().createNamespace(namespace); |
| 431 | + |
| 432 | + TopicName topicName = TopicName.get("persistent", NamespaceName.get(namespace), "topic-1"); |
| 433 | + |
| 434 | + SystemTopicBasedTopicPoliciesService service = |
| 435 | + Mockito.spy((SystemTopicBasedTopicPoliciesService) pulsar.getTopicPoliciesService()); |
| 436 | + |
| 437 | + // inject exception when create NamespaceEventsSystemTopicFactory |
| 438 | + Mockito.doThrow(new RuntimeException("test exception")).when(service) |
| 439 | + .getNamespaceEventsSystemTopicFactory(); |
| 440 | + |
| 441 | + CompletableFuture<Optional<TopicPolicies>> topicPoliciesFuture; |
| 442 | + Optional<TopicPolicies> topicPoliciesOptional; |
| 443 | + try { |
| 444 | + topicPoliciesFuture = |
| 445 | + service.getTopicPoliciesAsync(topicName, TopicPoliciesService.GetType.LOCAL_ONLY); |
| 446 | + topicPoliciesOptional = topicPoliciesFuture.join(); |
| 447 | + Assert.fail(); |
| 448 | + } catch (Exception e) { |
| 449 | + Assert.assertTrue(e.getCause().getMessage().contains("test exception")); |
| 450 | + } |
| 451 | + |
| 452 | + Mockito.reset(service); |
| 453 | + |
| 454 | + service.updateTopicPoliciesAsync(topicName, false, false, topicPolicies -> |
| 455 | + topicPolicies.setMaxConsumerPerTopic(10)).get(); |
| 456 | + |
| 457 | + topicPoliciesFuture = |
| 458 | + service.getTopicPoliciesAsync(topicName, TopicPoliciesService.GetType.LOCAL_ONLY); |
| 459 | + topicPoliciesOptional = topicPoliciesFuture.join(); |
| 460 | + |
| 461 | + Assert.assertNotNull(topicPoliciesOptional); |
| 462 | + Assert.assertTrue(topicPoliciesOptional.isPresent()); |
| 463 | + |
| 464 | + TopicPolicies topicPolicies = topicPoliciesOptional.get(); |
| 465 | + Assert.assertNotNull(topicPolicies); |
| 466 | + Assert.assertEquals(topicPolicies.getMaxConsumerPerTopic(), 10); |
| 467 | + } |
424 | 468 | } |
0 commit comments