-
Notifications
You must be signed in to change notification settings - Fork 7.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZOOKEEPER-4303: Allow configuring client port to 0 #1868
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,8 +271,8 @@ public static String getVersionFromFilename(String filename) { | |
* @throws ConfigException | ||
*/ | ||
public void parseProperties(Properties zkProp) throws IOException, ConfigException { | ||
int clientPort = 0; | ||
int secureClientPort = 0; | ||
Integer clientPort = null; | ||
Integer secureClientPort = null; | ||
int observerMasterPort = 0; | ||
String clientPortAddress = null; | ||
String secureClientPortAddress = null; | ||
|
@@ -427,7 +427,7 @@ public void parseProperties(Properties zkProp) throws IOException, ConfigExcepti | |
dataLogDir = dataDir; | ||
} | ||
|
||
if (clientPort == 0) { | ||
if (clientPort == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a behavior change but I think it make sense. Prior to this, "clientPortAddress" and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implicit logic here is that: use |
||
LOG.info("clientPort is not set"); | ||
if (clientPortAddress != null) { | ||
throw new IllegalArgumentException("clientPortAddress is set but clientPort is not set"); | ||
|
@@ -440,7 +440,7 @@ public void parseProperties(Properties zkProp) throws IOException, ConfigExcepti | |
LOG.info("clientPortAddress is {}", formatInetAddr(this.clientPortAddress)); | ||
} | ||
|
||
if (secureClientPort == 0) { | ||
if (secureClientPort == null) { | ||
LOG.info("secureClientPort is not set"); | ||
if (secureClientPortAddress != null) { | ||
throw new IllegalArgumentException("secureClientPortAddress is set but secureClientPort is not set"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,17 @@ | |
*/ | ||
package org.apache.zookeeper.server.embedded; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.endsWith; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.Assert.assertTrue; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Properties; | ||
import org.apache.zookeeper.PortAssignment; | ||
import org.apache.zookeeper.test.ClientBase; | ||
import org.junit.function.ThrowingRunnable; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -95,4 +100,31 @@ public void testStart() throws Exception { | |
|
||
} | ||
|
||
@Test | ||
public void testBindPortZero() throws Exception { | ||
final Properties configZookeeper = new Properties(); | ||
final ZooKeeperServerEmbedded.ZookKeeperServerEmbeddedBuilder builder = ZooKeeperServerEmbedded.builder() | ||
.baseDir(baseDir) | ||
.configuration(configZookeeper) | ||
.exitHandler(ExitHandler.LOG_ONLY); | ||
|
||
// Unconfigured client port will still fail | ||
try (ZooKeeperServerEmbedded zkServer = builder.build()) { | ||
zkServer.start(); | ||
assertThrows(IllegalStateException.class, new ThrowingRunnable() { | ||
@Override | ||
public void run() throws Throwable { | ||
zkServer.getConnectionString(); | ||
} | ||
}); | ||
} | ||
|
||
// Explicit port zero should work | ||
configZookeeper.put("clientPort", "0"); | ||
try (ZooKeeperServerEmbedded zkServer = builder.build()) { | ||
zkServer.start(); | ||
assertThat(zkServer.getConnectionString(), not(endsWith(":0"))); | ||
assertTrue(ClientBase.waitForServerUp(zkServer.getConnectionString(), 60000)); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind add one more case to assert explicit "127.0.0.1:0" ? As I said above, I think it is a noticeable change. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: static ?