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 2024/04/26 12:10:43 UTC
(pulsar) 02/02: [fix][test] Clear fields in test cleanup to reduce memory consumption (#22583)
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 72833feba28740b7f02e1978edae7baf36a462bf
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Thu Apr 25 21:54:55 2024 +0300
[fix][test] Clear fields in test cleanup to reduce memory consumption (#22583)
(cherry picked from commit 3de14c55de138770ed61d1a14cd883048ea1915c)
---
.../pulsar/broker/MultiBrokerTestZKBaseTest.java | 1 +
.../apache/pulsar/broker/SLAMonitoringTest.java | 21 +++++++--
.../loadbalance/LeaderElectionServiceTest.java | 5 +-
.../broker/loadbalance/LoadBalancerTest.java | 11 ++++-
.../loadbalance/SimpleLoadManagerImplTest.java | 30 +++++++++---
.../loadbalance/extensions/BrokerRegistryTest.java | 10 +++-
.../ExtensibleLoadManagerImplBaseTest.java | 8 +++-
.../loadbalance/impl/BundleSplitterTaskTest.java | 10 +++-
.../impl/ModularLoadManagerImplTest.java | 35 ++++++++++----
.../broker/service/AdvertisedAddressTest.java | 10 +++-
.../pulsar/broker/service/BkEnsemblesTestBase.java | 15 ++++--
.../broker/service/BrokerBookieIsolationTest.java | 6 ++-
.../CanReconnectZKClientPulsarServiceBaseTest.java | 24 +++++++---
.../pulsar/broker/service/MaxMessageSizeTest.java | 14 +++++-
.../broker/service/OneWayReplicatorTestBase.java | 44 ++++++++++++++----
.../pulsar/broker/service/ReplicatorTest.java | 8 ++--
.../pulsar/broker/service/ReplicatorTestBase.java | 53 ++++++++++++++++------
.../pulsar/broker/service/TopicOwnerTest.java | 15 ++++--
.../coordinator/TransactionMetaStoreTestBase.java | 17 ++++---
.../client/api/ClientDeduplicationFailureTest.java | 20 ++++++--
.../worker/PulsarFunctionE2ESecurityTest.java | 25 ++++++++--
.../worker/PulsarFunctionPublishTest.java | 25 ++++++++--
.../functions/worker/PulsarFunctionTlsTest.java | 8 +++-
.../worker/PulsarWorkerAssignmentTest.java | 25 ++++++++--
.../apache/pulsar/io/AbstractPulsarE2ETest.java | 42 +++++++++--------
.../apache/pulsar/io/PulsarFunctionAdminTest.java | 25 ++++++++--
.../apache/pulsar/io/PulsarFunctionTlsTest.java | 20 ++++++--
.../pulsar/zookeeper/ZookeeperServerTest.java | 15 ++++--
.../org/apache/pulsar/metadata/TestZKServer.java | 1 +
29 files changed, 414 insertions(+), 129 deletions(-)
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/MultiBrokerTestZKBaseTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/MultiBrokerTestZKBaseTest.java
index 0cd5bce5d51..b1e608b620a 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/MultiBrokerTestZKBaseTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/MultiBrokerTestZKBaseTest.java
@@ -48,6 +48,7 @@ public abstract class MultiBrokerTestZKBaseTest extends MultiBrokerBaseTest {
} catch (Exception e) {
log.error("Error in stopping ZK server", e);
}
+ testZKServer = null;
}
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/SLAMonitoringTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/SLAMonitoringTest.java
index 4a6524bf245..941229fc3d9 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/SLAMonitoringTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/SLAMonitoringTest.java
@@ -126,15 +126,26 @@ public class SLAMonitoringTest {
@AfterClass(alwaysRun = true)
public void shutdown() throws Exception {
log.info("--- Shutting down ---");
- executor.shutdownNow();
- executor = null;
+ if (executor != null) {
+ executor.shutdownNow();
+ executor = null;
+ }
for (int i = 0; i < BROKER_COUNT; i++) {
- pulsarAdmins[i].close();
- pulsarServices[i].close();
+ if (pulsarAdmins[i] != null) {
+ pulsarAdmins[i].close();
+ pulsarAdmins[i] = null;
+ }
+ if (pulsarServices[i] != null) {
+ pulsarServices[i].close();
+ pulsarServices[i] = null;
+ }
}
- bkEnsemble.stop();
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
}
@Test
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LeaderElectionServiceTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LeaderElectionServiceTest.java
index ded4ee8e58d..358410f1f28 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LeaderElectionServiceTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LeaderElectionServiceTest.java
@@ -59,7 +59,10 @@ public class LeaderElectionServiceTest {
@AfterMethod(alwaysRun = true)
void shutdown() throws Exception {
- bkEnsemble.stop();
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
log.info("---- bk stopped ----");
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LoadBalancerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LoadBalancerTest.java
index 04a2175b1d1..f2a9e8643b2 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LoadBalancerTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LoadBalancerTest.java
@@ -153,13 +153,20 @@ public class LoadBalancerTest {
executor.shutdownNow();
for (int i = 0; i < BROKER_COUNT; i++) {
- pulsarAdmins[i].close();
+ if (pulsarAdmins[i] != null) {
+ pulsarAdmins[i].close();
+ pulsarAdmins[i] = null;
+ }
if (pulsarServices[i] != null) {
pulsarServices[i].close();
+ pulsarServices[i] = null;
}
}
- bkEnsemble.stop();
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
}
private void loopUntilLeaderChangesForAllBroker(List<PulsarService> activePulsars, LeaderBroker oldLeader) {
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/SimpleLoadManagerImplTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/SimpleLoadManagerImplTest.java
index f92faa3e4bd..f6ee4ea95b6 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/SimpleLoadManagerImplTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/SimpleLoadManagerImplTest.java
@@ -163,15 +163,33 @@ public class SimpleLoadManagerImplTest {
@AfterMethod(alwaysRun = true)
void shutdown() throws Exception {
log.info("--- Shutting down ---");
- executor.shutdownNow();
+ if (executor != null) {
+ executor.shutdownNow();
+ executor = null;
+ }
- admin1.close();
- admin2.close();
+ if (admin1 != null) {
+ admin1.close();
+ admin1 = null;
+ }
+ if (admin2 != null) {
+ admin2.close();
+ admin2 = null;
+ }
- pulsar2.close();
- pulsar1.close();
+ if (pulsar2 != null) {
+ pulsar2.close();
+ pulsar2 = null;
+ }
+ if (pulsar1 != null) {
+ pulsar1.close();
+ pulsar1 = null;
+ }
- bkEnsemble.stop();
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
}
private void createNamespacePolicies(PulsarService pulsar) throws Exception {
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/extensions/BrokerRegistryTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/extensions/BrokerRegistryTest.java
index e199e695cf7..4945da7a4f0 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/extensions/BrokerRegistryTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/extensions/BrokerRegistryTest.java
@@ -193,8 +193,14 @@ public class BrokerRegistryTest {
@AfterClass(alwaysRun = true)
void shutdown() throws Exception {
- executor.shutdownNow();
- bkEnsemble.stop();
+ if (executor != null) {
+ executor.shutdownNow();
+ executor = null;
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
}
@AfterMethod(alwaysRun = true)
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/extensions/ExtensibleLoadManagerImplBaseTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/extensions/ExtensibleLoadManagerImplBaseTest.java
index c74820e69a1..1d0b2f4216f 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/extensions/ExtensibleLoadManagerImplBaseTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/extensions/ExtensibleLoadManagerImplBaseTest.java
@@ -99,8 +99,14 @@ public abstract class ExtensibleLoadManagerImplBaseTest extends MockedPulsarServ
@Override
@AfterClass(alwaysRun = true)
protected void cleanup() throws Exception {
- this.additionalPulsarTestContext.close();
+ if (additionalPulsarTestContext != null) {
+ additionalPulsarTestContext.close();
+ additionalPulsarTestContext = null;
+ }
super.internalCleanup();
+ pulsar1 = pulsar2 = null;
+ primaryLoadManager = secondaryLoadManager = null;
+ channel1 = channel2 = null;
}
@BeforeMethod(alwaysRun = true)
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/BundleSplitterTaskTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/BundleSplitterTaskTest.java
index 3173987a3c8..bc49352f41d 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/BundleSplitterTaskTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/BundleSplitterTaskTest.java
@@ -150,8 +150,14 @@ public class BundleSplitterTaskTest {
@AfterMethod(alwaysRun = true)
void shutdown() throws Exception {
log.info("--- Shutting down ---");
- pulsar.close();
- bkEnsemble.stop();
+ if (pulsar != null) {
+ pulsar.close();
+ pulsar = null;
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
}
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImplTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImplTest.java
index 8609d5889af..75ca0a1bf55 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImplTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImplTest.java
@@ -224,19 +224,36 @@ public class ModularLoadManagerImplTest {
@AfterMethod(alwaysRun = true)
void shutdown() throws Exception {
log.info("--- Shutting down ---");
- executor.shutdownNow();
-
- admin1.close();
- admin2.close();
+ if (executor != null) {
+ executor.shutdownNow();
+ executor = null;
+ }
- pulsar2.close();
- pulsar1.close();
+ if (admin1 != null) {
+ admin1.close();
+ admin1 = null;
+ }
+ if (admin2 != null) {
+ admin2.close();
+ admin2 = null;
+ }
- if (pulsar3.isRunning()) {
+ if (pulsar2 != null) {
+ pulsar2.close();
+ pulsar2 = null;
+ }
+ if (pulsar1 != null) {
+ pulsar1.close();
+ pulsar1 = null;
+ }
+ if (pulsar3 != null && pulsar3.isRunning()) {
pulsar3.close();
}
-
- bkEnsemble.stop();
+ pulsar3 = null;
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
}
private NamespaceBundle makeBundle(final String property, final String cluster, final String namespace) {
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/AdvertisedAddressTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/AdvertisedAddressTest.java
index 19e40ebf996..a60d6599e8f 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/AdvertisedAddressTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/AdvertisedAddressTest.java
@@ -66,8 +66,14 @@ public class AdvertisedAddressTest {
@AfterMethod(alwaysRun = true)
public void shutdown() throws Exception {
- pulsar.close();
- bkEnsemble.stop();
+ if (pulsar != null) {
+ pulsar.close();
+ pulsar = null;
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
}
@Test
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BkEnsemblesTestBase.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BkEnsemblesTestBase.java
index 9b3d145dea2..2402bbe9367 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BkEnsemblesTestBase.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BkEnsemblesTestBase.java
@@ -116,9 +116,18 @@ public abstract class BkEnsemblesTestBase extends TestRetrySupport {
protected void cleanup() throws Exception {
config = null;
markCurrentSetupNumberCleaned();
- admin.close();
- pulsar.close();
- bkEnsemble.stop();
+ if (admin != null) {
+ admin.close();
+ admin = null;
+ }
+ if (pulsar != null) {
+ pulsar.close();
+ pulsar = null;
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
}
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerBookieIsolationTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerBookieIsolationTest.java
index 3b2f3cf215e..f08edc36898 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerBookieIsolationTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerBookieIsolationTest.java
@@ -105,8 +105,12 @@ public class BrokerBookieIsolationTest {
protected void cleanup() throws Exception {
if (pulsarService != null) {
pulsarService.close();
+ pulsarService = null;
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
}
- bkEnsemble.stop();
}
/**
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/CanReconnectZKClientPulsarServiceBaseTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/CanReconnectZKClientPulsarServiceBaseTest.java
index bc6df685ffc..a1cb4abc4c3 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/CanReconnectZKClientPulsarServiceBaseTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/CanReconnectZKClientPulsarServiceBaseTest.java
@@ -43,7 +43,6 @@ import org.awaitility.reflect.WhiteboxImpl;
@Slf4j
public abstract class CanReconnectZKClientPulsarServiceBaseTest extends TestRetrySupport {
-
protected final String defaultTenant = "public";
protected final String defaultNamespace = defaultTenant + "/default";
protected int numberOfBookies = 3;
@@ -60,6 +59,7 @@ public abstract class CanReconnectZKClientPulsarServiceBaseTest extends TestRetr
protected ZooKeeper localZkOfBroker;
protected Object localMetaDataStoreClientCnx;
protected final AtomicBoolean LocalMetadataStoreInReconnectFinishSignal = new AtomicBoolean();
+
protected void startZKAndBK() throws Exception {
// Start ZK.
brokerConfigZk = new ZookeeperServerTest(0);
@@ -198,18 +198,30 @@ public abstract class CanReconnectZKClientPulsarServiceBaseTest extends TestRetr
stopLocalMetadataStoreAlwaysReconnect();
// Stop brokers.
- client.close();
- admin.close();
+ if (client != null) {
+ client.close();
+ client = null;
+ }
+ if (admin != null) {
+ admin.close();
+ admin = null;
+ }
if (pulsar != null) {
pulsar.close();
+ pulsar = null;
}
// Stop ZK and BK.
- bkEnsemble.stop();
- brokerConfigZk.stop();
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
+ if (brokerConfigZk != null) {
+ brokerConfigZk.stop();
+ brokerConfigZk = null;
+ }
// Reset configs.
config = new ServiceConfiguration();
- setConfigDefaults(config, clusterName, bkEnsemble, brokerConfigZk);
}
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/MaxMessageSizeTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/MaxMessageSizeTest.java
index fb15661fddf..84543a82d77 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/MaxMessageSizeTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/MaxMessageSizeTest.java
@@ -91,8 +91,18 @@ public class MaxMessageSizeTest {
@AfterMethod(alwaysRun = true)
void shutdown() {
try {
- pulsar.close();
- bkEnsemble.stop();
+ if (admin != null) {
+ admin.close();
+ admin = null;
+ }
+ if (pulsar != null) {
+ pulsar.close();
+ pulsar = null;
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
} catch (Throwable t) {
t.printStackTrace();
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/OneWayReplicatorTestBase.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/OneWayReplicatorTestBase.java
index 33620716288..795983f7482 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/OneWayReplicatorTestBase.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/OneWayReplicatorTestBase.java
@@ -193,27 +193,51 @@ public abstract class OneWayReplicatorTestBase extends TestRetrySupport {
log.info("--- Shutting down ---");
// Stop brokers.
- client1.close();
- client2.close();
- admin1.close();
- admin2.close();
+ if (client1 != null) {
+ client1.close();
+ client1 = null;
+ }
+ if (client2 != null) {
+ client2.close();
+ client2 = null;
+ }
+ if (admin1 != null) {
+ admin1.close();
+ admin1 = null;
+ }
+ if (admin2 != null) {
+ admin2.close();
+ admin2 = null;
+ }
if (pulsar2 != null) {
pulsar2.close();
+ pulsar2 = null;
}
if (pulsar1 != null) {
pulsar1.close();
+ pulsar1 = null;
}
// Stop ZK and BK.
- bkEnsemble1.stop();
- bkEnsemble2.stop();
- brokerConfigZk1.stop();
- brokerConfigZk2.stop();
+ if (bkEnsemble1 != null) {
+ bkEnsemble1.stop();
+ bkEnsemble1 = null;
+ }
+ if (bkEnsemble2 != null) {
+ bkEnsemble2.stop();
+ bkEnsemble2 = null;
+ }
+ if (brokerConfigZk1 != null) {
+ brokerConfigZk1.stop();
+ brokerConfigZk1 = null;
+ }
+ if (brokerConfigZk2 != null) {
+ brokerConfigZk2.stop();
+ brokerConfigZk2 = null;
+ }
// Reset configs.
config1 = new ServiceConfiguration();
- setConfigDefaults(config1, cluster1, bkEnsemble1, brokerConfigZk1);
config2 = new ServiceConfiguration();
- setConfigDefaults(config2, cluster2, bkEnsemble2, brokerConfigZk2);
}
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTest.java
index 3fa3a8dfc0f..bd0496e0718 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTest.java
@@ -130,9 +130,11 @@ public class ReplicatorTest extends ReplicatorTestBase {
@BeforeMethod(alwaysRun = true)
public void beforeMethod(Method m) throws Exception {
methodName = m.getName();
- admin1.namespaces().removeBacklogQuota("pulsar/ns");
- admin1.namespaces().removeBacklogQuota("pulsar/ns1");
- admin1.namespaces().removeBacklogQuota("pulsar/global/ns");
+ if (admin1 != null) {
+ admin1.namespaces().removeBacklogQuota("pulsar/ns");
+ admin1.namespaces().removeBacklogQuota("pulsar/ns1");
+ admin1.namespaces().removeBacklogQuota("pulsar/global/ns");
+ }
}
@Override
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTestBase.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTestBase.java
index beb1a3c4b93..97a2f633d81 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTestBase.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTestBase.java
@@ -348,22 +348,18 @@ public abstract class ReplicatorTestBase extends TestRetrySupport {
public void resetConfig1() {
config1 = new ServiceConfiguration();
- setConfig1DefaultValue();
}
public void resetConfig2() {
config2 = new ServiceConfiguration();
- setConfig2DefaultValue();
}
public void resetConfig3() {
config3 = new ServiceConfiguration();
- setConfig3DefaultValue();
}
public void resetConfig4() {
config4 = new ServiceConfiguration();
- setConfig4DefaultValue();
}
private int inSec(int time, TimeUnit unit) {
@@ -379,29 +375,60 @@ public abstract class ReplicatorTestBase extends TestRetrySupport {
executor = null;
}
- admin1.close();
- admin2.close();
- admin3.close();
- admin4.close();
+ if (admin1 != null) {
+ admin1.close();
+ admin1 = null;
+ }
+ if (admin2 != null) {
+ admin2.close();
+ admin2 = null;
+ }
+ if (admin3 != null) {
+ admin3.close();
+ admin3 = null;
+ }
+ if (admin4 != null) {
+ admin4.close();
+ admin4 = null;
+ }
if (pulsar4 != null) {
pulsar4.close();
+ pulsar4 = null;
}
if (pulsar3 != null) {
pulsar3.close();
+ pulsar3 = null;
}
if (pulsar2 != null) {
pulsar2.close();
+ pulsar2 = null;
}
if (pulsar1 != null) {
pulsar1.close();
+ pulsar1 = null;
}
- bkEnsemble1.stop();
- bkEnsemble2.stop();
- bkEnsemble3.stop();
- bkEnsemble4.stop();
- globalZkS.stop();
+ if (bkEnsemble1 != null) {
+ bkEnsemble1.stop();
+ bkEnsemble1 = null;
+ }
+ if (bkEnsemble2 != null) {
+ bkEnsemble2.stop();
+ bkEnsemble2 = null;
+ }
+ if (bkEnsemble3 != null) {
+ bkEnsemble3.stop();
+ bkEnsemble3 = null;
+ }
+ if (bkEnsemble4 != null) {
+ bkEnsemble4.stop();
+ bkEnsemble4 = null;
+ }
+ if (globalZkS != null) {
+ globalZkS.stop();
+ globalZkS = null;
+ }
resetConfig1();
resetConfig2();
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/TopicOwnerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/TopicOwnerTest.java
index 5a8fd34c9cd..521d68cebe5 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/TopicOwnerTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/TopicOwnerTest.java
@@ -117,10 +117,19 @@ public class TopicOwnerTest {
@AfterMethod(alwaysRun = true)
void tearDown() throws Exception {
for (int i = 0; i < BROKER_COUNT; i++) {
- pulsarServices[i].close();
- pulsarAdmins[i].close();
+ if (pulsarAdmins[i] != null) {
+ pulsarAdmins[i].close();
+ pulsarAdmins[i] = null;
+ }
+ if (pulsarServices[i] != null) {
+ pulsarServices[i].close();
+ pulsarServices[i] = null;
+ }
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
}
- bkEnsemble.stop();
}
@SuppressWarnings("unchecked")
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/coordinator/TransactionMetaStoreTestBase.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/coordinator/TransactionMetaStoreTestBase.java
index 7a0fb48f911..5bf48932f36 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/coordinator/TransactionMetaStoreTestBase.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/coordinator/TransactionMetaStoreTestBase.java
@@ -122,22 +122,27 @@ public abstract class TransactionMetaStoreTestBase extends TestRetrySupport {
protected void cleanup() throws Exception {
if (transactionCoordinatorClient != null) {
transactionCoordinatorClient.close();
+ transactionCoordinatorClient = null;
}
- for (PulsarAdmin admin : pulsarAdmins) {
- if (admin != null) {
- admin.close();
+ for (int i = 0; i < BROKER_COUNT; i++) {
+ if (pulsarAdmins[i] != null) {
+ pulsarAdmins[i].close();
+ pulsarAdmins[i] = null;
}
}
if (pulsarClient != null) {
pulsarClient.close();
+ pulsarClient = null;
}
- for (PulsarService service : pulsarServices) {
- if (service != null) {
- service.close();
+ for (int i = 0; i < BROKER_COUNT; i++) {
+ if (pulsarServices[i] != null) {
+ pulsarServices[i].close();
+ pulsarServices[i] = null;
}
}
if (bkEnsemble != null) {
bkEnsemble.stop();
+ bkEnsemble = null;
}
Mockito.reset();
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ClientDeduplicationFailureTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ClientDeduplicationFailureTest.java
index 6b3b05405ba..601a8d76aaa 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ClientDeduplicationFailureTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ClientDeduplicationFailureTest.java
@@ -127,10 +127,22 @@ public class ClientDeduplicationFailureTest {
@AfterMethod(alwaysRun = true)
void shutdown() throws Exception {
log.info("--- Shutting down ---");
- pulsarClient.close();
- admin.close();
- pulsar.close();
- bkEnsemble.stop();
+ if (pulsarClient != null) {
+ pulsarClient.close();
+ pulsar = null;
+ }
+ if (admin != null) {
+ admin.close();
+ admin = null;
+ }
+ if (pulsar != null) {
+ pulsar.close();
+ pulsar = null;
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
}
private static class ProducerThread implements Runnable {
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionE2ESecurityTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionE2ESecurityTest.java
index cbf2f28b0b5..e9b3531c7c2 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionE2ESecurityTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionE2ESecurityTest.java
@@ -216,11 +216,26 @@ public class PulsarFunctionE2ESecurityTest {
void shutdown() throws Exception {
try {
log.info("--- Shutting down ---");
- pulsarClient.close();
- superUserAdmin.close();
- functionsWorkerService.stop();
- pulsar.close();
- bkEnsemble.stop();
+ if (pulsarClient != null) {
+ pulsarClient.close();
+ pulsarClient = null;
+ }
+ if (superUserAdmin != null) {
+ superUserAdmin.close();
+ superUserAdmin = null;
+ }
+ if (functionsWorkerService != null) {
+ functionsWorkerService.stop();
+ functionsWorkerService = null;
+ }
+ if (pulsar != null) {
+ pulsar.close();
+ pulsar = null;
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
} finally {
if (tempDirectory != null) {
tempDirectory.delete();
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionPublishTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionPublishTest.java
index 72e6a3766ae..68afa83e88b 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionPublishTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionPublishTest.java
@@ -218,11 +218,26 @@ public class PulsarFunctionPublishTest {
void shutdown() throws Exception {
try {
log.info("--- Shutting down ---");
- pulsarClient.close();
- admin.close();
- functionsWorkerService.stop();
- pulsar.close();
- bkEnsemble.stop();
+ if (pulsarClient != null) {
+ pulsarClient.close();
+ pulsarClient = null;
+ }
+ if (admin != null) {
+ admin.close();
+ admin = null;
+ }
+ if (functionsWorkerService != null) {
+ functionsWorkerService.stop();
+ functionsWorkerService = null;
+ }
+ if (pulsar != null) {
+ pulsar.close();
+ pulsar = null;
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
} finally {
if (tempDirectory != null) {
tempDirectory.delete();
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionTlsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionTlsTest.java
index 3508cf0bfc7..3be16357d33 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionTlsTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionTlsTest.java
@@ -202,11 +202,13 @@ public class PulsarFunctionTlsTest {
for (int i = 0; i < BROKER_COUNT; i++) {
if (pulsarAdmins[i] != null) {
pulsarAdmins[i].close();
+ pulsarAdmins[i] = null;
}
}
for (int i = 0; i < BROKER_COUNT; i++) {
if (fnWorkerServices[i] != null) {
fnWorkerServices[i].stop();
+ fnWorkerServices[i] = null;
}
}
for (int i = 0; i < BROKER_COUNT; i++) {
@@ -221,9 +223,13 @@ public class PulsarFunctionTlsTest {
getBrokerServicePort().ifPresent(PortManager::releaseLockedPort);
pulsarServices[i].getConfiguration()
.getWebServicePort().ifPresent(PortManager::releaseLockedPort);
+ pulsarServices[i] = null;
}
}
- bkEnsemble.stop();
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
} finally {
for (int i = 0; i < BROKER_COUNT; i++) {
if (tempDirectories[i] != null) {
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarWorkerAssignmentTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarWorkerAssignmentTest.java
index 6226fa90488..9c137e37095 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarWorkerAssignmentTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarWorkerAssignmentTest.java
@@ -131,11 +131,26 @@ public class PulsarWorkerAssignmentTest {
void shutdown() {
log.info("--- Shutting down ---");
try {
- pulsarClient.close();
- admin.close();
- functionsWorkerService.stop();
- pulsar.close();
- bkEnsemble.stop();
+ if (pulsarClient != null) {
+ pulsarClient.close();
+ pulsarClient = null;
+ }
+ if (admin != null) {
+ admin.close();
+ admin = null;
+ }
+ if (functionsWorkerService != null) {
+ functionsWorkerService.stop();
+ functionsWorkerService = null;
+ }
+ if (pulsar != null) {
+ pulsar.close();
+ pulsar = null;
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
} catch (Exception e) {
log.warn("Encountered errors at shutting down PulsarWorkerAssignmentTest", e);
} finally {
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/io/AbstractPulsarE2ETest.java b/pulsar-broker/src/test/java/org/apache/pulsar/io/AbstractPulsarE2ETest.java
index 3c0dd0822b7..d27e2763904 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/io/AbstractPulsarE2ETest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/io/AbstractPulsarE2ETest.java
@@ -239,29 +239,35 @@ public abstract class AbstractPulsarE2ETest {
void shutdown() throws Exception {
log.info("--- Shutting down ---");
try {
- if (fileServer != null) {
- fileServer.stop();
- }
+ if (fileServer != null) {
+ fileServer.stop();
+ fileServer = null;
+ }
- if (pulsarClient != null) {
- pulsarClient.close();
- }
+ if (pulsarClient != null) {
+ pulsarClient.close();
+ pulsarClient = null;
+ }
- if (admin != null) {
- admin.close();
- }
+ if (admin != null) {
+ admin.close();
+ admin = null;
+ }
- if (functionsWorkerService != null) {
- functionsWorkerService.stop();
- }
+ if (functionsWorkerService != null) {
+ functionsWorkerService.stop();
+ functionsWorkerService = null;
+ }
- if (pulsar != null) {
- pulsar.close();
- }
+ if (pulsar != null) {
+ pulsar.close();
+ pulsar = null;
+ }
- if (bkEnsemble != null) {
- bkEnsemble.stop();
- }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
} finally {
if (tempDirectory != null) {
tempDirectory.delete();
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionAdminTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionAdminTest.java
index 22b9ad0df3a..aafd82d339a 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionAdminTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionAdminTest.java
@@ -172,11 +172,26 @@ public class PulsarFunctionAdminTest {
@AfterMethod(alwaysRun = true)
void shutdown() throws Exception {
log.info("--- Shutting down ---");
- pulsarClient.close();
- admin.close();
- functionsWorkerService.stop();
- pulsar.close();
- bkEnsemble.stop();
+ if (pulsarClient != null) {
+ pulsarClient.close();
+ pulsarClient = null;
+ }
+ if (admin != null) {
+ admin.close();
+ admin = null;
+ }
+ if (functionsWorkerService != null) {
+ functionsWorkerService.stop();
+ functionsWorkerService = null;
+ }
+ if (pulsar != null) {
+ pulsar.close();
+ pulsar = null;
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
}
private PulsarWorkerService createPulsarFunctionWorker(ServiceConfiguration config) {
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionTlsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionTlsTest.java
index 810ac69ac3e..da479321b8b 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionTlsTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionTlsTest.java
@@ -180,10 +180,22 @@ public class PulsarFunctionTlsTest {
void shutdown() throws Exception {
log.info("--- Shutting down ---");
try {
- functionAdmin.close();
- functionsWorkerService.stop();
- workerServer.stop();
- bkEnsemble.stop();
+ if (functionAdmin != null) {
+ functionAdmin.close();
+ functionAdmin = null;
+ }
+ if (functionsWorkerService != null) {
+ functionsWorkerService.stop();
+ functionsWorkerService = null;
+ }
+ if (workerServer != null) {
+ workerServer.stop();
+ workerServer = null;
+ }
+ if (bkEnsemble != null) {
+ bkEnsemble.stop();
+ bkEnsemble = null;
+ }
} finally {
if (tempDirectory != null) {
tempDirectory.delete();
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/zookeeper/ZookeeperServerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/zookeeper/ZookeeperServerTest.java
index 013bc23d663..355d2a0b1db 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/zookeeper/ZookeeperServerTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/zookeeper/ZookeeperServerTest.java
@@ -68,15 +68,20 @@ public class ZookeeperServerTest implements Closeable {
}
public void stop() throws IOException {
- zks.shutdown();
- serverFactory.shutdown();
- log.info("Stoppend ZK server at {}", hostPort);
+ if (zks != null) {
+ zks.shutdown();
+ zks = null;
+ }
+ if (serverFactory != null) {
+ serverFactory.shutdown();
+ serverFactory = null;
+ }
+ log.info("Stopped ZK server at {}", hostPort);
}
@Override
public void close() throws IOException {
- zks.shutdown();
- serverFactory.shutdown();
+ stop();
zkTmpDir.delete();
}
diff --git a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/TestZKServer.java b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/TestZKServer.java
index 33034ddb3fe..0d01d9c56ab 100644
--- a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/TestZKServer.java
+++ b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/TestZKServer.java
@@ -131,6 +131,7 @@ public class TestZKServer implements AutoCloseable {
public void stop() throws Exception {
if (zooKeeperServerEmbedded != null) {
zooKeeperServerEmbedded.close();
+ zooKeeperServerEmbedded = null;
}
log.info("Stopped test ZK server");
}