Skip to content
Open
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 @@ -68,7 +68,6 @@
import org.apache.pulsar.common.naming.NamespaceBundleSplitAlgorithm;
import org.apache.pulsar.common.naming.NamespaceBundles;
import org.apache.pulsar.common.naming.NamespaceName;
import org.apache.pulsar.common.naming.TopicDomain;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.policies.data.AuthAction;
import org.apache.pulsar.common.policies.data.AutoSubscriptionCreationOverride;
Expand Down Expand Up @@ -225,12 +224,9 @@ protected void internalDeleteNamespace(AsyncResponse asyncResponse, boolean auth
boolean isEmpty;
List<String> topics;
try {
topics = pulsar().getNamespaceService().getListOfPersistentTopics(namespaceName)
topics = pulsar().getNamespaceService().getFullListOfTopics(namespaceName)
.get(config().getMetadataStoreOperationTimeoutSeconds(), TimeUnit.SECONDS);
topics.addAll(getPartitionedTopicList(TopicDomain.persistent));
topics.addAll(getPartitionedTopicList(TopicDomain.non_persistent));
isEmpty = topics.isEmpty();

} catch (Exception e) {
asyncResponse.resume(new RestException(e));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2431,4 +2431,27 @@ public void testPartitionedStatsAggregationByProducerNamePerPartition(String top
assertEquals(topicStats.getPublishers().size(), 2);
topicStats.getPublishers().forEach(p -> assertTrue(p.isSupportsPartialProducer()));
}

@Test
public void testDeleteNamespaceWithDeletedPartitionedTopic() throws Exception {
final String namespace = "prop-xyz/ns-delete";
admin.namespaces().createNamespace(namespace);
final String topicName = "persistent://" + namespace + "/delete-ns-topic";
admin.topics().createPartitionedTopic(topicName, 10);
List<String> topics = pulsar.getPulsarResources().getTopicResources()
.listPersistentTopicsAsync(NamespaceName.get(namespace)).get();
topics.forEach(topic -> {
try {
admin.topics().delete(topic);
} catch (PulsarAdminException e) {
fail("should not fail to delete");
}
});
admin.namespaces().deleteNamespace(namespace);
try {
admin.namespaces().getPolicies(namespace);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be an exception, so a fail() should be added here

} catch (PulsarAdminException.NotFoundException e) {
// Ok..
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -729,20 +729,19 @@ public void testDeleteNamespaces() throws Exception {

response = mock(AsyncResponse.class);
namespaces.deleteNamespace(response, testNs.getTenant(), testNs.getCluster(), testNs.getLocalName(), false, false);
errorCaptor = ArgumentCaptor.forClass(RestException.class);
// Ok, namespace not empty
verify(response, timeout(5000).times(1)).resume(errorCaptor.capture());
assertEquals(errorCaptor.getValue().getResponse().getStatus(), Status.CONFLICT.getStatusCode());

mockZooKeeperGlobal.delete("/admin/partitioned-topics/" + topicName.getPersistenceNamingEncoding(), -1);
ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class);
verify(response, timeout(5000).times(1)).resume(responseCaptor.capture());
assertEquals(responseCaptor.getValue().getStatus(), Status.NO_CONTENT.getStatusCode());

testNs = this.testGlobalNamespaces.get(0);
namespaces.setNamespaceReplicationClusters(testNs.getTenant(), testNs.getCluster(), testNs.getLocalName(), Lists.newArrayList("use"));
// setup ownership to localhost
doReturn(Optional.of(localWebServiceUrl)).when(nsSvc).getWebServiceUrl(testNs, options);
doReturn(true).when(nsSvc).isServiceUnitOwned(testNs);
response = mock(AsyncResponse.class);
namespaces.deleteNamespace(response, testNs.getTenant(), testNs.getCluster(), testNs.getLocalName(), false, false);
ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class);
responseCaptor = ArgumentCaptor.forClass(Response.class);
verify(response, timeout(5000).times(1)).resume(responseCaptor.capture());
assertEquals(responseCaptor.getValue().getStatus(), Status.NO_CONTENT.getStatusCode());

Expand All @@ -755,12 +754,11 @@ public void testDeleteNamespaces() throws Exception {
responseCaptor = ArgumentCaptor.forClass(Response.class);
verify(response, timeout(5000).times(1)).resume(responseCaptor.capture());
assertEquals(responseCaptor.getValue().getStatus(), Status.NO_CONTENT.getStatusCode());
List<String> nsList = Lists.newArrayList(this.testLocalNamespaces.get(1).toString(),
this.testLocalNamespaces.get(2).toString());
List<String> nsList = Lists.newArrayList(this.testLocalNamespaces.get(2).toString());
nsList.sort(null);
assertEquals(namespaces.getTenantNamespaces(this.testTenant), nsList);

testNs = this.testLocalNamespaces.get(1);
testNs = this.testLocalNamespaces.get(2);
// setup ownership to localhost
doReturn(Optional.of(localWebServiceUrl)).when(nsSvc).getWebServiceUrl(testNs, options);
doReturn(true).when(nsSvc).isServiceUnitOwned(testNs);
Expand Down
Loading