Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public void addOwnedNamespaceBundleAsync(NamespaceBundle namespaceBundle) {
// Read policies in background
.thenAccept(__ -> readMorePoliciesAsync(reader));
});
initFuture.exceptionally(ex -> {
initFuture.exceptionallyAsync(ex -> {
try {
if (closed.get()) {
return null;
Expand All @@ -601,7 +601,7 @@ public void addOwnedNamespaceBundleAsync(NamespaceBundle namespaceBundle) {
namespace, cleanupEx);
}
return null;
});
}, pulsarService.getExecutor());
// let caller know we've got an exception.
return initFuture;
}).thenApply(__ -> true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -421,4 +422,47 @@ public void testPrepareInitPoliciesCacheAsyncWhenNamespaceBeingDeleted() throws
service.prepareInitPoliciesCacheAsync(namespaceName).get();
admin.namespaces().deleteNamespace(NAMESPACE5);
}

@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")).when(service)
.getNamespaceEventsSystemTopicFactory();

CompletableFuture<Optional<TopicPolicies>> topicPoliciesFuture;
Optional<TopicPolicies> topicPoliciesOptional;
try {
topicPoliciesFuture =
service.getTopicPoliciesAsync(topicName, TopicPoliciesService.GetType.LOCAL_ONLY);
topicPoliciesOptional = topicPoliciesFuture.join();
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e.getCause().getMessage().contains("test exception"));
}

Mockito.reset(service);

service.updateTopicPoliciesAsync(topicName, false, false, topicPolicies ->
topicPolicies.setMaxConsumerPerTopic(10)).get();

topicPoliciesFuture =
service.getTopicPoliciesAsync(topicName, TopicPoliciesService.GetType.LOCAL_ONLY);
topicPoliciesOptional = topicPoliciesFuture.join();

Assert.assertNotNull(topicPoliciesOptional);
Assert.assertTrue(topicPoliciesOptional.isPresent());

TopicPolicies topicPolicies = topicPoliciesOptional.get();
Assert.assertNotNull(topicPolicies);
Assert.assertEquals(topicPolicies.getMaxConsumerPerTopic(), 10);
}
}
Loading