Skip to content
Merged
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 @@ -154,6 +154,8 @@
@Test(groups = "broker-admin")
public class AdminApiTest extends MockedPulsarServiceBaseTest {

private static final String BROKER_SHUTDOWN_TIMEOUT_MS = "brokerShutdownTimeoutMs";

private MockedPulsarService mockPulsarSetup;

private PulsarService otherPulsar;
Expand Down Expand Up @@ -216,6 +218,14 @@ private void setupConfigAndStart(java.util.function.Consumer<ServiceConfiguratio

@AfterMethod(alwaysRun = true)
public void resetClusters() throws Exception {
if (pulsar == null || !pulsar.isRunning()) {
// A test method left the broker stopped, for example because stopBroker() failed. Throwing from
// here is a TestNG configuration failure, which makes TestNG skip every remaining test method of
// this class. TestRetrySupport recreates the shared test context before the next test method.
log.warn().log("Broker isn't running, skipping the cleanup of the previous test method");
return;
}
restoreBrokerShutdownTimeout();
pulsar.getConfiguration().setForceDeleteTenantAllowed(true);
pulsar.getConfiguration().setForceDeleteNamespaceAllowed(true);
for (String tenant : admin.tenants().getTenants()) {
Expand All @@ -237,6 +247,25 @@ public void resetClusters() throws Exception {
setupClusters();
}

/**
* Several test methods of this class lower the {@code brokerShutdownTimeoutMs} dynamic configuration to 10ms.
* The broker applies dynamic configuration changes asynchronously, so when the value is left behind it can
* become effective while a later test method is shutting the broker down in stopBroker() or restartBroker().
* PulsarService#close then fails with "Timeout in close" and leaves the test holding a broker that is no
* longer listening, which fails this @AfterMethod and skips the remaining test methods of the class.
*/
private void restoreBrokerShutdownTimeout() throws Exception {
String overriddenValue = admin.brokers().getAllDynamicConfigurations().get(BROKER_SHUTDOWN_TIMEOUT_MS);
if (overriddenValue == null) {
return;
}
long overriddenTimeoutMs = Long.parseLong(overriddenValue);
// removing the dynamic configuration makes the broker restore the value it was started with
admin.brokers().deleteDynamicConfiguration(BROKER_SHUTDOWN_TIMEOUT_MS);
Awaitility.await().untilAsserted(
() -> assertNotEquals(pulsar.getConfiguration().getBrokerShutdownTimeoutMs(), overriddenTimeoutMs));
}

private void setupClusters() throws PulsarAdminException {
admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build());
TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test"));
Expand Down Expand Up @@ -754,6 +783,8 @@ public void testGetDynamicLocalConfiguration() throws Exception {
admin.brokers().updateDynamicConfiguration(configName, Long.toString(shutdownTime));
// Now, znode is created: updateConfigurationAndRegisterListeners and check if configuration updated
assertEquals(Long.parseLong(admin.brokers().getAllDynamicConfigurations().get(configName)), shutdownTime);
// wait until the broker has applied the value, so that the @AfterMethod always has to restore it
Awaitility.await().until(() -> pulsar.getConfiguration().getBrokerShutdownTimeoutMs() == shutdownTime);
}

@Test
Expand Down
Loading