Skip to content

Commit

Permalink
Decoupling node registration module (SelfRegisteringRemote) from conc…
Browse files Browse the repository at this point in the history
…rete implementation of the server to be run on the node.
  • Loading branch information
barancev committed Oct 14, 2015
1 parent c7f393c commit 0ea8273
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion java/server/src/org/openqa/grid/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ java_library(name = 'grid',
'//java/client/src/org/openqa/selenium/remote:remote',
'//java/server/src/org/openqa/grid/common:common',
'//java/server/src/org/openqa/selenium/remote/server/log:log',
'//java/server/src/org/openqa/selenium/server:server',
"//java/server/src/org/openqa/selenium/server:shared",
'//third_party/java/gson:gson',
'//third_party/java/guava-libraries:guava-libraries',
'//third_party/java/httpcomponents:httpclient',
Expand Down
2 changes: 1 addition & 1 deletion java/server/src/org/openqa/grid/build.desc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ java_library(name = "grid",
deps = [
"//java/client/src/org/openqa/selenium:webdriver-api",
"//java/server/src/org/openqa/grid/common",
"//java/server/src/org/openqa/selenium/server:base",
"//java/server/src/org/openqa/selenium/remote/server",
"//third_party/java/httpcomponents:httpclient",
"//third_party/java/guava-libraries",
"//third_party/java/jcip_annotations",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.internal.HttpClientFactory;
import org.openqa.selenium.remote.server.log.LoggingManager;
import org.openqa.selenium.server.SeleniumServer;
import org.openqa.selenium.server.shared.IServer;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -92,10 +92,16 @@ public URL getRemoteURL() {
}
}

private SeleniumServer server;
private IServer server;

public void setRemoteServer(IServer server) {
this.server = server;
}

public void startRemoteServer() throws Exception {
server = new SeleniumServer(nodeConfig.getConfiguration());
if (server == null) {
throw new GridConfigurationException("no server set to register to the hub");
}
server.boot();
}

Expand Down
1 change: 1 addition & 0 deletions java/server/src/org/openqa/grid/selenium/GridLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static void main(String[] args) throws Exception {
try {
RegistrationRequest c = RegistrationRequest.build(args);
SelfRegisteringRemote remote = new SelfRegisteringRemote(c);
remote.setRemoteServer(new SeleniumServer(c.getConfiguration()));
remote.startRemoteServer();
log.info("Selenium Grid node is up and ready to register to the hub");
remote.startRegistrationProcess();
Expand Down
1 change: 1 addition & 0 deletions java/server/src/org/openqa/selenium/remote/server/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ java_library(name = 'server',
'//third_party/java/servlet:servlet-api',
],
visibility = [
'//java/server/src/org/openqa/grid:grid',
'//java/server/src/com/thoughtworks/selenium/webdriven:rc-emulation-servlet',
'//java/server/src/org/openqa/selenium/server:server',
'//java/server/test/com/thoughtworks/selenium/webdriven:webdriven',
Expand Down
1 change: 1 addition & 0 deletions java/server/src/org/openqa/selenium/server/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ java_library(name = 'server',
java_library(name = 'shared',
srcs = glob(['shared/*.java']),
visibility = [
'//java/server/src/org/openqa/grid:grid',
'//java/server/src/org/openqa/grid/common:common',
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.openqa.selenium.server.htmlrunner.HTMLResultsListener;
import org.openqa.selenium.server.htmlrunner.SeleniumHTMLRunnerResultsHandler;
import org.openqa.selenium.server.htmlrunner.SingleTestSuiteResourceHandler;
import org.openqa.selenium.server.shared.IServer;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -185,7 +186,7 @@
*
* @author plightbo
*/
public class SeleniumServer implements SslCertificateGenerator {
public class SeleniumServer implements SslCertificateGenerator, IServer {

private Log LOGGER;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.openqa.selenium.server.shared;

public interface IServer {
void boot() throws Exception;
void stop();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.server.SeleniumServer;


public class ConfigInheritanceTest {
Expand All @@ -52,6 +53,7 @@ public static void prepare() throws Exception {
remote.getConfiguration().put("A2", "proxyA2");
remote.getConfiguration().put("B2", 50);

remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
remote.startRemoteServer();
remote.sendRegistrationRequest();
RegistryTestHelper.waitForNode(hub.getRegistry(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.remote.internal.HttpClientFactory;
import org.openqa.selenium.server.SeleniumServer;

import java.io.BufferedReader;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -80,6 +81,8 @@ public void testIsRegistered() throws Exception {
SelfRegisteringRemote selenium1 =
GridTestHelper.getRemoteWithoutCapabilities(hub.getUrl(), GridRole.NODE);
selenium1.addBrowser(GridTestHelper.getDefaultBrowserCapability(), 1);

selenium1.setRemoteServer(new SeleniumServer(selenium1.getConfiguration()));
selenium1.startRemoteServer();
selenium1.sendRegistrationRequest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.server.SeleniumServer;

public class GridSerializeExceptionTest {

Expand All @@ -39,6 +40,7 @@ public static void prepare() throws Exception {
SelfRegisteringRemote remote =
GridTestHelper.getRemoteWithoutCapabilities(hub, GridRole.NODE);

remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
remote.startRemoteServer();
remote.sendRegistrationRequest();
RegistryTestHelper.waitForNode(hub.getRegistry(), 1);
Expand Down
2 changes: 2 additions & 0 deletions java/server/test/org/openqa/grid/e2e/misc/HubRestart.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.server.SeleniumServer;

/**
* A node will try to contact the hub it's registered to every RegistrationRequest.REGISTER_CYCLE
Expand All @@ -57,6 +58,7 @@ public static void prepare() throws Exception {

remote.getConfiguration().put(RegistrationRequest.REGISTER_CYCLE, 250);

remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
remote.startRemoteServer();

}
Expand Down
2 changes: 2 additions & 0 deletions java/server/test/org/openqa/grid/e2e/misc/HubRestartNeg.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.server.SeleniumServer;

/**
* by specifing a RegistrationRequest.REGISTER_CYCLE= -1 , the node to not try to register against
Expand Down Expand Up @@ -58,6 +59,7 @@ public static void prepare() throws Exception {

remote.getConfiguration().put(RegistrationRequest.REGISTER_CYCLE, -1);

remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
remote.startRemoteServer();

}
Expand Down
3 changes: 3 additions & 0 deletions java/server/test/org/openqa/grid/e2e/misc/Issue1586.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.server.SeleniumServer;

import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -46,6 +47,8 @@ public static void prepare() throws Exception {
SelfRegisteringRemote webdriver =
GridTestHelper.getRemoteWithoutCapabilities(hub.getUrl(), GridRole.NODE);
webdriver.addBrowser(GridTestHelper.getDefaultBrowserCapability(), 1);

webdriver.setRemoteServer(new SeleniumServer(webdriver.getConfiguration()));
webdriver.startRemoteServer();
webdriver.sendRegistrationRequest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.server.SeleniumServer;

import java.net.URL;
import java.util.Map;
Expand Down Expand Up @@ -98,6 +99,7 @@ public int compareTo(Map<String, Object> a, Map<String, Object> b) {
remote = GridTestHelper.getRemoteWithoutCapabilities(hubURL, GridRole.NODE);
remote.addBrowser(browser, 1);

remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
remote.startRemoteServer();
remote.setMaxConcurrent(1);
remote.setTimeout(-1, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.server.SeleniumServer;

import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -58,6 +59,8 @@ public static void setup() throws Exception {
node = GridTestHelper.getRemoteWithoutCapabilities(hub.getUrl(), GridRole.NODE);
node.addBrowser(GridTestHelper.getSelenium1FirefoxCapability(), 1);
node.addBrowser(GridTestHelper.getDefaultBrowserCapability(), 1);

node.setRemoteServer(new SeleniumServer(node.getConfiguration()));
node.startRemoteServer();
node.sendRegistrationRequest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.server.SeleniumServer;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;

Expand All @@ -50,6 +51,7 @@
public class CrashWhenStartingBrowserTest {

private static Hub hub;
private static SelfRegisteringRemote remote;
private static Registry registry;
private static Wait<Object> wait = new FluentWait<Object>("").withTimeout(30, SECONDS);

Expand All @@ -62,13 +64,13 @@ public static void prepareANodePointingToANonExistingFirefox() throws Exception
hub = GridTestHelper.getHub();
registry = hub.getRegistry();

SelfRegisteringRemote remote =
GridTestHelper.getRemoteWithoutCapabilities(hub.getUrl(), GridRole.NODE);
remote = GridTestHelper.getRemoteWithoutCapabilities(hub.getUrl(), GridRole.NODE);

DesiredCapabilities firefox = DesiredCapabilities.firefox();
firefox.setCapability(FirefoxDriver.BINARY, wrong_path);
remote.addBrowser(firefox, 1);

remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
remote.startRemoteServer();
remote.sendRegistrationRequest();
RegistryTestHelper.waitForNode(registry, 1);
Expand Down Expand Up @@ -127,6 +129,7 @@ private static String getProxyId() throws Exception {

@AfterClass
public static void stop() throws Exception {
remote.stopRemoteServer();
hub.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.server.SeleniumServer;

import java.io.IOException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -102,6 +103,7 @@ public static void prepare() throws Exception {
caps.setVersion("30");
remote.addBrowser(caps, 1);

remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
remote.startRemoteServer();
remote.sendRegistrationRequest();
RegistryTestHelper.waitForNode(registry, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.selenium.proxy.DefaultRemoteProxy;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.server.SeleniumServer;
import org.openqa.selenium.support.ui.FluentWait;

import java.util.Iterator;
Expand Down Expand Up @@ -67,6 +68,7 @@ public static void prepare() throws Exception {
// add browser
remote.addBrowser(GridTestHelper.getDefaultBrowserCapability(), 1);

remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
remote.startRemoteServer();
remote.sendRegistrationRequest();
RegistryTestHelper.waitForNode(registry, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.selenium.proxy.DefaultRemoteProxy;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.server.SeleniumServer;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;

Expand Down Expand Up @@ -61,6 +62,7 @@ public static void prepare() throws Exception {
// add browser
remote.addBrowser(GridTestHelper.getDefaultBrowserCapability(), 1);

remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
remote.startRemoteServer();
remote.sendRegistrationRequest();
RegistryTestHelper.waitForNode(registry, 1);
Expand All @@ -82,6 +84,7 @@ public void markdown() throws Exception {
}

// and back up
remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
remote.startRemoteServer();

// should be up
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.server.SeleniumServer;

import java.net.URL;

Expand Down Expand Up @@ -64,6 +65,7 @@ public static void setup() throws Exception {

node.addBrowser(GridTestHelper.getDefaultBrowserCapability(), 1);
node.setTimeout(originalTimeout, 1000);
node.setRemoteServer(new SeleniumServer(node.getConfiguration()));
node.startRemoteServer();
node.sendRegistrationRequest();
RegistryTestHelper.waitForNode(hub.getRegistry(), 1);
Expand Down Expand Up @@ -91,6 +93,7 @@ public void nodeServerCanStopAndRestart() throws Exception {
node.setTimeout(newtimeout, 1000);

// restart it
node.setRemoteServer(new SeleniumServer(node.getConfiguration()));
node.startRemoteServer();
node.sendRegistrationRequest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.server.SeleniumServer;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;

Expand All @@ -62,6 +63,7 @@ public static void setup() throws Exception {
node.addBrowser(GridTestHelper.getSelenium1FirefoxCapability(), 1);
node.addBrowser(GridTestHelper.getDefaultBrowserCapability(), 1);
node.setTimeout(5000, 2000);
node.setRemoteServer(new SeleniumServer(node.getConfiguration()));
node.startRemoteServer();
node.sendRegistrationRequest();

Expand Down
2 changes: 2 additions & 0 deletions java/server/test/org/openqa/grid/e2e/node/SmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.server.SeleniumServer;

import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -61,6 +62,7 @@ public void prepare() throws Exception {

remote.addBrowser(firefoxOnSeleniumCapability, 1);

remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
remote.startRemoteServer();

remote.getConfiguration().put(RegistrationRequest.TIME_OUT, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.openqa.grid.internal.utils;

import static com.thoughtworks.selenium.SeleneseTestBase.assertEquals;
import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.openqa.grid.common.RegistrationRequest;
Expand Down

0 comments on commit 0ea8273

Please sign in to comment.