Skip to content

Commit

Permalink
Disable Zookeeper AdminServer (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
gquintana authored Mar 1, 2022
1 parent 5eaf776 commit c23fa87
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.apache.curator.test.TestingServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;

import java.io.IOException;

Expand Down Expand Up @@ -61,15 +63,18 @@ public void start() {
try {
if (zkServer == null) {
// Define configuration
final Map<String, Object> customProperties = new HashMap<>();
customProperties.put("admin.enableServer", "false");
final InstanceSpec zkInstanceSpec = new InstanceSpec(
Utils.createTempDirectory(),
-1,
-1,
-1,
false,
-1,
-1,
1000
Utils.createTempDirectory(), //dataDirectory
-1, //port
-1, //electionPort
-1, //quorumPort
false, //deleteDataDirectoryOnClose
-1, //serverId
-1, //tickTime
1000, //maxClientCnxns
customProperties
);

// Create instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand All @@ -52,6 +55,7 @@ void testStart() throws Exception {

// Validate the zookeeper server appears to be functioning.
testZookeeperConnection(zookeeperTestServer.getConnectString());
testZookeeperAdminDisabled();

// Call start again
zookeeperTestServer.start();
Expand All @@ -61,6 +65,22 @@ void testStart() throws Exception {
}
}

private void testZookeeperAdminDisabled() throws MalformedURLException {
final URL adminUrl = new URL("http", "127.0.0.1", 8080,"/stat");
try {
final HttpURLConnection adminConnection = (HttpURLConnection) adminUrl.openConnection();
adminConnection.setRequestMethod("GET");
final String responseServer = adminConnection.getHeaderField("Server");
final int responseCode = adminConnection.getResponseCode();
if (responseServer != null) {
Assertions.assertFalse(responseServer.startsWith("Jetty"), "Jetty Server started");
}
Assertions.fail("Admin Server " + responseServer + " replied with status code " + responseCode);
} catch (IOException e) {
// Admin Server not started
}
}

/**
* Test restart() starts the service gracefully if not started.
*/
Expand Down

0 comments on commit c23fa87

Please sign in to comment.