Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

package org.apache.hadoop.hdds.scm.server;

import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CLIENT_BIND_HOST_DEFAULT;

import java.net.ServerSocket;

import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
Expand Down Expand Up @@ -46,7 +52,11 @@ public class TestSCMClientProtocolServer {

@Before
public void setUp() throws Exception {
int port = new ServerSocket(0).getLocalPort();
config = new OzoneConfiguration();
config.set(OZONE_SCM_CLIENT_ADDRESS_KEY,
StringUtils.join(OZONE_SCM_CLIENT_BIND_HOST_DEFAULT, ":",
String.valueOf(port)));
eventQueue = new EventQueue();
scmClientProtocolServer = new SCMClientProtocolServer(config, null);
BlockManager blockManager = Mockito.mock(BlockManagerImpl.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@
*/
package org.apache.hadoop.hdds.scm.server;

import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_SECURITY_SERVICE_ADDRESS_KEY;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_SECURITY_SERVICE_BIND_HOST_DEFAULT;

import java.net.ServerSocket;

import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
Expand All @@ -32,10 +39,19 @@ public class TestSCMSecurityProtocolServer {

@Rule
public Timeout timeout = new Timeout(1000 * 20);
private static int scmRpcSecurePort;

@BeforeClass
public static void setupClass() throws Exception {
scmRpcSecurePort = new ServerSocket(0).getLocalPort();
}

@Before
public void setUp() throws Exception {
config = new OzoneConfiguration();
config.set(OZONE_SCM_SECURITY_SERVICE_ADDRESS_KEY,
StringUtils.join(OZONE_SCM_SECURITY_SERVICE_BIND_HOST_DEFAULT,
":", String.valueOf(scmRpcSecurePort)));
Copy link
Contributor

@bharatviswa504 bharatviswa504 Aug 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can directly specify OZONE_SCM_SECURITY_SERVICE_BIND_HOST_DEFAULT:0
Is there any reason for doing this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bharatviswa504 No specific reason. I just thought StringUtils is cleaner. I can do a simple concatenation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment is not related to the usage of StringUtils, we can directly use OZONE_SCM_SECURITY_SERVICE_BIND_HOST_DEFAULT:0, instead of getting from scmRpcSecurePort, which we get from new ServerSocket(0).getLocalPort(); In this way during server start, it will choose available free random port.

securityProtocolServer = new SCMSecurityProtocolServer(config, null);
}

Expand Down