You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2026/09/14 14:18:13 UTC
(pulsar) 11/17: [fix][test] Isolate mutable broker fixtures between test methods (#26563)
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 6327e7dd537959189690a33ac6351348cc3bb750
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Sun Sep 13 19:29:20 2026 +0300
[fix][test] Isolate mutable broker fixtures between test methods (#26563)
(cherry picked from commit 0e76cf34d0dd5229a9662618d724e75583c52849)
---
.../service/BrokerDispatchRateLimiterTest.java | 8 +--
.../BrokerServiceAutoTopicCreationTest.java | 12 ++---
.../pulsar/broker/service/BrokerServiceTest.java | 57 +++++++++++-----------
3 files changed, 35 insertions(+), 42 deletions(-)
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerDispatchRateLimiterTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerDispatchRateLimiterTest.java
index 0db1a0f13acf..62f186de94af 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerDispatchRateLimiterTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerDispatchRateLimiterTest.java
@@ -36,19 +36,19 @@ import org.apache.pulsar.client.api.Schema;
import org.apache.pulsar.client.api.SubscriptionType;
import org.awaitility.Awaitility;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@Test(groups = "broker")
public class BrokerDispatchRateLimiterTest extends BrokerTestBase {
- @BeforeClass
+ @BeforeMethod
@Override
protected void setup() throws Exception {
super.baseSetup();
}
- @AfterClass(alwaysRun = true)
+ @AfterMethod(alwaysRun = true)
@Override
protected void cleanup() throws Exception {
super.internalCleanup();
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceAutoTopicCreationTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceAutoTopicCreationTest.java
index 916485823e29..8a4f0c8db0df 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceAutoTopicCreationTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceAutoTopicCreationTest.java
@@ -49,31 +49,25 @@ import org.apache.pulsar.common.policies.data.TenantInfoImpl;
import org.apache.pulsar.common.policies.data.TopicType;
import org.awaitility.Awaitility;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@Test(groups = "broker")
public class BrokerServiceAutoTopicCreationTest extends BrokerTestBase{
- @BeforeClass
+ @BeforeMethod
@Override
protected void setup() throws Exception {
super.baseSetup();
}
- @AfterClass(alwaysRun = true)
+ @AfterMethod(alwaysRun = true)
@Override
protected void cleanup() throws Exception {
super.internalCleanup();
}
- @AfterMethod(alwaysRun = true)
- protected void cleanupTest() throws Exception {
- pulsar.getAdminClient().namespaces().removeAutoTopicCreation("prop/ns-abc");
- }
-
@Test
public void testAutoNonPartitionedTopicCreation() throws Exception{
pulsar.getConfiguration().setAllowAutoTopicCreation(true);
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java
index 552a390bfe28..bf346641c76a 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java
@@ -2169,37 +2169,36 @@ public class BrokerServiceTest extends BrokerTestBase {
Set<String> providers = new HashSet<>();
providers.add("org.apache.pulsar.broker.authentication.AuthenticationProviderTls");
- conf.setAuthenticationEnabled(true);
- conf.setAuthenticationProviders(providers);
- conf.setBrokerServicePortTls(Optional.of(0));
- conf.setWebServicePortTls(Optional.of(0));
- conf.setTlsCertificateFilePath(BROKER_CERT_FILE_PATH);
- conf.setTlsKeyFilePath(BROKER_KEY_FILE_PATH);
- conf.setTlsAllowInsecureConnection(false);
- conf.setTlsTrustCertsFilePath(CA_CERT_FILE_PATH);
- conf.setNumExecutorThreadPoolSize(5);
- restartBroker();
-
- String authParam = String.format("tlsCertFile:%s,tlsKeyFile:%s", getTlsFileForClient("admin.cert"),
- getTlsFileForClient("admin.key-pk8"));
- String authClassName = "org.apache.pulsar.client.impl.auth.AuthenticationTls";
- ClientConfigurationData conf = new ClientConfigurationData();
- conf.setServiceUrl(brokerUrlTls.toString());
- conf.setAuthParams(authParam);
- conf.setAuthPluginClassName(authClassName);
- conf.setTlsAllowInsecureConnection(true);
-
- PulsarClient pulsarClient = null;
try {
- pulsarClient = (new ClientBuilderImpl(conf)).build();
-
- @Cleanup
- Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName)
- .subscribe();
- } catch (Exception e) {
- fail("should not fail");
+ conf.setAuthenticationEnabled(true);
+ conf.setAuthenticationProviders(providers);
+ conf.setBrokerServicePortTls(Optional.of(0));
+ conf.setWebServicePortTls(Optional.of(0));
+ conf.setTlsCertificateFilePath(BROKER_CERT_FILE_PATH);
+ conf.setTlsKeyFilePath(BROKER_KEY_FILE_PATH);
+ conf.setTlsAllowInsecureConnection(false);
+ conf.setTlsTrustCertsFilePath(CA_CERT_FILE_PATH);
+ conf.setNumExecutorThreadPoolSize(5);
+ restartBroker();
+
+ String authParam = String.format("tlsCertFile:%s,tlsKeyFile:%s", getTlsFileForClient("admin.cert"),
+ getTlsFileForClient("admin.key-pk8"));
+ String authClassName = "org.apache.pulsar.client.impl.auth.AuthenticationTls";
+ ClientConfigurationData conf = new ClientConfigurationData();
+ conf.setServiceUrl(brokerUrlTls.toString());
+ conf.setAuthParams(authParam);
+ conf.setAuthPluginClassName(authClassName);
+ conf.setTlsAllowInsecureConnection(true);
+
+ try (PulsarClient pulsarClient = new ClientBuilderImpl(conf).build()) {
+ @Cleanup
+ Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName)
+ .subscribe();
+ } catch (Exception e) {
+ fail("should not fail", e);
+ }
} finally {
- pulsarClient.close();
+ resetState();
}
}