Skip to content

Commit

Permalink
[fix][broker]add test case for deleting namespace fail when has parti…
Browse files Browse the repository at this point in the history
…tioned system topic (#17338)

(cherry picked from commit bfbe381)
  • Loading branch information
poorbarcode authored and coderzc committed Feb 28, 2023
1 parent 6c49b79 commit f1ec5ca
Showing 1 changed file with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.core.Response.Status;
import lombok.AllArgsConstructor;
import lombok.Cleanup;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.bookkeeper.mledger.ManagedLedger;
import org.apache.bookkeeper.mledger.impl.ManagedCursorImpl;
Expand Down Expand Up @@ -1326,9 +1328,43 @@ public void testDeleteTenant() throws Exception {
assertFalse(pulsar.getLocalMetadataStore().exists(localPoliciesPath).join());
}

@Test
public void testDeleteNamespace() throws Exception {
pulsar.getConfiguration().setForceDeleteNamespaceAllowed(false);
@Data
@AllArgsConstructor
private static class NamespaceAttr {
private boolean systemTopicEnabled;
private String autoTopicCreationType;
private int defaultNumPartitions;
private boolean forceDeleteNamespaceAllowed;
}

@DataProvider(name = "namespaceAttrs")
public Object[][] namespaceAttributes(){
return new Object[][]{
{new NamespaceAttr(false, "non-partitioned", 0, false)},
{new NamespaceAttr(true, "non-partitioned", 0, false)},
{new NamespaceAttr(true, "partitioned", 3, false)}
};
}

private NamespaceAttr markOriginalNamespaceAttr(){
return new NamespaceAttr(conf.isSystemTopicEnabled(), conf.getAllowAutoTopicCreationType(),
conf.getDefaultNumPartitions(), conf.isForceDeleteNamespaceAllowed());
}

private void setNamespaceAttr(NamespaceAttr namespaceAttr){
conf.setSystemTopicEnabled(namespaceAttr.systemTopicEnabled);
conf.setAllowAutoTopicCreationType(namespaceAttr.autoTopicCreationType);
conf.setDefaultNumPartitions(namespaceAttr.defaultNumPartitions);
conf.setForceDeleteNamespaceAllowed(namespaceAttr.forceDeleteNamespaceAllowed);
}

@Test(dataProvider = "namespaceAttrs")
public void testDeleteNamespace(NamespaceAttr namespaceAttr) throws Exception {
// Set conf.
internalCleanup();
NamespaceAttr originalNamespaceAttr = markOriginalNamespaceAttr();
setNamespaceAttr(namespaceAttr);
setup();

String tenant = "test-tenant";
assertFalse(admin.tenants().getTenants().contains(tenant));
Expand Down Expand Up @@ -1373,6 +1409,11 @@ public void testDeleteNamespace() throws Exception {

final String bundleDataPath = "/loadbalance/bundle-data/" + namespace;
assertFalse(pulsar.getLocalMetadataStore().exists(bundleDataPath).join());

// Reset config
internalCleanup();
setNamespaceAttr(originalNamespaceAttr);
setup();
}

private void awaitChangeEventTopicAndCompactionCreateFinish(String ns, String topic) throws Exception {
Expand Down

0 comments on commit f1ec5ca

Please sign in to comment.