Skip to content

Commit

Permalink
SimonStewart: Removing the selenium rc reference from the webdriver s…
Browse files Browse the repository at this point in the history
…ervlet. The grid build fails in the same way as on a pristine client, so I assume that this change is a no-op.

r16527
  • Loading branch information
shs96c committed Apr 10, 2012
1 parent 7f5a7ae commit d03a509
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void updateLastAccessTime() {
lastAccess = System.currentTimeMillis();
}

public boolean isTimedOut(int timeout) {
public boolean isTimedOut(long timeout) {
return timeout > 0 && (lastAccess + timeout) < System.currentTimeMillis();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.util.EnumSet;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import javax.servlet.ServletException;
Expand Down Expand Up @@ -144,7 +145,6 @@
import org.openqa.selenium.remote.server.xdrpc.CrossDomainRpcLoader;
import org.openqa.selenium.remote.server.xdrpc.CrossDomainRpcRenderer;
import org.openqa.selenium.remote.server.xdrpc.HttpServletRequestProxy;
import org.openqa.selenium.server.RemoteControlConfiguration;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Supplier;
Expand Down Expand Up @@ -183,33 +183,24 @@ public void init() throws ServletException {
DriverSessions driverSessions = sessionsSupplier.get();
setupMappings(driverSessions, logger);

RemoteControlConfiguration rcc =
(RemoteControlConfiguration) getServletContext().getAttribute(RemoteControlConfiguration.KEY);
int configSessionTimeoutMs = rcc == null ? -1 : (int)rcc.getTimeoutInMs();
int configBrowserTimeoutMs = rcc == null ? -1 : rcc.getBrowserTimeoutInMs();

int sessionTimeOutInMs =
getValueToUseInMs("webdriver.server.session.timeout", configSessionTimeoutMs, 1800);
int browserTimeoutInMs = getValueToUseInMs(configBrowserTimeoutMs, 0);
long sessionTimeOutInMs = getValueToUseInMs("webdriver.server.session.timeout", 1800);
long browserTimeoutInMs = getValueToUseInMs("webdriver.server.browser.timeout", 0);

if (sessionTimeOutInMs > 0 || browserTimeoutInMs > 0) {
sessionCleaner = new SessionCleaner(driverSessions, logger, sessionTimeOutInMs, browserTimeoutInMs);
sessionCleaner.start();
}
}

private int getValueToUseInMs(String sysPropName, int rccTimeOutMs, int defaultValueIfAllElse) {
final String property = System.getProperty(sysPropName);
if (property == null){
return getValueToUseInMs(rccTimeOutMs, defaultValueIfAllElse);
} else {
return Integer.parseInt(property) * 1000;
private long getValueToUseInMs(String propertyName, long defaultValue) {
long time = defaultValue;
final String property = getInitParameter(propertyName);
if (property != null) {
time = Long.parseLong(property);
}
}

private int getValueToUseInMs(int rccTimeOutMs, int defaultValueIfAllElse) {
return (rccTimeOutMs > 0) ? rccTimeOutMs : defaultValueIfAllElse * 1000;
}
return TimeUnit.SECONDS.toMillis(time);
}

@Override
public void destroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface Session {

String getAndClearScreenshot();

boolean isTimedOut(int timeout);
boolean isTimedOut(long timeout);

/**
* Indicates that the session is in use at this moment (being forwarded to browser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
class SessionCleaner extends Thread { // Thread safety reviewed

private final DriverSessions driverSessions;
private final int clientGoneTimeout;
private final int insideBrowserTimeout;
private final int sleepInterval;
private final long clientGoneTimeout;
private final long insideBrowserTimeout;
private final long sleepInterval;
private final Logger log;
private volatile boolean running = true;

SessionCleaner(DriverSessions driverSessions, Logger log, int clientGoneTimeout, int insideBrowserTimeout) {
SessionCleaner(DriverSessions driverSessions, Logger log, long clientGoneTimeout, long insideBrowserTimeout) {
super("DriverServlet Session Cleaner");
this.log = log;
this.clientGoneTimeout = clientGoneTimeout;
Expand All @@ -48,7 +48,7 @@ class SessionCleaner extends Thread { // Thread safety reviewed
log.warning("The specified browser timeout is TOO LOW for safe operations and may have"+
"other side-effects\n. Please specify a slightly higher browserTimeout.");
}
int lowestNonZero = Math.min((insideBrowserTimeout > 0) ? insideBrowserTimeout : clientGoneTimeout,
long lowestNonZero = Math.min((insideBrowserTimeout > 0) ? insideBrowserTimeout : clientGoneTimeout,
clientGoneTimeout > 0 ? clientGoneTimeout : insideBrowserTimeout);
this.sleepInterval = lowestNonZero / 10;
}
Expand Down
17 changes: 14 additions & 3 deletions java/server/src/org/openqa/selenium/server/SeleniumServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,22 @@ private HttpContext createDriverContextWithSeleniumDriverResourceHandler(
return driverContext;
}

private HttpContext createWebDriverRemoteContext(DriverSessions webdrDriverSessions) {
private HttpContext createWebDriverRemoteContext(DriverSessions webDriverSessions) {
HttpContext webdriverContext = new HttpContext();

webdriverContext.setAttribute(RemoteControlConfiguration.KEY, configuration);
webdriverContext.setAttribute(DriverServlet.SESSIONS_KEY, webdrDriverSessions);
long sessionTimeout = configuration.getTimeoutInSeconds();
if (sessionTimeout == 0) {
sessionTimeout = -1;
}
long browserTimeout = configuration.getBrowserTimeoutInMs();
if (browserTimeout == 0) {
browserTimeout = -1;
} else {
browserTimeout /= 1000;
}
webdriverContext.setInitParameter("webdriver.server.session.timeout", String.valueOf(sessionTimeout));
webdriverContext.setInitParameter("webdriver.server.browser.timeout", String.valueOf(browserTimeout));
webdriverContext.setAttribute(DriverServlet.SESSIONS_KEY, webDriverSessions);
webdriverContext.setContextPath("/wd");
ServletHandler handler = new ServletHandler();
handler.addServlet("WebDriver remote server", "/hub/*", DriverServlet.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public String getAndClearScreenshot() {
return null;
}

public boolean isTimedOut(int timeout) {
public boolean isTimedOut(long timeout) {
return timeout > 0 && (lastAccess + timeout) < System.currentTimeMillis();
}

Expand Down

0 comments on commit d03a509

Please sign in to comment.