Skip to content

Commit 4666974

Browse files
committed
ZOOKEEPER-4962: Export bound client port for ZooKeeperServerEmbedded
Since, `ZooKeeperServerEmbedded` could bind to port 0 and get unused port from system. It would be good to export the bound client port in addition to `getConnectionString`.
1 parent 770804b commit 4666974

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperServerMain.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,13 @@ ServerCnxnFactory getSecureCnxnFactory() {
242242
return secureCnxnFactory;
243243
}
244244

245-
// VisibleForTesting
246245
public int getClientPort() {
247246
if (cnxnFactory != null) {
248247
return cnxnFactory.getLocalPort();
249248
}
250249
return 0;
251250
}
252251

253-
// VisibleForTesting
254252
public int getSecureClientPort() {
255253
if (secureCnxnFactory != null) {
256254
return secureCnxnFactory.getLocalPort();

zookeeper-server/src/main/java/org/apache/zookeeper/server/embedded/ZooKeeperServerEmbedded.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ static ZookKeeperServerEmbeddedBuilder builder() {
116116
*/
117117
void start(long startupTimeout) throws Exception;
118118

119+
/**
120+
* Get client port for no secure connection.
121+
*/
122+
int getClientPort();
123+
124+
/**
125+
* Get client port for secure connection.
126+
*/
127+
int getSecureClientPort();
128+
119129
/**
120130
* Get a connection string useful for the client.
121131
* @return the connection string

zookeeper-server/src/main/java/org/apache/zookeeper/server/embedded/ZooKeeperServerEmbeddedImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ public void run() {
190190
}
191191
}
192192

193+
@Override
194+
public int getClientPort() {
195+
return boundClientPort;
196+
}
197+
198+
@Override
199+
public int getSecureClientPort() {
200+
return boundSecureClientPort;
201+
}
202+
193203
@Override
194204
public String getConnectionString() {
195205
return prettifyConnectionString(config.getClientPortAddress(), boundClientPort);

0 commit comments

Comments
 (0)