Skip to content

Commit

Permalink
[fix][test] Clear fields in test cleanup to reduce memory consumption (
Browse files Browse the repository at this point in the history
…apache#22583)

(cherry picked from commit 3de14c5)
  • Loading branch information
lhotari committed Apr 26, 2024
1 parent 8ecfd64 commit 72833fe
Show file tree
Hide file tree
Showing 29 changed files with 414 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected void onCleanup() {
} catch (Exception e) {
log.error("Error in stopping ZK server", e);
}
testZKServer = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,26 @@ private void createTenant(PulsarAdmin pulsarAdmin)
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public void setup() throws Exception {

@AfterMethod(alwaysRun = true)
void shutdown() throws Exception {
bkEnsemble.stop();
if (bkEnsemble != null) {
bkEnsemble.stop();
bkEnsemble = null;
}
log.info("---- bk stopped ----");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,20 @@ void shutdown() throws Exception {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,33 @@ void setup() throws Exception {
@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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,14 @@ private BrokerRegistryImpl createBrokerRegistryImpl(PulsarService pulsar) {

@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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ protected void setup() throws Exception {
@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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,14 @@ public void testLoadBalancerNamespaceMaximumBundles() throws Exception {
@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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,36 @@ void setup() throws Exception {
@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ public void setup() throws Exception {

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,18 @@ protected void setup() throws Exception {
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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ protected void setup() throws Exception {
protected void cleanup() throws Exception {
if (pulsarService != null) {
pulsarService.close();
pulsarService = null;
}
if (bkEnsemble != null) {
bkEnsemble.stop();
bkEnsemble = null;
}
bkEnsemble.stop();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

@Slf4j
public abstract class CanReconnectZKClientPulsarServiceBaseTest extends TestRetrySupport {

protected final String defaultTenant = "public";
protected final String defaultNamespace = defaultTenant + "/default";
protected int numberOfBookies = 3;
Expand All @@ -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);
Expand Down Expand Up @@ -198,18 +198,30 @@ protected void cleanup() throws Exception {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,18 @@ void setup() {
@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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,27 +193,51 @@ protected void cleanup() throws Exception {
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);
}
}
Loading

0 comments on commit 72833fe

Please sign in to comment.