Skip to content

Commit

Permalink
Making test sever ports constructor parameters, they should not (and …
Browse files Browse the repository at this point in the history
…cannot) be changed on the fly.
  • Loading branch information
barancev committed Apr 8, 2017
1 parent 25feb2c commit 32ff140
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class SeleniumAppServer extends JettyAppServer {

private static final String RC_CONTEXT_PATH = "/selenium-server";

public SeleniumAppServer() {
super();
public SeleniumAppServer(String hostname, int httpPort, int httpsPort) {
super(hostname, httpPort, httpsPort);
ServletContextHandler context = addResourceHandler(RC_CONTEXT_PATH, findRootOfRcTestPages());
addServlet(context, "/cachedContentTest", CachedContentServlet.class);
}
Expand All @@ -45,15 +45,11 @@ protected String getMainContextPath(String relativeUrl) {
}

public static void main(String[] args) {
JettyAppServer server = new SeleniumAppServer();

server.listenOn(getHttpPortFromEnv());
System.out.println(String.format("Starting server on port %d", getHttpPortFromEnv()));

server.listenSecurelyOn(getHttpsPortFromEnv());
System.out.println(String.format("HTTPS on %d", getHttpsPortFromEnv()));

server.start();
int httpPort = getHttpPortFromEnv();
int httpsPort = getHttpsPortFromEnv();
System.out.println(String.format("Starting server on HTTPS port %d and HTTPS port %d",
httpPort, httpsPort));
new SeleniumAppServer(detectHostname(), httpPort, httpsPort).start();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,6 @@ public void start() {
public void stop() {
command.destroy();
}

@Override
public void listenOn(int port) {
throw new UnsupportedOperationException("listenOn");
}

@Override
public void listenSecurelyOn(int port) {
throw new UnsupportedOperationException("listenSecurelyOn");
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,4 @@ public interface AppServer {
void start();

void stop();

void listenOn(int port);

void listenSecurelyOn(int port);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.google.common.collect.ImmutableList;

import org.openqa.selenium.io.TemporaryFilesystem;
import org.openqa.selenium.net.NetworkUtils;
import org.openqa.selenium.testing.InProject;
import org.seleniumhq.jetty9.http.HttpVersion;
Expand All @@ -42,6 +43,7 @@
import org.seleniumhq.jetty9.servlet.ServletHolder;
import org.seleniumhq.jetty9.util.ssl.SslContextFactory;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.EnumSet;
Expand Down Expand Up @@ -74,16 +76,19 @@ public class JettyAppServer implements AppServer {
private final String hostName;

public JettyAppServer() {
this(detectHostname());
this(detectHostname(), getHttpPort(), getHttpsPort());
}

public static String detectHostname() {
String hostnameFromProperty = System.getenv(HOSTNAME_FOR_TEST_ENV_NAME);
return hostnameFromProperty == null ? "localhost" : hostnameFromProperty;
}

public JettyAppServer(String hostName) {
public JettyAppServer(String hostName, int httpPort, int httpsPort) {
this.hostName = hostName;
this.port = httpPort;
this.securePort = httpsPort;

// Be quiet. Unless we want things to be chatty
if (!Boolean.getBoolean("webdriver.debug")) {
new NullLogger().disableLogging();
Expand Down Expand Up @@ -116,17 +121,14 @@ public JettyAppServer(String hostName) {
addServlet(defaultContext, "/quitquitquit", KillSwitchServlet.class);
addServlet(defaultContext, "/basicAuth", BasicAuth.class);
addServlet(defaultContext, "/generated/*", GeneratedJsTestServlet.class);

listenOn(getHttpPort());
listenSecurelyOn(getHttpsPort());
}

private int getHttpPort() {
private static int getHttpPort() {
String port = System.getenv(FIXED_HTTP_PORT_ENV_NAME);
return port == null ? findFreePort() : Integer.parseInt(port);
}

private int getHttpsPort() {
private static int getHttpsPort() {
String port = System.getenv(FIXED_HTTPS_PORT_ENV_NAME);
return port == null ? findFreePort() : Integer.parseInt(port);
}
Expand Down Expand Up @@ -218,16 +220,6 @@ protected Path getKeyStore() {
return InProject.locate("java/client/test/org/openqa/selenium/environment/webserver/keystore");
}

@Override
public void listenOn(int port) {
this.port = port;
}

@Override
public void listenSecurelyOn(int port) {
this.securePort = port;
}

@Override
public void stop() {
try {
Expand Down Expand Up @@ -291,15 +283,11 @@ protected static int getHttpsPortFromEnv() {
}

public static void main(String[] args) {
JettyAppServer server = new JettyAppServer(detectHostname());

server.listenOn(getHttpPortFromEnv());
System.out.println(String.format("Starting server on port %d", getHttpPortFromEnv()));

server.listenSecurelyOn(getHttpsPortFromEnv());
System.out.println(String.format("HTTPS on %d", getHttpsPortFromEnv()));

server.start();
int httpPort = getHttpPortFromEnv();
int httpsPort = getHttpsPortFromEnv();
System.out.println(String.format("Starting server on HTTPS port %d and HTTPS port %d",
httpPort, httpsPort));
new JettyAppServer(detectHostname(), httpPort, httpsPort).start();
}

}

0 comments on commit 32ff140

Please sign in to comment.