Skip to content

Commit

Permalink
hub, remove a duplicate call to initServer (one must call start to st…
Browse files Browse the repository at this point in the history
…art it, which calls initServer). Getting rid of lots of magic strings related to tests creating a new session / grid console page. Deleting old servlets from the hub.
  • Loading branch information
lukeis committed Mar 16, 2016
1 parent 057dc48 commit d52b42c
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 34 deletions.
27 changes: 17 additions & 10 deletions java/server/src/org/openqa/grid/web/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ public Hub(GridHubConfiguration gridHubConfiguration) {
}
}
}

initServer();

}

private void initServer() {
Expand Down Expand Up @@ -150,23 +147,22 @@ private void initServer() {
root.addServlet(DisplayHelpServlet.class.getName(), "/*");

root.addServlet(ConsoleServlet.class.getName(), "/grid/console/*");
root.addServlet(ConsoleServlet.class.getName(), "/grid/beta/console/*");

root.addServlet(RegistrationServlet.class.getName(), "/grid/register/*");
// TODO remove at some point. Here for backward compatibility of
// tests etc.
root.addServlet(DriverServlet.class.getName(), "/grid/driver/*");

root.addServlet(DriverServlet.class.getName(), "/wd/hub/*");
root.addServlet(DriverServlet.class.getName(), "/selenium-server/driver/*");

root.addServlet(ResourceServlet.class.getName(), "/grid/resources/*");

root.addServlet(ProxyStatusServlet.class.getName(), "/grid/api/proxy/*");

root.addServlet(HubStatusServlet.class.getName(), "/grid/api/hub/*");

root.addServlet(TestSessionStatusServlet.class.getName(), "/grid/api/testsession/*");

root.addServlet(LifecycleServlet.class.getName(), "/lifecycle-manager/*");

// Selenium Grid 1.0 compatibility routes for older nodes trying to
// work with the newer hub.
root.addServlet(RegistrationServlet.class.getName(), "/registration-manager/register/*");
root.addServlet(Grid1HeartbeatServlet.class.getName(), "/heartbeat");

// Load any additional servlets provided by the user.
Expand Down Expand Up @@ -208,4 +204,15 @@ public URL getRegistrationURL() {
return getUrl("/grid/register/");
}

/**
* @return URL one would use to request a new WebDriver session on this hub.
*/
public URL getWebDriverHubRequestURL() {
return getUrl("/wd/hub");
}

public URL getConsoleURL() {
return getUrl("/grid/console");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.grid.web.servlet.handler;

import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.internal.ExternalSessionKey;
import org.openqa.grid.internal.Registry;
import org.openqa.grid.internal.TestSession;
Expand All @@ -27,7 +26,6 @@

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public abstract class SeleniumBasedRequest extends HttpServletRequestWrapper {

private static List<SeleniumBasedRequestFactory> requestFactories =
new ImmutableList.Builder<SeleniumBasedRequestFactory>()
.add(new LegacySeleniumRequestFactory())
.add(new WebDriverRequestFactory())
.add(new LegacySeleniumRequestFactory())
.build();

public static SeleniumBasedRequest createFromRequest(HttpServletRequest request, Registry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class WebDriverRequestFactory implements SeleniumBasedRequestFactory {
public SeleniumBasedRequest createFromRequest(HttpServletRequest request, Registry registry) {
String path = request.getServletPath();
if (! ("/grid/driver".equals(path) || "/wd/hub".equals(path))) {
if (!"/wd/hub".equals(path)) {
return null;
}
return new WebDriverRequest(request, registry);
Expand Down
2 changes: 1 addition & 1 deletion java/server/test/org/openqa/grid/e2e/misc/Issue1586.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void prepare() throws Exception {
public void test() throws MalformedURLException {
WebDriver driver = null;
try {
driver = new RemoteWebDriver(new URL(hub.getUrl() + "/grid/driver"), GridTestHelper.getDefaultBrowserCapability());
driver = new RemoteWebDriver(hub.getWebDriverHubRequestURL(), GridTestHelper.getDefaultBrowserCapability());
for (int i = 0; i < 20; i++) {
driver.get("https://github.com/SeleniumHQ/selenium");
WebElement keywordInput = driver.findElement(By.name("q"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public static void prepare() throws Exception {
registry = hub.getRegistry();

hubURL = hub.getUrl();
driverURL = new URL(hubURL + "/grid/driver");
consoleURL = new URL(hubURL + "/grid/console");
driverURL = hub.getWebDriverHubRequestURL();
consoleURL = hub.getConsoleURL();

// assigning a priority rule where requests with the flag "important" go first.
registry.getConfiguration().prioritizer = new Prioritizer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public static void setup() throws Exception {

@Test
public void testWebDriverTimesOut() throws InterruptedException, MalformedURLException {
String url = "http://" + hub.getConfiguration().host + ":" + hub.getConfiguration().port + "/grid/admin/SlowServlet";
String url = hub.getUrl("/grid/admin/SlowServlet").toExternalForm();
DesiredCapabilities caps = GridTestHelper.getDefaultBrowserCapability();
WebDriver driver = new RemoteWebDriver(new URL(hub.getUrl() + "/wd/hub"), caps);
WebDriver driver = new RemoteWebDriver(hub.getWebDriverHubRequestURL(), caps);

try {
driver.get(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.openqa.selenium.support.ui.Wait;

import java.net.MalformedURLException;
import java.net.URL;


public class CrashWhenStartingBrowserTest {
Expand Down Expand Up @@ -92,7 +91,7 @@ public void serverCrashesStartingFirefox() throws MalformedURLException {
WebDriverException exception = null;
try {
DesiredCapabilities ff = DesiredCapabilities.firefox();
new RemoteWebDriver(new URL(hub.getUrl() + "/wd/hub"), ff);
new RemoteWebDriver(hub.getWebDriverHubRequestURL(), ff);
} catch (WebDriverException expected) {
exception = expected;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ public void nodeServerCanStopAndRestart() throws Exception {
assertEquals(p.getTimeOut(), originalTimeout * 1000);
}

URL hubURL = new URL("http://" + hub.getConfiguration().host + ":" + hub.getConfiguration().port);

DesiredCapabilities caps = GridTestHelper.getDefaultBrowserCapability();
new RemoteWebDriver(new URL(hubURL + "/grid/driver"), caps);
new RemoteWebDriver(hub.getWebDriverHubRequestURL(), caps);

// kill the node
node.stopRemoteServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public static void setup() throws Exception {

@Test
public void webDriverTimesOut() throws InterruptedException, MalformedURLException {
String url = "http://" + hub.getConfiguration().host + ":" + hub.getConfiguration().port + "/grid/console";
String url = hub.getConsoleURL().toString();
DesiredCapabilities caps = GridTestHelper.getDefaultBrowserCapability();
WebDriver driver = new RemoteWebDriver(new URL(hub.getUrl() + "/wd/hub"), caps);
WebDriver driver = new RemoteWebDriver(hub.getWebDriverHubRequestURL(), caps);
driver.get(url);
assertEquals(driver.getTitle(), "Grid Console");
wait.until(new Function<Object, Integer>() {
Expand Down
4 changes: 2 additions & 2 deletions java/server/test/org/openqa/grid/e2e/node/SmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public void firefoxOnWebDriver() throws MalformedURLException {
WebDriver driver = null;
try {
DesiredCapabilities caps = GridTestHelper.getDefaultBrowserCapability();
driver = new RemoteWebDriver(new URL(hub.getUrl() + "/wd/hub"), caps);
driver.get(hub.getUrl() + "/grid/console");
driver = new RemoteWebDriver(hub.getWebDriverHubRequestURL(), caps);
driver.get(hub.getConsoleURL().toString());
assertEquals(driver.getTitle(), "Grid Console");
} finally {
if (driver != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.openqa.grid.common.GridRole;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.common.SeleniumProtocol;
import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;
import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.net.PortProber;
Expand Down Expand Up @@ -87,10 +87,6 @@ public static Hub getHub(GridHubConfiguration config) throws Exception {

public static RemoteWebDriver getRemoteWebDriver(DesiredCapabilities caps, Hub hub)
throws MalformedURLException {
return new RemoteWebDriver(getGridDriver(hub), caps);
}

public static URL getGridDriver(Hub hub) throws MalformedURLException {
return new URL(hub.getUrl() + "/grid/driver");
return new RemoteWebDriver(hub.getWebDriverHubRequestURL(), caps);
}
}

0 comments on commit d52b42c

Please sign in to comment.