Skip to content

Commit

Permalink
[Issue 3837][pulsar-client-tools]Delete schema when deleting a topic (a…
Browse files Browse the repository at this point in the history
…pache#3941)

Fixes: apache#3837 

### Motivation


* Providing an option to delete schema when deleting a topic.

### Modifications

* Add deleteSchema parameter for delete and delete-partitioned-topic

### Verifying this change

Test pass
  • Loading branch information
tuteng authored and sijie committed Apr 1, 2019
1 parent 205a79b commit b2aae9c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.times;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
Expand All @@ -41,6 +42,7 @@
import org.apache.pulsar.client.admin.ResourceQuotas;
import org.apache.pulsar.client.admin.Tenants;
import org.apache.pulsar.client.admin.Topics;
import org.apache.pulsar.client.admin.Schemas;
import org.apache.pulsar.client.api.MessageId;
import org.apache.pulsar.common.policies.data.AuthAction;
import org.apache.pulsar.common.policies.data.BacklogQuota;
Expand Down Expand Up @@ -558,11 +560,14 @@ void topics() throws Exception {
PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
Topics mockTopics = mock(Topics.class);
when(admin.topics()).thenReturn(mockTopics);
Schemas mockSchemas = mock(Schemas.class);
when(admin.schemas()).thenReturn(mockSchemas);

CmdTopics cmdTopics = new CmdTopics(admin);

cmdTopics.run(split("delete persistent://myprop/clust/ns1/ds1"));
cmdTopics.run(split("delete persistent://myprop/clust/ns1/ds1 -d"));
verify(mockTopics).delete("persistent://myprop/clust/ns1/ds1", false);
verify(mockSchemas).deleteSchema("persistent://myprop/clust/ns1/ds1");

cmdTopics.run(split("unload persistent://myprop/clust/ns1/ds1"));
verify(mockTopics).unload("persistent://myprop/clust/ns1/ds1");
Expand Down Expand Up @@ -615,8 +620,9 @@ void topics() throws Exception {
cmdTopics.run(split("get-partitioned-topic-metadata persistent://myprop/clust/ns1/ds1"));
verify(mockTopics).getPartitionedTopicMetadata("persistent://myprop/clust/ns1/ds1");

cmdTopics.run(split("delete-partitioned-topic persistent://myprop/clust/ns1/ds1"));
cmdTopics.run(split("delete-partitioned-topic persistent://myprop/clust/ns1/ds1 -d"));
verify(mockTopics).deletePartitionedTopic("persistent://myprop/clust/ns1/ds1", false);
verify(mockSchemas, times(2)).deleteSchema("persistent://myprop/clust/ns1/ds1");

cmdTopics.run(split("peek-messages persistent://myprop/clust/ns1/ds1 -s sub1 -n 3"));
verify(mockTopics).peekMessages("persistent://myprop/clust/ns1/ds1", "sub1", 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,17 @@ private class DeletePartitionedCmd extends CliCommand {
"--force" }, description = "Close all producer/consumer/replicator and delete topic forcefully")
private boolean force = false;

@Parameter(names = { "-d",
"--deleteSchema" }, description = "Delete schema while deleting topic")
private boolean deleteSchema = false;

@Override
void run() throws Exception {
String topic = validateTopicName(params);
topics.deletePartitionedTopic(topic, force);
if (deleteSchema) {
admin.schemas().deleteSchema(topic);
}
}
}

Expand All @@ -287,10 +294,17 @@ private class DeleteCmd extends CliCommand {
"--force" }, description = "Close all producer/consumer/replicator and delete topic forcefully")
private boolean force = false;

@Parameter(names = { "-d",
"--deleteSchema" }, description = "Delete schema while deleting topic")
private boolean deleteSchema = false;

@Override
void run() throws PulsarAdminException {
String topic = validateTopicName(params);
topics.delete(topic, force);
if (deleteSchema) {
admin.schemas().deleteSchema(topic);
}
}
}

Expand Down

0 comments on commit b2aae9c

Please sign in to comment.