From 486c670e156acadba4399b245aa45261ae88db20 Mon Sep 17 00:00:00 2001 From: Lari Hotari Date: Tue, 20 Sep 2022 18:47:21 +0300 Subject: [PATCH] [fix][tests] Fix resource leak in tests. Call cleanup before setup - when setup is called explicitly, cleanup should be issued before it - remove unnecessary "resetConfig" method calls - resetConfig gets called as part of internalCleanup - when resetConfig is in cleanup, it's possible to override config before calling setup - this allows using setup & cleanup methods instead of using error prone internalSetup and internalCleanup methods which might leave something behind --- .../pulsar/broker/PulsarServiceTest.java | 4 +- .../pulsar/broker/admin/AdminApi2Test.java | 125 ++++++++---------- .../broker/admin/AdminApiClusterTest.java | 1 - .../broker/admin/AdminApiHealthCheckTest.java | 1 - .../admin/AdminApiMaxUnackedMessages.java | 1 - .../pulsar/broker/admin/AdminRestTest.java | 1 - .../broker/admin/MaxUnackedMessagesTest.java | 1 - .../pulsar/broker/admin/NamespacesTest.java | 14 +- .../pulsar/broker/admin/NamespacesV2Test.java | 1 - .../broker/admin/TopicMessageTTLTest.java | 11 +- .../broker/admin/TopicPoliciesTest.java | 1 - .../broker/admin/v1/V1_AdminApi2Test.java | 1 - .../admin/v3/AdminApiTransactionTest.java | 15 ++- .../auth/MockedPulsarServiceBaseTest.java | 4 +- .../broker/service/BrokerServiceTest.java | 1 - .../service/InactiveTopicDeleteTest.java | 2 +- .../MessagePublishBufferThrottleTest.java | 1 - .../service/PersistentTopicE2ETest.java | 8 +- .../persistent/TopicDuplicationTest.java | 25 ++-- .../stats/MetricsAuthenticationTest.java | 1 - .../broker/stats/PrometheusMetricsTest.java | 4 +- .../systopic/PartitionedSystemTopicTest.java | 1 - .../transaction/TransactionTestBase.java | 2 +- ...enticationTlsHostnameVerificationTest.java | 3 +- .../AuthorizationProducerConsumerTest.java | 16 +-- .../client/api/KeySharedSubscriptionTest.java | 1 - .../api/MessageDispatchThrottlingTest.java | 3 +- .../impl/MessagePublishThrottlingTest.java | 1 - .../pulsar/client/impl/NegativeAcksTest.java | 2 +- .../impl/PatternTopicsConsumerImplTest.java | 7 +- .../impl/TopicPublishThrottlingInitTest.java | 1 - .../org/apache/pulsar/schema/SchemaTest.java | 6 +- .../ProxyEncryptionPublishConsumeTest.java | 1 - .../proxy/ProxyPublishConsumeTest.java | 1 - .../pulsar/client/cli/DocumentTest.java | 1 - .../client/cli/PulsarClientToolWsTest.java | 1 - 36 files changed, 110 insertions(+), 160 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/PulsarServiceTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/PulsarServiceTest.java index bb616356d514d..c207a6fcfe92f 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/PulsarServiceTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/PulsarServiceTest.java @@ -48,7 +48,6 @@ protected void setup() throws Exception { protected void cleanup() throws Exception { super.internalCleanup(); useStaticPorts = false; - resetConfig(); } @Override @@ -105,6 +104,7 @@ public void testGetWorkerServiceException() throws Exception { @Test public void testAdvertisedAddress() throws Exception { + cleanup(); useStaticPorts = true; setup(); assertEquals(pulsar.getAdvertisedAddress(), "localhost"); @@ -117,6 +117,7 @@ public void testAdvertisedAddress() throws Exception { @Test public void testAdvertisedListeners() throws Exception { + cleanup(); // don't use dynamic ports when using advertised listeners (#12079) useStaticPorts = true; conf.setAdvertisedListeners("internal:pulsar://gateway:6650, internal:pulsar+ssl://gateway:6651"); @@ -132,6 +133,7 @@ public void testAdvertisedListeners() throws Exception { @Test public void testDynamicBrokerPort() throws Exception { + cleanup(); useStaticPorts = false; setup(); assertEquals(pulsar.getAdvertisedAddress(), "localhost"); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java index a619bab272e54..c982630438309 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java @@ -60,6 +60,7 @@ import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl; import org.apache.pulsar.broker.BrokerTestUtil; import org.apache.pulsar.broker.PulsarService; +import org.apache.pulsar.broker.ServiceConfiguration; import org.apache.pulsar.broker.admin.AdminApiTest.MockedPulsarService; import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest; import org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl; @@ -129,9 +130,6 @@ public class AdminApi2Test extends MockedPulsarServiceBaseTest { @BeforeMethod @Override public void setup() throws Exception { - conf.setForceDeleteNamespaceAllowed(true); - conf.setLoadBalancerEnabled(true); - conf.setEnableNamespaceIsolationUpdateOnTime(true); super.internalSetup(); // create otherbroker to test redirect on calls that need @@ -146,12 +144,22 @@ public void setup() throws Exception { admin.namespaces().createNamespace("prop-xyz/ns1", Set.of("test")); } + @Override + protected ServiceConfiguration getDefaultConf() { + ServiceConfiguration conf = super.getDefaultConf(); + conf.setForceDeleteNamespaceAllowed(true); + conf.setLoadBalancerEnabled(true); + conf.setEnableNamespaceIsolationUpdateOnTime(true); + return conf; + } + @AfterMethod(alwaysRun = true) @Override public void cleanup() throws Exception { super.internalCleanup(); if (mockPulsarSetup != null) { mockPulsarSetup.cleanup(); + mockPulsarSetup = null; } resetConfig(); } @@ -278,12 +286,12 @@ public void testIncrementPartitionsOfTopic() throws Exception { public void testTopicPoliciesWithMultiBroker() throws Exception { //setup cluster with 3 broker cleanup(); - super.internalSetup(); - admin.clusters().createCluster("test", + setup(); + admin.clusters().updateCluster("test", ClusterData.builder().serviceUrl((pulsar.getWebServiceAddress() + ",localhost:1026," + "localhost:2050")).build()); TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test")); - admin.tenants().createTenant("prop-xyz", tenantInfo); - admin.namespaces().createNamespace("prop-xyz/ns1", Set.of("test")); + admin.tenants().createTenant("prop-xyz2", tenantInfo); + admin.namespaces().createNamespace("prop-xyz2/ns1", Set.of("test")); conf.setBrokerServicePort(Optional.of(1024)); conf.setBrokerServicePortTls(Optional.of(1025)); conf.setWebServicePort(Optional.of(1026)); @@ -302,14 +310,14 @@ public void testTopicPoliciesWithMultiBroker() throws Exception { PulsarAdmin admin3 = PulsarAdmin.builder().serviceHttpUrl(pulsar3.getWebServiceAddress()).build(); //for partitioned topic, we can get topic policies from every broker - final String topic = "persistent://prop-xyz/ns1/" + BrokerTestUtil.newUniqueName("test"); + final String topic = "persistent://prop-xyz2/ns1/" + BrokerTestUtil.newUniqueName("test"); int partitionNum = 3; admin.topics().createPartitionedTopic(topic, partitionNum); pulsarClient.newConsumer().topic(topic).subscriptionName("sub").subscribe().close(); setTopicPoliciesAndValidate(admin2, admin3, topic); //for non-partitioned topic, we can get topic policies from every broker - final String topic2 = "persistent://prop-xyz/ns1/" + BrokerTestUtil.newUniqueName("test"); + final String topic2 = "persistent://prop-xyz2/ns1/" + BrokerTestUtil.newUniqueName("test"); pulsarClient.newConsumer().topic(topic2).subscriptionName("sub").subscribe().close(); setTopicPoliciesAndValidate(admin2, admin3, topic2); } @@ -655,19 +663,18 @@ public void testMaxConsumersOnSubApi() throws Exception { public void testLoadReportApi() throws Exception { this.conf.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName()); + @Cleanup("cleanup") MockedPulsarService mockPulsarSetup1 = new MockedPulsarService(this.conf); mockPulsarSetup1.setup(); PulsarAdmin simpleLoadManagerAdmin = mockPulsarSetup1.getAdmin(); assertNotNull(simpleLoadManagerAdmin.brokerStats().getLoadReport()); this.conf.setLoadManagerClassName(ModularLoadManagerImpl.class.getName()); + @Cleanup("cleanup") MockedPulsarService mockPulsarSetup2 = new MockedPulsarService(this.conf); mockPulsarSetup2.setup(); PulsarAdmin modularLoadManagerAdmin = mockPulsarSetup2.getAdmin(); assertNotNull(modularLoadManagerAdmin.brokerStats().getLoadReport()); - - mockPulsarSetup1.cleanup(); - mockPulsarSetup2.cleanup(); } @Test @@ -1442,7 +1449,7 @@ public void testDeleteTenant() throws Exception { // Disabled conf: systemTopicEnabled. see: https://github.com/apache/pulsar/pull/17070 boolean originalSystemTopicEnabled = conf.isSystemTopicEnabled(); if (originalSystemTopicEnabled) { - internalCleanup(); + cleanup(); conf.setSystemTopicEnabled(false); setup(); } @@ -1496,7 +1503,7 @@ public void testDeleteTenant() throws Exception { assertFalse(pulsar.getLocalMetadataStore().exists(bundleDataPath).join()); // Reset conf: systemTopicEnabled if (originalSystemTopicEnabled) { - internalCleanup(); + cleanup(); conf.setSystemTopicEnabled(true); setup(); } @@ -1535,7 +1542,7 @@ private void setNamespaceAttr(NamespaceAttr namespaceAttr){ @Test(dataProvider = "namespaceAttrs") public void testDeleteNamespace(NamespaceAttr namespaceAttr) throws Exception { // Set conf. - internalCleanup(); + cleanup(); NamespaceAttr originalNamespaceAttr = markOriginalNamespaceAttr(); setNamespaceAttr(namespaceAttr); setup(); @@ -1586,7 +1593,7 @@ public void testDeleteNamespace(NamespaceAttr namespaceAttr) throws Exception { assertFalse(pulsar.getLocalMetadataStore().exists(bundleDataPath).join()); // Reset config - internalCleanup(); + cleanup(); setNamespaceAttr(originalNamespaceAttr); setup(); } @@ -1636,7 +1643,7 @@ private void awaitChangeEventTopicAndCompactionCreateFinish(String ns, String to @Test public void testDeleteNamespaceWithTopicPolicies() throws Exception { - stopBroker(); + cleanup(); setup(); String tenant = "test-tenant"; @@ -1940,10 +1947,9 @@ public void testUpdateClusterWithProxyUrl() throws Exception { @Test public void testMaxNamespacesPerTenant() throws Exception { - super.internalCleanup(); + cleanup(); conf.setMaxNamespacesPerTenant(2); - super.internalSetup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); + setup(); TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test")); admin.tenants().createTenant("testTenant", tenantInfo); admin.namespaces().createNamespace("testTenant/ns1", Set.of("test")); @@ -1956,10 +1962,9 @@ public void testMaxNamespacesPerTenant() throws Exception { } //unlimited - super.internalCleanup(); + cleanup(); conf.setMaxNamespacesPerTenant(0); - super.internalSetup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); + setup(); admin.tenants().createTenant("testTenant", tenantInfo); for (int i = 0; i < 10; i++) { admin.namespaces().createNamespace("testTenant/ns-" + i, Set.of("test")); @@ -1968,10 +1973,9 @@ public void testMaxNamespacesPerTenant() throws Exception { @Test public void testAutoTopicCreationOverrideWithMaxNumPartitionsLimit() throws Exception{ - super.internalCleanup(); + cleanup(); conf.setMaxNumPartitionsPerPartitionedTopic(10); - super.internalSetup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); + setup(); TenantInfoImpl tenantInfo = new TenantInfoImpl( Set.of("role1", "role2"), Set.of("test")); admin.tenants().createTenant("testTenant", tenantInfo); @@ -2010,10 +2014,9 @@ public void testAutoTopicCreationOverrideWithMaxNumPartitionsLimit() throws Exce } @Test public void testMaxTopicsPerNamespace() throws Exception { - super.internalCleanup(); + cleanup(); conf.setMaxTopicsPerNamespace(10); - super.internalSetup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); + setup(); TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test")); admin.tenants().createTenant("testTenant", tenantInfo); admin.namespaces().createNamespace("testTenant/ns1", Set.of("test")); @@ -2033,10 +2036,9 @@ public void testMaxTopicsPerNamespace() throws Exception { } //unlimited - super.internalCleanup(); + cleanup(); conf.setMaxTopicsPerNamespace(0); - super.internalSetup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); + setup(); admin.tenants().createTenant("testTenant", tenantInfo); admin.namespaces().createNamespace("testTenant/ns1", Set.of("test")); for (int i = 0; i < 10; ++i) { @@ -2045,10 +2047,9 @@ public void testMaxTopicsPerNamespace() throws Exception { } // check first create normal topic, then system topics, unlimited even setMaxTopicsPerNamespace - super.internalCleanup(); + cleanup(); conf.setMaxTopicsPerNamespace(5); - super.internalSetup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); + setup(); admin.tenants().createTenant("testTenant", tenantInfo); admin.namespaces().createNamespace("testTenant/ns1", Set.of("test")); for (int i = 0; i < 5; ++i) { @@ -2058,10 +2059,9 @@ public void testMaxTopicsPerNamespace() throws Exception { // check first create system topics, then normal topic, unlimited even setMaxTopicsPerNamespace - super.internalCleanup(); + cleanup(); conf.setMaxTopicsPerNamespace(5); - super.internalSetup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); + setup(); admin.tenants().createTenant("testTenant", tenantInfo); admin.namespaces().createNamespace("testTenant/ns1", Set.of("test")); admin.topics().createPartitionedTopic("persistent://testTenant/ns1/__change_events", 6); @@ -2070,12 +2070,11 @@ public void testMaxTopicsPerNamespace() throws Exception { } // check producer/consumer auto create partitioned topic - super.internalCleanup(); + cleanup(); conf.setMaxTopicsPerNamespace(10); conf.setDefaultNumPartitions(3); conf.setAllowAutoTopicCreationType("partitioned"); - super.internalSetup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); + setup(); admin.tenants().createTenant("testTenant", tenantInfo); admin.namespaces().createNamespace("testTenant/ns1", Set.of("test")); @@ -2090,11 +2089,10 @@ public void testMaxTopicsPerNamespace() throws Exception { } // check producer/consumer auto create non-partitioned topic - super.internalCleanup(); + cleanup(); conf.setMaxTopicsPerNamespace(3); conf.setAllowAutoTopicCreationType("non-partitioned"); - super.internalSetup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); + setup(); admin.tenants().createTenant("testTenant", tenantInfo); admin.namespaces().createNamespace("testTenant/ns1", Set.of("test")); @@ -2125,11 +2123,10 @@ public void testInvalidBundleErrorResponse() throws Exception { @Test public void testMaxSubscriptionsPerTopic() throws Exception { - super.internalCleanup(); + cleanup(); conf.setMaxSubscriptionsPerTopic(2); - super.internalSetup(); + setup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test")); admin.tenants().createTenant("testTenant", tenantInfo); admin.namespaces().createNamespace("testTenant/ns1", Set.of("test")); @@ -2150,11 +2147,10 @@ public void testMaxSubscriptionsPerTopic() throws Exception { log.info("create subscription failed. Exception: ", e); } - super.internalCleanup(); + cleanup(); conf.setMaxSubscriptionsPerTopic(0); - super.internalSetup(); + setup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); admin.tenants().createTenant("testTenant", tenantInfo); admin.namespaces().createNamespace("testTenant/ns1", Set.of("test")); @@ -2166,11 +2162,10 @@ public void testMaxSubscriptionsPerTopic() throws Exception { admin.topics().createSubscription(topic, "test-sub" + i, MessageId.earliest); } - super.internalCleanup(); + cleanup(); conf.setMaxSubscriptionsPerTopic(2); - super.internalSetup(); + setup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); admin.tenants().createTenant("testTenant", tenantInfo); admin.namespaces().createNamespace("testTenant/ns1", Set.of("test")); @@ -2308,14 +2303,10 @@ public void testMaxSubPerTopic() throws Exception { @Test(timeOut = 30000) public void testMaxSubPerTopicPriority() throws Exception { final int brokerLevelMaxSub = 2; - super.internalCleanup(); - mockPulsarSetup.cleanup(); + cleanup(); conf.setMaxSubscriptionsPerTopic(brokerLevelMaxSub); - super.internalSetup(); + setup(); - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build()); - TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test")); - admin.tenants().createTenant("prop-xyz", tenantInfo); final String myNamespace = "prop-xyz/ns" + UUID.randomUUID(); admin.namespaces().createNamespace(myNamespace, Set.of("test")); final String topic = "persistent://" + myNamespace + "/testMaxSubPerTopic"; @@ -2365,14 +2356,10 @@ public void testMaxSubPerTopicPriority() throws Exception { @Test public void testMaxProducersPerTopicUnlimited() throws Exception { final int maxProducersPerTopic = 1; - super.internalCleanup(); - mockPulsarSetup.cleanup(); + cleanup(); conf.setMaxProducersPerTopic(maxProducersPerTopic); - super.internalSetup(); + setup(); //init namespace - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build()); - TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test")); - admin.tenants().createTenant("prop-xyz", tenantInfo); final String myNamespace = "prop-xyz/ns" + UUID.randomUUID(); admin.namespaces().createNamespace(myNamespace, Set.of("test")); final String topic = "persistent://" + myNamespace + "/testMaxProducersPerTopicUnlimited"; @@ -2418,14 +2405,10 @@ public void testMaxProducersPerTopicUnlimited() throws Exception { @Test public void testMaxConsumersPerTopicUnlimited() throws Exception { final int maxConsumersPerTopic = 1; - super.internalCleanup(); - mockPulsarSetup.cleanup(); + cleanup(); conf.setMaxConsumersPerTopic(maxConsumersPerTopic); - super.internalSetup(); + setup(); //init namespace - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build()); - TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test")); - admin.tenants().createTenant("prop-xyz", tenantInfo); final String myNamespace = "prop-xyz/ns" + UUID.randomUUID(); admin.namespaces().createNamespace(myNamespace, Set.of("test")); final String topic = "persistent://" + myNamespace + "/testMaxConsumersPerTopicUnlimited"; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiClusterTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiClusterTest.java index 6c4c7ad7db98a..87521d617a5f5 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiClusterTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiClusterTest.java @@ -40,7 +40,6 @@ public class AdminApiClusterTest extends MockedPulsarServiceBaseTest { @BeforeMethod @Override public void setup() throws Exception { - resetConfig(); super.internalSetup(); admin.clusters() .createCluster(CLUSTER, ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build()); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiHealthCheckTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiHealthCheckTest.java index 8729190cc3569..1a2e2fd7f404a 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiHealthCheckTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiHealthCheckTest.java @@ -52,7 +52,6 @@ public class AdminApiHealthCheckTest extends MockedPulsarServiceBaseTest { @BeforeMethod @Override public void setup() throws Exception { - resetConfig(); super.internalSetup(); admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build()); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiMaxUnackedMessages.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiMaxUnackedMessages.java index 22cac388947ba..b4d333a35ee2f 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiMaxUnackedMessages.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiMaxUnackedMessages.java @@ -59,7 +59,6 @@ public void setup() throws Exception { @Override public void cleanup() throws Exception { super.internalCleanup(); - resetConfig(); } @Test(timeOut = 30000) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminRestTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminRestTest.java index c04063f777954..154c3a9227781 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminRestTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminRestTest.java @@ -103,7 +103,6 @@ private String parseResponseEntity(Object entity) throws Exception { @BeforeMethod @Override protected void setup() throws Exception { - resetConfig(); super.internalSetup(); // Create tenant, namespace, topic admin.clusters().createCluster(clusterName, ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/MaxUnackedMessagesTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/MaxUnackedMessagesTest.java index 40c3674a27cb1..87e4f703bbfa5 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/MaxUnackedMessagesTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/MaxUnackedMessagesTest.java @@ -67,7 +67,6 @@ protected void setup() throws Exception { @Override protected void cleanup() throws Exception { super.internalCleanup(); - resetConfig(); } @Test(timeOut = 10000) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java index c43faa35279ca..6c3fba38642d1 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java @@ -159,7 +159,6 @@ public void initNamespace() throws Exception { @Override @BeforeMethod public void setup() throws Exception { - resetConfig(); conf.setTopicLevelPoliciesEnabled(false); conf.setSystemTopicEnabled(false); conf.setClusterName(testLocalCluster); @@ -1557,10 +1556,9 @@ public void testRetentionPolicyValidation() throws Exception { public void testMaxTopicsPerNamespace() throws Exception { cleanup(); conf.setMaxTopicsPerNamespace(15); - super.internalSetup(); + setup(); - String namespace = "testTenant/ns1"; - admin.clusters().createCluster("use", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); + String namespace = BrokerTestUtil.newUniqueName("testTenant/ns1"); TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("use")); admin.tenants().createTenant("testTenant", tenantInfo); @@ -1572,7 +1570,7 @@ public void testMaxTopicsPerNamespace() throws Exception { assertEquals(10, admin.namespaces().getMaxTopicsPerNamespace(namespace)); // check create partitioned/non-partitioned topics using namespace policy - String topic = "persistent://testTenant/ns1/test_create_topic_v"; + String topic = "persistent://" + namespace + "/test_create_topic_v"; admin.topics().createPartitionedTopic(topic + "1", 2); admin.topics().createPartitionedTopic(topic + "2", 3); admin.topics().createPartitionedTopic(topic + "3", 4); @@ -1610,9 +1608,8 @@ public void testMaxTopicsPerNamespace() throws Exception { conf.setMaxTopicsPerNamespace(0); conf.setDefaultNumPartitions(3); conf.setAllowAutoTopicCreationType("partitioned"); - super.internalSetup(); + setup(); - admin.clusters().createCluster("use", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); admin.tenants().createTenant("testTenant", tenantInfo); admin.namespaces().createNamespace(namespace, Set.of("use")); admin.namespaces().setMaxTopicsPerNamespace(namespace, 10); @@ -1640,9 +1637,8 @@ public void testMaxTopicsPerNamespace() throws Exception { conf.setMaxTopicsPerNamespace(0); conf.setDefaultNumPartitions(1); conf.setAllowAutoTopicCreationType("non-partitioned"); - super.internalSetup(); + setup(); - admin.clusters().createCluster("use", ClusterData.builder().serviceUrl(brokerUrl.toString()).build()); admin.tenants().createTenant("testTenant", tenantInfo); admin.namespaces().createNamespace(namespace, Set.of("use")); admin.namespaces().setMaxTopicsPerNamespace(namespace, 3); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesV2Test.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesV2Test.java index 2e45b7fbb28e1..556f9f3ac0544 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesV2Test.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesV2Test.java @@ -87,7 +87,6 @@ public void initNamespace() throws Exception { @Override @BeforeMethod public void setup() throws Exception { - resetConfig(); conf.setClusterName(testLocalCluster); super.internalSetup(); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicMessageTTLTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicMessageTTLTest.java index 8d3e303465ee9..d1fa01306f756 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicMessageTTLTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicMessageTTLTest.java @@ -48,7 +48,6 @@ public class TopicMessageTTLTest extends MockedPulsarServiceBaseTest { @BeforeMethod @Override protected void setup() throws Exception { - resetConfig(); this.conf.setTtlDurationDefaultInSeconds(3600); super.internalSetup(); @@ -125,15 +124,9 @@ public void testGetMessageTTL() throws Exception { @Test public void testTopicPolicyDisabled() throws Exception { - super.internalCleanup(); + cleanup(); this.conf.setTopicLevelPoliciesEnabled(false); - super.internalSetup(); - - admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build()); - TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test")); - admin.tenants().createTenant(this.testTenant, tenantInfo); - admin.namespaces().createNamespace(testTenant + "/" + testNamespace, Set.of("test")); - admin.topics().createPartitionedTopic(testTopic, 2); + setup(); try { admin.topics().getMessageTTL(testTopic); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicPoliciesTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicPoliciesTest.java index 559ac648d0268..0cf5ed79ea743 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicPoliciesTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicPoliciesTest.java @@ -131,7 +131,6 @@ protected void setup() throws Exception { @Override public void cleanup() throws Exception { super.internalCleanup(); - this.resetConfig(); } @Test diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v1/V1_AdminApi2Test.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v1/V1_AdminApi2Test.java index 8c4b347d473c0..f339416c2b9d7 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v1/V1_AdminApi2Test.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v1/V1_AdminApi2Test.java @@ -81,7 +81,6 @@ public class V1_AdminApi2Test extends MockedPulsarServiceBaseTest { @BeforeMethod @Override public void setup() throws Exception { - resetConfig(); conf.setTopicLevelPoliciesEnabled(false); conf.setSystemTopicEnabled(false); conf.setLoadBalancerEnabled(true); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionTest.java index d0240a8768fa3..8c002080abe18 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/AdminApiTransactionTest.java @@ -38,6 +38,7 @@ import lombok.Cleanup; import org.apache.bookkeeper.mledger.impl.PositionImpl; import org.apache.http.HttpStatus; +import org.apache.pulsar.broker.ServiceConfiguration; import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest; import org.apache.pulsar.client.admin.PulsarAdminException; import org.apache.pulsar.client.api.Consumer; @@ -80,13 +81,19 @@ @Test(groups = "broker-admin") public class AdminApiTransactionTest extends MockedPulsarServiceBaseTest { - @BeforeMethod @Override - protected void setup() throws Exception { + protected ServiceConfiguration getDefaultConf() { + ServiceConfiguration conf = super.getDefaultConf(); conf.setEnablePackagesManagement(true); conf.setPackagesManagementStorageProvider(MockedPackagesStorageProvider.class.getName()); conf.setTransactionCoordinatorEnabled(true); conf.setTransactionBufferSnapshotMaxTransactionCount(1); + return conf; + } + + @BeforeMethod + @Override + protected void setup() throws Exception { super.internalSetup(); admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build()); TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test")); @@ -566,9 +573,9 @@ public void testGetPendingAckInternalStats() throws Exception { @Test(timeOut = 20000) public void testTransactionNotEnabled() throws Exception { - stopBroker(); + cleanup(); conf.setTransactionCoordinatorEnabled(false); - super.internalSetup(); + setup(); try { admin.transactions().getCoordinatorInternalStats(1, false); } catch (PulsarAdminException ex) { diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockedPulsarServiceBaseTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockedPulsarServiceBaseTest.java index f70b3b43ab937..b4d7b2e5a32b7 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockedPulsarServiceBaseTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockedPulsarServiceBaseTest.java @@ -353,7 +353,7 @@ protected PulsarService newPulsarService(ServiceConfiguration conf) throws Excep protected void setupBrokerMocks(PulsarService pulsar) throws Exception { // Override default providers with mocked ones doReturn(mockBookKeeperClientFactory).when(pulsar).newBookKeeperClientFactory(); - + PulsarMetadataEventSynchronizer synchronizer = StringUtils .isNotBlank(pulsar.getConfig().getMetadataSyncEventTopic()) ? new PulsarMetadataEventSynchronizer(pulsar, pulsar.getConfig().getMetadataSyncEventTopic()) @@ -517,7 +517,7 @@ public static void setFieldValue(Class clazz, Object classObj, String fieldNa field.set(classObj, fieldValue); } - protected static ServiceConfiguration getDefaultConf() { + protected ServiceConfiguration getDefaultConf() { ServiceConfiguration configuration = new ServiceConfiguration(); configuration.setAdvertisedAddress("localhost"); configuration.setClusterName(configClusterName); 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 a2ce2c23ffe3b..389e9420c025c 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 @@ -134,7 +134,6 @@ protected void setup() throws Exception { @Override protected void cleanup() throws Exception { super.internalCleanup(); - resetConfig(); } // method for resetting state explicitly diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/InactiveTopicDeleteTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/InactiveTopicDeleteTest.java index 4a372c31b151a..1013e79916cc4 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/InactiveTopicDeleteTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/InactiveTopicDeleteTest.java @@ -50,7 +50,7 @@ public class InactiveTopicDeleteTest extends BrokerTestBase { @BeforeMethod protected void setup() throws Exception { - resetConfig(); + //No-op } @AfterMethod(alwaysRun = true) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/MessagePublishBufferThrottleTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/MessagePublishBufferThrottleTest.java index c0f5f59584c9b..82a3b1e376100 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/MessagePublishBufferThrottleTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/MessagePublishBufferThrottleTest.java @@ -43,7 +43,6 @@ protected void setup() throws Exception { @Override protected void cleanup() throws Exception { super.internalCleanup(); - resetConfig(); } @Test diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicE2ETest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicE2ETest.java index f8ee8a3148db1..5e27d9f647b93 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicE2ETest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicE2ETest.java @@ -1327,7 +1327,7 @@ public void testProducerQueueFullBlocking() throws Exception { .create(); // 2. Stop broker - super.internalCleanup(); + cleanup(); // 2. producer publish messages long startTime = System.nanoTime(); @@ -1374,7 +1374,7 @@ public void testProducerQueueFullNonBlocking() throws Exception { .create(); // 2. Stop broker - super.internalCleanup(); + cleanup(); // 2. producer publish messages long startTime = System.nanoTime(); @@ -1930,7 +1930,7 @@ public void testProducerBusy() throws Exception { @Test public void testHttpLookupWithNotFoundError() throws Exception { - stopBroker(); + cleanup(); isTcpLookup = false; setup(); try { @@ -2017,7 +2017,7 @@ public T create(String topic, ManagedLedger ledger, BrokerServ if(topicClazz == NonPersistentTopic.class) { return (T) new NonPersistentTopic(topic, brokerService); }else { - return (T) new PersistentTopic(topic, ledger, brokerService); + return (T) new PersistentTopic(topic, ledger, brokerService); } } catch (Exception e) { throw new IllegalStateException(e); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/TopicDuplicationTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/TopicDuplicationTest.java index 971b058a86d93..23136ea93443b 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/TopicDuplicationTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/TopicDuplicationTest.java @@ -54,7 +54,6 @@ public class TopicDuplicationTest extends ProducerConsumerBase { @BeforeMethod @Override protected void setup() throws Exception { - resetConfig(); this.conf.setBrokerDeduplicationEnabled(true); super.internalSetup(); super.producerBaseSetup(); @@ -221,14 +220,12 @@ public void testDuplicationSnapshotApi() throws Exception { @Test(timeOut = 30000) public void testTopicPolicyTakeSnapshot() throws Exception { - super.internalCleanup(); - resetConfig(); + cleanup(); conf.setBrokerDeduplicationEnabled(true); conf.setBrokerDeduplicationSnapshotFrequencyInSeconds(1); conf.setBrokerDeduplicationSnapshotIntervalSeconds(7); conf.setBrokerDeduplicationEntriesInterval(20000); - super.internalSetup(); - super.producerBaseSetup(); + setup(); final String topicName = testTopic + UUID.randomUUID().toString(); final String producerName = "my-producer"; @@ -330,14 +327,12 @@ public void testDuplicationSnapshot() throws Exception { } private void testTakeSnapshot(boolean enabledSnapshot) throws Exception { - super.internalCleanup(); - resetConfig(); + cleanup(); conf.setBrokerDeduplicationEnabled(true); conf.setBrokerDeduplicationSnapshotFrequencyInSeconds(enabledSnapshot ? 1 : 0); conf.setBrokerDeduplicationSnapshotIntervalSeconds(1); conf.setBrokerDeduplicationEntriesInterval(20000); - super.internalSetup(); - super.producerBaseSetup(); + setup(); final String topicName = testTopic + UUID.randomUUID().toString(); final String producerName = "my-producer"; @@ -407,14 +402,12 @@ public void testNamespacePolicyApi() throws Exception { @Test(timeOut = 30000) public void testNamespacePolicyTakeSnapshot() throws Exception { - super.internalCleanup(); - resetConfig(); + cleanup(); conf.setBrokerDeduplicationEnabled(true); conf.setBrokerDeduplicationSnapshotFrequencyInSeconds(1); conf.setBrokerDeduplicationSnapshotIntervalSeconds(3); conf.setBrokerDeduplicationEntriesInterval(20000); - super.internalSetup(); - super.producerBaseSetup(); + setup(); final String topicName = testTopic + UUID.randomUUID().toString(); final String producerName = "my-producer"; @@ -459,14 +452,12 @@ public void testNamespacePolicyTakeSnapshot() throws Exception { @Test(timeOut = 30000) public void testDisableNamespacePolicyTakeSnapshot() throws Exception { - super.internalCleanup(); - resetConfig(); + cleanup(); conf.setBrokerDeduplicationEnabled(true); conf.setBrokerDeduplicationSnapshotFrequencyInSeconds(1); conf.setBrokerDeduplicationSnapshotIntervalSeconds(1); conf.setBrokerDeduplicationEntriesInterval(20000); - super.internalSetup(); - super.producerBaseSetup(); + setup(); final String topicName = testTopic + UUID.randomUUID().toString(); final String producerName = "my-producer"; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/MetricsAuthenticationTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/MetricsAuthenticationTest.java index a47b8402325f5..0866729586fe9 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/MetricsAuthenticationTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/MetricsAuthenticationTest.java @@ -46,7 +46,6 @@ protected void setup() throws Exception { @Override protected void cleanup() throws Exception { super.internalCleanup(); - resetConfig(); } @Test diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java index b14b5f3802bf3..cfab570301873 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java @@ -96,18 +96,16 @@ protected void setup() throws Exception { @Override protected void cleanup() throws Exception { super.internalCleanup(); - resetConfig(); } @Test public void testPublishRateLimitedTimes() throws Exception { - cleanup(); checkPublishRateLimitedTimes(true); - cleanup(); checkPublishRateLimitedTimes(false); } private void checkPublishRateLimitedTimes(boolean preciseRateLimit) throws Exception { + cleanup(); if (preciseRateLimit) { conf.setBrokerPublisherThrottlingTickTimeMillis(10000000); conf.setMaxPublishRatePerTopicInMessages(1); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/systopic/PartitionedSystemTopicTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/systopic/PartitionedSystemTopicTest.java index b13c8ff2cb2c6..9beebe1883b0a 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/systopic/PartitionedSystemTopicTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/systopic/PartitionedSystemTopicTest.java @@ -69,7 +69,6 @@ public class PartitionedSystemTopicTest extends BrokerTestBase { @BeforeMethod @Override protected void setup() throws Exception { - resetConfig(); conf.setAllowAutoTopicCreation(false); conf.setAllowAutoTopicCreationType("partitioned"); conf.setDefaultNumPartitions(PARTITIONS); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionTestBase.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionTestBase.java index 33a995fae9902..d7a828b1b9f6c 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionTestBase.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionTestBase.java @@ -279,7 +279,7 @@ protected final void internalCleanup() { admin = null; } if (pulsarClient != null) { - pulsarClient.close(); + pulsarClient.shutdown(); pulsarClient = null; } if (pulsarServiceList.size() > 0) { diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthenticationTlsHostnameVerificationTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthenticationTlsHostnameVerificationTest.java index c4be1a419a4dd..c46058a4919d1 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthenticationTlsHostnameVerificationTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthenticationTlsHostnameVerificationTest.java @@ -141,6 +141,7 @@ public Object[][] codecProvider() { public void testTlsSyncProducerAndConsumerWithInvalidBrokerHost(boolean hostnameVerificationEnabled) throws Exception { log.info("-- Starting {} test --", methodName); + cleanup(); this.hostnameVerificationEnabled = hostnameVerificationEnabled; clientTrustCertFilePath = TLS_MIM_TRUST_CERT_FILE_PATH; @@ -184,7 +185,7 @@ public void testTlsSyncProducerAndConsumerWithInvalidBrokerHost(boolean hostname @Test public void testTlsSyncProducerAndConsumerCorrectBrokerHost() throws Exception { log.info("-- Starting {} test --", methodName); - + cleanup(); // setup broker cert which has CN = "localhost" conf.setBrokerServicePortTls(Optional.of(0)); conf.setWebServicePortTls(Optional.of(0)); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthorizationProducerConsumerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthorizationProducerConsumerTest.java index a995e8202d83b..f7e6594576e98 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthorizationProducerConsumerTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthorizationProducerConsumerTest.java @@ -117,7 +117,7 @@ protected void cleanup() throws Exception { @Test public void testProducerAndConsumerAuthorization() throws Exception { log.info("-- Starting {} test --", methodName); - + cleanup(); conf.setAuthorizationProvider(TestAuthorizationProvider.class.getName()); setup(); @@ -177,7 +177,7 @@ public void testProducerAndConsumerAuthorization() throws Exception { @Test public void testSubscriberPermission() throws Exception { log.info("-- Starting {} test --", methodName); - + cleanup(); conf.setEnablePackagesManagement(true); conf.setPackagesManagementStorageProvider(MockedPackagesStorageProvider.class.getName()); conf.setAuthorizationProvider(PulsarAuthorizationProvider.class.getName()); @@ -367,7 +367,7 @@ public void testSubscriberPermission() throws Exception { @Test public void testClearBacklogPermission() throws Exception { log.info("-- Starting {} test --", methodName); - + cleanup(); conf.setAuthorizationProvider(PulsarAuthorizationProvider.class.getName()); setup(); @@ -466,7 +466,7 @@ public void testClearBacklogPermission() throws Exception { @Test public void testSchemaCompatibilityStrategyPermission() throws Exception { log.info("-- Starting {} test --", methodName); - + cleanup(); conf.setAnonymousUserRole("superUser"); conf.setAuthorizationProvider(PulsarAuthorizationProvider.class.getName()); setup(); @@ -551,7 +551,7 @@ public void testSchemaCompatibilityStrategyPermission() throws Exception { @Test public void testSubscriptionPrefixAuthorization() throws Exception { log.info("-- Starting {} test --", methodName); - + cleanup(); conf.setAuthorizationProvider(TestAuthorizationProviderWithSubscriptionPrefix.class.getName()); setup(); @@ -593,7 +593,7 @@ public void testSubscriptionPrefixAuthorization() throws Exception { @Test public void testGrantPermission() throws Exception { log.info("-- Starting {} test --", methodName); - + cleanup(); conf.setAuthorizationProvider(TestAuthorizationProviderWithGrantPermission.class.getName()); setup(); @@ -612,7 +612,7 @@ public void testGrantPermission() throws Exception { @Test public void testAuthData() throws Exception { log.info("-- Starting {} test --", methodName); - + cleanup(); conf.setAuthorizationProvider(TestAuthorizationProviderWithGrantPermission.class.getName()); setup(); @@ -635,7 +635,7 @@ public void testAuthData() throws Exception { @Test public void testPermissionForProducerCreateInitialSubscription() throws Exception { log.info("-- Starting {} test --", methodName); - + cleanup(); conf.setAuthorizationProvider(PulsarAuthorizationProvider.class.getName()); setup(); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/KeySharedSubscriptionTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/KeySharedSubscriptionTest.java index c5d716de01112..8742b8798b49e 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/KeySharedSubscriptionTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/KeySharedSubscriptionTest.java @@ -112,7 +112,6 @@ public Object[][] topicDomainProvider() { @BeforeMethod(alwaysRun = true) @Override protected void setup() throws Exception { - super.resetConfig(); super.internalSetup(); super.producerBaseSetup(); this.conf.setSubscriptionKeySharedUseConsistentHashing(true); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/MessageDispatchThrottlingTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/MessageDispatchThrottlingTest.java index 1d0b1be365934..23b4ea4f3815b 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/MessageDispatchThrottlingTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/MessageDispatchThrottlingTest.java @@ -79,7 +79,6 @@ protected void setup() throws Exception { @Override protected void cleanup() throws Exception { super.internalCleanup(); - super.resetConfig(); } @DataProvider(name = "subscriptions") @@ -1195,7 +1194,7 @@ public void testRelativeMessageRateLimitingThrottling(SubscriptionType subscript /** * Validates that backlog consumers cache the reads and reused by other backlog consumers while draining the * backlog. - * + * * @throws Exception */ @Test diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessagePublishThrottlingTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessagePublishThrottlingTest.java index 2049050fa8d64..d838c06ed217c 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessagePublishThrottlingTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessagePublishThrottlingTest.java @@ -64,7 +64,6 @@ protected void setup() throws Exception { @Override protected void cleanup() throws Exception { super.internalCleanup(); - super.resetConfig(); } /** diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/NegativeAcksTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/NegativeAcksTest.java index c5d030380393a..769b832ab778d 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/NegativeAcksTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/NegativeAcksTest.java @@ -299,7 +299,7 @@ public void testNegativeAcksDeleteFromUnackedTracker() throws Exception { @Test(timeOut = 10000) public void testNegativeAcksWithBatchAckEnabled() throws Exception { - stopBroker(); + cleanup(); conf.setAcknowledgmentAtBatchIndexLevelEnabled(true); setup(); String topic = BrokerTestUtil.newUniqueName("testNegativeAcksWithBatchAckEnabled"); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PatternTopicsConsumerImplTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PatternTopicsConsumerImplTest.java index 38f2ca366bb98..85be004b732e3 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PatternTopicsConsumerImplTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PatternTopicsConsumerImplTest.java @@ -228,16 +228,15 @@ public void testBinaryProtoToGetTopicsOfNamespacePersistent() throws Exception { @Test(timeOut = testTimeout) public void testPubRateOnNonPersistent() throws Exception { - internalCleanup(); + cleanup(); conf.setMaxPublishRatePerTopicInBytes(10000L); conf.setMaxPublishRatePerTopicInMessages(100); Thread.sleep(500); isTcpLookup = true; - super.internalSetup(); - super.producerBaseSetup(); + setup(); testBinaryProtoToGetTopicsOfNamespaceNonPersistent(); } - + // verify consumer create success, and works well. @Test(timeOut = testTimeout) public void testBinaryProtoToGetTopicsOfNamespaceNonPersistent() throws Exception { diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicPublishThrottlingInitTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicPublishThrottlingInitTest.java index 76c0d7e46f8e0..ee8961d008c78 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicPublishThrottlingInitTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicPublishThrottlingInitTest.java @@ -52,7 +52,6 @@ protected void setup() throws Exception { @Override protected void cleanup() throws Exception { super.internalCleanup(); - super.resetConfig(); } /** diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/schema/SchemaTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/schema/SchemaTest.java index 0620326e94d75..9974ac8c544b1 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/schema/SchemaTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/schema/SchemaTest.java @@ -987,7 +987,7 @@ public void testProducerMultipleSchemaMessages() throws Exception { producer.newMessage(Schema.BYTES).value("test".getBytes(StandardCharsets.UTF_8)).send(); producer.newMessage(Schema.BYTES).value("test".getBytes(StandardCharsets.UTF_8)).send(); producer.newMessage(Schema.BOOL).value(true).send(); - + Schema personThreeSchema = Schema.AVRO(Schemas.PersonThree.class); byte[] personThreeSchemaBytes = personThreeSchema.getSchemaInfo().getSchema(); org.apache.avro.Schema personThreeSchemaAvroNative = new Parser().parse(new ByteArrayInputStream(personThreeSchemaBytes)); @@ -1216,7 +1216,7 @@ private void checkSchemaForAutoSchema(Message message) { @Test public void testAvroSchemaWithHttpLookup() throws Exception { - stopBroker(); + cleanup(); isTcpLookup = false; setup(); testIncompatibleSchema(); @@ -1224,7 +1224,7 @@ public void testAvroSchemaWithHttpLookup() throws Exception { @Test public void testAvroSchemaWithTcpLookup() throws Exception { - stopBroker(); + cleanup(); isTcpLookup = true; setup(); testIncompatibleSchema(); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/websocket/proxy/ProxyEncryptionPublishConsumeTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/websocket/proxy/ProxyEncryptionPublishConsumeTest.java index 87741e5bede1d..2b5fe4c55cb54 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/websocket/proxy/ProxyEncryptionPublishConsumeTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/websocket/proxy/ProxyEncryptionPublishConsumeTest.java @@ -87,7 +87,6 @@ public void setup() throws Exception { @AfterMethod(alwaysRun = true) protected void cleanup() throws Exception { - super.resetConfig(); super.internalCleanup(); if (service != null) { service.close(); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/websocket/proxy/ProxyPublishConsumeTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/websocket/proxy/ProxyPublishConsumeTest.java index 951a3db4f0291..7abdc643462da 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/websocket/proxy/ProxyPublishConsumeTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/websocket/proxy/ProxyPublishConsumeTest.java @@ -109,7 +109,6 @@ public void setup() throws Exception { @AfterMethod(alwaysRun = true) protected void cleanup() throws Exception { - super.resetConfig(); super.internalCleanup(); if (service != null) { service.close(); diff --git a/pulsar-client-tools-test/src/test/java/org/apache/pulsar/client/cli/DocumentTest.java b/pulsar-client-tools-test/src/test/java/org/apache/pulsar/client/cli/DocumentTest.java index 25c9b2ed3df1a..c4243ad72fcb4 100644 --- a/pulsar-client-tools-test/src/test/java/org/apache/pulsar/client/cli/DocumentTest.java +++ b/pulsar-client-tools-test/src/test/java/org/apache/pulsar/client/cli/DocumentTest.java @@ -42,7 +42,6 @@ protected void setup() throws Exception { @AfterMethod(alwaysRun = true) @Override protected void cleanup() throws Exception { - super.resetConfig(); super.internalCleanup(); } diff --git a/pulsar-client-tools-test/src/test/java/org/apache/pulsar/client/cli/PulsarClientToolWsTest.java b/pulsar-client-tools-test/src/test/java/org/apache/pulsar/client/cli/PulsarClientToolWsTest.java index 6b6e5a1c9af75..be75cf873e17c 100644 --- a/pulsar-client-tools-test/src/test/java/org/apache/pulsar/client/cli/PulsarClientToolWsTest.java +++ b/pulsar-client-tools-test/src/test/java/org/apache/pulsar/client/cli/PulsarClientToolWsTest.java @@ -46,7 +46,6 @@ protected void setup() throws Exception { @AfterMethod(alwaysRun = true) @Override protected void cleanup() throws Exception { - super.resetConfig(); super.internalCleanup(); }