Skip to content

Commit

Permalink
[improve][test] Restart broker in SimpleProducerConsumerTest if ns de…
Browse files Browse the repository at this point in the history
…letion times out (#22734)
  • Loading branch information
lhotari authored May 20, 2024
1 parent 9c60134 commit 47fd1a3
Showing 1 changed file with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
import org.apache.pulsar.common.protocol.Commands;
import org.apache.pulsar.common.schema.SchemaType;
import org.apache.pulsar.common.util.FutureUtil;
import org.apache.pulsar.tests.ThreadDumpUtil;
import org.awaitility.Awaitility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -147,25 +148,31 @@ protected void setup() throws Exception {
}

@AfterMethod(alwaysRun = true)
public void rest() throws Exception {
pulsar.getConfiguration().setForceDeleteTenantAllowed(true);
pulsar.getConfiguration().setForceDeleteNamespaceAllowed(true);
public void cleanupAfterMethod() throws Exception {
try {
pulsar.getConfiguration().setForceDeleteTenantAllowed(true);
pulsar.getConfiguration().setForceDeleteNamespaceAllowed(true);

for (String tenant : admin.tenants().getTenants()) {
for (String namespace : admin.namespaces().getNamespaces(tenant)) {
deleteNamespaceWithRetry(namespace, true);
for (String tenant : admin.tenants().getTenants()) {
for (String namespace : admin.namespaces().getNamespaces(tenant)) {
deleteNamespaceWithRetry(namespace, true);
}
admin.tenants().deleteTenant(tenant, true);
}
admin.tenants().deleteTenant(tenant, true);
}

for (String cluster : admin.clusters().getClusters()) {
admin.clusters().deleteCluster(cluster);
}

pulsar.getConfiguration().setForceDeleteTenantAllowed(false);
pulsar.getConfiguration().setForceDeleteNamespaceAllowed(false);
for (String cluster : admin.clusters().getClusters()) {
admin.clusters().deleteCluster(cluster);
}

super.producerBaseSetup();
pulsar.getConfiguration().setForceDeleteTenantAllowed(false);
pulsar.getConfiguration().setForceDeleteNamespaceAllowed(false);
super.producerBaseSetup();
} catch (Exception | AssertionError e) {
log.warn("Failed to clean up state. Restarting broker.", e);
log.warn("Thread dump:\n{}", ThreadDumpUtil.buildThreadDiagnosticString());
cleanup();
setup();
}
}

@DataProvider
Expand Down

0 comments on commit 47fd1a3

Please sign in to comment.