Skip to content

Commit 32ff140

Browse files
committed
Making test sever ports constructor parameters, they should not (and cannot) be changed on the fly.
1 parent 25feb2c commit 32ff140

File tree

4 files changed

+21
-51
lines changed

4 files changed

+21
-51
lines changed

java/client/test/com/thoughtworks/selenium/testing/SeleniumAppServer.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public class SeleniumAppServer extends JettyAppServer {
2727

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

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

4747
public static void main(String[] args) {
48-
JettyAppServer server = new SeleniumAppServer();
49-
50-
server.listenOn(getHttpPortFromEnv());
51-
System.out.println(String.format("Starting server on port %d", getHttpPortFromEnv()));
52-
53-
server.listenSecurelyOn(getHttpsPortFromEnv());
54-
System.out.println(String.format("HTTPS on %d", getHttpsPortFromEnv()));
55-
56-
server.start();
48+
int httpPort = getHttpPortFromEnv();
49+
int httpsPort = getHttpsPortFromEnv();
50+
System.out.println(String.format("Starting server on HTTPS port %d and HTTPS port %d",
51+
httpPort, httpsPort));
52+
new SeleniumAppServer(detectHostname(), httpPort, httpsPort).start();
5753
}
5854

5955
}

java/client/test/com/thoughtworks/selenium/testing/SeleniumTestEnvironment.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,6 @@ public void start() {
122122
public void stop() {
123123
command.destroy();
124124
}
125-
126-
@Override
127-
public void listenOn(int port) {
128-
throw new UnsupportedOperationException("listenOn");
129-
}
130-
131-
@Override
132-
public void listenSecurelyOn(int port) {
133-
throw new UnsupportedOperationException("listenSecurelyOn");
134-
}
135125
};
136126
}
137127

java/client/test/org/openqa/selenium/environment/webserver/AppServer.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,4 @@ public interface AppServer {
3434
void start();
3535

3636
void stop();
37-
38-
void listenOn(int port);
39-
40-
void listenSecurelyOn(int port);
4137
}

java/client/test/org/openqa/selenium/environment/webserver/JettyAppServer.java

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.google.common.collect.ImmutableList;
2424

25+
import org.openqa.selenium.io.TemporaryFilesystem;
2526
import org.openqa.selenium.net.NetworkUtils;
2627
import org.openqa.selenium.testing.InProject;
2728
import org.seleniumhq.jetty9.http.HttpVersion;
@@ -42,6 +43,7 @@
4243
import org.seleniumhq.jetty9.servlet.ServletHolder;
4344
import org.seleniumhq.jetty9.util.ssl.SslContextFactory;
4445

46+
import java.io.File;
4547
import java.nio.file.Files;
4648
import java.nio.file.Path;
4749
import java.util.EnumSet;
@@ -74,16 +76,19 @@ public class JettyAppServer implements AppServer {
7476
private final String hostName;
7577

7678
public JettyAppServer() {
77-
this(detectHostname());
79+
this(detectHostname(), getHttpPort(), getHttpsPort());
7880
}
7981

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

85-
public JettyAppServer(String hostName) {
87+
public JettyAppServer(String hostName, int httpPort, int httpsPort) {
8688
this.hostName = hostName;
89+
this.port = httpPort;
90+
this.securePort = httpsPort;
91+
8792
// Be quiet. Unless we want things to be chatty
8893
if (!Boolean.getBoolean("webdriver.debug")) {
8994
new NullLogger().disableLogging();
@@ -116,17 +121,14 @@ public JettyAppServer(String hostName) {
116121
addServlet(defaultContext, "/quitquitquit", KillSwitchServlet.class);
117122
addServlet(defaultContext, "/basicAuth", BasicAuth.class);
118123
addServlet(defaultContext, "/generated/*", GeneratedJsTestServlet.class);
119-
120-
listenOn(getHttpPort());
121-
listenSecurelyOn(getHttpsPort());
122124
}
123125

124-
private int getHttpPort() {
126+
private static int getHttpPort() {
125127
String port = System.getenv(FIXED_HTTP_PORT_ENV_NAME);
126128
return port == null ? findFreePort() : Integer.parseInt(port);
127129
}
128130

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

221-
@Override
222-
public void listenOn(int port) {
223-
this.port = port;
224-
}
225-
226-
@Override
227-
public void listenSecurelyOn(int port) {
228-
this.securePort = port;
229-
}
230-
231223
@Override
232224
public void stop() {
233225
try {
@@ -291,15 +283,11 @@ protected static int getHttpsPortFromEnv() {
291283
}
292284

293285
public static void main(String[] args) {
294-
JettyAppServer server = new JettyAppServer(detectHostname());
295-
296-
server.listenOn(getHttpPortFromEnv());
297-
System.out.println(String.format("Starting server on port %d", getHttpPortFromEnv()));
298-
299-
server.listenSecurelyOn(getHttpsPortFromEnv());
300-
System.out.println(String.format("HTTPS on %d", getHttpsPortFromEnv()));
301-
302-
server.start();
286+
int httpPort = getHttpPortFromEnv();
287+
int httpsPort = getHttpsPortFromEnv();
288+
System.out.println(String.format("Starting server on HTTPS port %d and HTTPS port %d",
289+
httpPort, httpsPort));
290+
new JettyAppServer(detectHostname(), httpPort, httpsPort).start();
303291
}
304292

305293
}

0 commit comments

Comments
 (0)