forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] [client] Fix resource leak in Pulsar Client since HttpLookupSer…
…vice doesn't get closed (apache#22858) (cherry picked from commit bc3dc77) (cherry picked from commit e9264a9)
- Loading branch information
1 parent
4fc7561
commit 1dc870c
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...broker/src/test/java/org/apache/pulsar/broker/admin/PulsarClientImplMultiBrokersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.broker.admin; | ||
|
||
import static org.testng.Assert.fail; | ||
import static org.testng.AssertJUnit.assertEquals; | ||
import static org.testng.AssertJUnit.assertTrue; | ||
import java.util.Map; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.pulsar.broker.MultiBrokerBaseTest; | ||
import org.apache.pulsar.broker.PulsarService; | ||
import org.apache.pulsar.client.impl.LookupService; | ||
import org.apache.pulsar.client.impl.PulsarClientImpl; | ||
import org.awaitility.reflect.WhiteboxImpl; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Test multi-broker admin api. | ||
*/ | ||
@Slf4j | ||
@Test(groups = "broker-admin") | ||
public class PulsarClientImplMultiBrokersTest extends MultiBrokerBaseTest { | ||
@Override | ||
protected int numberOfAdditionalBrokers() { | ||
return 3; | ||
} | ||
|
||
@Override | ||
protected void doInitConf() throws Exception { | ||
super.doInitConf(); | ||
this.conf.setManagedLedgerMaxEntriesPerLedger(10); | ||
} | ||
|
||
@Override | ||
protected void onCleanup() { | ||
super.onCleanup(); | ||
} | ||
|
||
@Test(timeOut = 30 * 1000) | ||
public void testReleaseUrlLookupServices() throws Exception { | ||
PulsarClientImpl pulsarClient = (PulsarClientImpl) additionalBrokerClients.get(0); | ||
Map<String, LookupService> urlLookupMap = WhiteboxImpl.getInternalState(pulsarClient, "urlLookupMap"); | ||
assertEquals(urlLookupMap.size(), 0); | ||
for (PulsarService pulsar : additionalBrokers) { | ||
pulsarClient.getLookup(pulsar.getBrokerServiceUrl()); | ||
pulsarClient.getLookup(pulsar.getWebServiceAddress()); | ||
} | ||
assertEquals(urlLookupMap.size(), additionalBrokers.size() * 2); | ||
// Verify: lookup services will be release. | ||
pulsarClient.close(); | ||
assertEquals(urlLookupMap.size(), 0); | ||
try { | ||
for (PulsarService pulsar : additionalBrokers) { | ||
pulsarClient.getLookup(pulsar.getBrokerServiceUrl()); | ||
pulsarClient.getLookup(pulsar.getWebServiceAddress()); | ||
} | ||
fail("Expected a error when calling pulsarClient.getLookup if getLookup was closed"); | ||
} catch (IllegalStateException illegalArgumentException) { | ||
assertTrue(illegalArgumentException.getMessage().contains("has been closed")); | ||
} | ||
assertEquals(urlLookupMap.size(), 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters