Skip to content

Commit

Permalink
[fix][test] Fix LocalBookkeeperEnsemble resource leak in tests (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
lhotari authored Oct 23, 2023
1 parent e16671f commit a0f8b0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.apache.bookkeeper.clients.exceptions.NamespaceExistsException;
import org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException;
import org.apache.bookkeeper.common.allocator.PoolingPolicy;
import org.apache.bookkeeper.common.component.ComponentStarter;
import org.apache.bookkeeper.common.component.LifecycleComponent;
import org.apache.bookkeeper.common.component.LifecycleComponentStack;
import org.apache.bookkeeper.common.concurrent.FutureUtils;
Expand Down Expand Up @@ -132,7 +131,7 @@ public LocalBookkeeperEnsemble(int numberOfBookies,
boolean clearOldData,
String advertisedAddress) {
this(numberOfBookies, zkPort, streamStoragePort, zkDataDirName, bkDataDirName, clearOldData, advertisedAddress,
new BasePortManager(bkBasePort));
bkBasePort != 0 ? new BasePortManager(bkBasePort) : () -> 0);
}

public LocalBookkeeperEnsemble(int numberOfBookies,
Expand Down Expand Up @@ -311,6 +310,7 @@ private void runBookies(ServerConfiguration baseConf) throws Exception {
bsConfs[i] = new ServerConfiguration(baseConf);
// override settings
bsConfs[i].setBookiePort(bookiePort);
bsConfs[i].setBookieId("bk" + i + "test");
String zkServers = "127.0.0.1:" + zkPort;
String metadataServiceUriStr = "zk://" + zkServers + "/ledgers";

Expand Down Expand Up @@ -455,8 +455,10 @@ public void startBK(int i) throws Exception {
try {
bookieComponents[i] = org.apache.bookkeeper.server.Main
.buildBookieServer(new BookieConfiguration(bsConfs[i]));
ComponentStarter.startComponent(bookieComponents[i]);
bookieComponents[i].start();
} catch (BookieException.InvalidCookieException ice) {
LOG.warn("Invalid cookie found for bookie {}", i, ice);

// InvalidCookieException can happen if the machine IP has changed
// Since we are running here a local bookie that is always accessed
// from localhost, we can ignore the error
Expand All @@ -473,7 +475,7 @@ public void startBK(int i) throws Exception {

bookieComponents[i] = org.apache.bookkeeper.server.Main
.buildBookieServer(new BookieConfiguration(bsConfs[i]));
ComponentStarter.startComponent(bookieComponents[i]);
bookieComponents[i].start();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

import java.util.Collections;
import java.util.List;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Expand All @@ -39,22 +35,6 @@ void setup() throws Exception {
void teardown() throws Exception {
}

@Test
public void testAdvertisedAddress() throws Exception {
final int numBk = 1;

LocalBookkeeperEnsemble ensemble = new LocalBookkeeperEnsemble(
numBk, 0, 0, null, null, true, "127.0.0.2");
ensemble.startStandalone();

List<String> bookies = ensemble.getZkClient().getChildren("/ledgers/available", false);
Collections.sort(bookies);
assertEquals(bookies.size(), 2);
assertTrue(bookies.get(0).startsWith("127.0.0.2:"));

ensemble.stop();
}

@Test
public void testStartStop() throws Exception {

Expand Down

0 comments on commit a0f8b0d

Please sign in to comment.