Skip to content

Commit

Permalink
[grid] Test code cleanup, no functional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Apr 8, 2019
1 parent fad45d9 commit 85f900d
Show file tree
Hide file tree
Showing 34 changed files with 62 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ConfigInheritanceTest {
private Hub hub;

@Before
public void prepare() throws Exception {
public void prepare() {
GridHubConfiguration config = new GridHubConfiguration();
config.port = PortProber.findFreePort();
config.custom.put("A", "valueA");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
import org.openqa.grid.internal.TestSlot;
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.server.SeleniumServer;

import java.util.ArrayList;
Expand Down Expand Up @@ -98,7 +95,7 @@ public void testLoadIsDistributedEvenly() {

drivers.add(GridTestHelper.getRemoteWebDriver(hub));

Boolean foundOneFull = false;
boolean foundOneFull = false;
for (RemoteProxy p : ps) {
int freeslots = 0;
for (TestSlot ts : p.getTestSlots()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
import org.junit.Test;
import org.openqa.grid.e2e.utils.GridTestHelper;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.Platform;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonInput;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.io.BufferedReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class GridSerializeExceptionTest {
private Hub hub;

@Before
public void prepare() throws Exception {
public void prepare() {
hub = GridTestHelper.getHub();

SelfRegisteringRemote remote =
Expand Down
4 changes: 2 additions & 2 deletions java/server/test/org/openqa/grid/e2e/misc/HubRestart.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class HubRestart {
private GridHubConfiguration config = new GridHubConfiguration();

@Before
public void prepare() throws Exception {
public void prepare() {
config.host = "localhost";
config.port = PortProber.findFreePort();
config.timeout = 10;
Expand Down Expand Up @@ -99,7 +99,7 @@ public void nodeRegisterAgain() throws Exception {
}

@After
public void stop() throws Exception {
public void stop() {
hub.stop();
remote.stopRemoteServer();
}
Expand Down
4 changes: 2 additions & 2 deletions java/server/test/org/openqa/grid/e2e/misc/HubRestartNeg.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class HubRestartNeg {
private GridHubConfiguration config = new GridHubConfiguration();

@Before
public void prepare() throws Exception {
public void prepare() {
config.host = "localhost";
config.port = PortProber.findFreePort();
hub = new Hub(config);
Expand Down Expand Up @@ -91,7 +91,7 @@ public void nodeRegisterAgain() throws Exception {
}

@After
public void stop() throws Exception {
public void stop() {
hub.stop();
remote.stopRemoteServer();
}
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 @@ -38,7 +38,7 @@ public class Issue1586 {
private Hub hub;

@Before
public void prepare() throws Exception {
public void prepare() {
hub = GridTestHelper.getHub();

// register a webdriver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class WebDriverPriorityDemo {
private DesiredCapabilities important_browser = null;

@Before
public void prepare() throws Exception {
public void prepare() {

// start a small grid that only has 1 testing slot : htmlunit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class BrowserTimeOutTest {
private SelfRegisteringRemote node;

@Before
public void setup() throws Exception {
public void setup() {
GridHubConfiguration gridHubConfiguration = new GridHubConfiguration();
gridHubConfiguration.port = PortProber.findFreePort();
gridHubConfiguration.host = "localhost";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void prepareANodePointingToANonExistingFirefox() throws Exception {
public void serverCrashesStartingFirefox() {
// should be up
DefaultRemoteProxy p;
assertTrue(registry.getAllProxies().size() == 1);
assertEquals(1, registry.getAllProxies().size());
p = (DefaultRemoteProxy) registry.getAllProxies().getProxyById(proxyId);
wait.until(isUp(p));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class DefaultProxyInjectsConfigurationUuidTest {
private DesiredCapabilities ff20_caps;

@Before
public void prepare() throws Exception {
public void prepare() {

hub = GridTestHelper.getHub();
registry = hub.getRegistry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.openqa.grid.e2e.node;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -78,23 +79,23 @@ public void proxyIsUnregistered() throws InterruptedException {
DefaultRemoteProxy p;

// should be up
assertTrue(registry.getAllProxies().size() == 1);
assertEquals(1, registry.getAllProxies().size());
p = (DefaultRemoteProxy) registry.getAllProxies().getProxyById(proxyId);
waitFor(isUp(p));

remote.stopRemoteServer();

// first mark down - proxy is not down, proxy is not unregistered.
Thread.sleep(1500);
assertTrue(registry.getAllProxies().size() == 1);
assertEquals(1, registry.getAllProxies().size());
p = (DefaultRemoteProxy) registry.getAllProxies().getProxyById(proxyId);
assertFalse(p.isDown());

// node is considered down - proxy is down, proxy is not unregistered.
// sleep interval should be bigger than (STATUS_CHECK_TIMEOUT + NODE_POLLING) * DOWN_POLLING_LIMIT
// but less than UNREGISTER_IF_STILL_DOWN_AFTER (with previous sleeps accounting).
Thread.sleep(3500);
assertTrue(registry.getAllProxies().size() == 1);
assertEquals(1, registry.getAllProxies().size());
p = (DefaultRemoteProxy) registry.getAllProxies().getProxyById(proxyId);
assertTrue(p.isDown());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class NodeGoingDownAndUpTest {
private Wait<Object> wait = new FluentWait<Object>("").withTimeout(Duration.ofSeconds(30));

@Before
public void prepare() throws Exception {
public void prepare() {
hub = GridTestHelper.getHub();
registry = hub.getRegistry();

Expand All @@ -67,7 +67,7 @@ public void prepare() throws Exception {
}

@Test
public void markdown() throws Exception {
public void markdown() {
// should be up
for (RemoteProxy proxy : registry.getAllProxies()) {
wait.until(isUp((DefaultRemoteProxy) proxy));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class NodeRecoveryTest {
private final static int NEW_TIMEOUT = 20;

@Before
public void setup() throws Exception {
public void setup() {
GridHubConfiguration config = new GridHubConfiguration();
config.host = "localhost";
config.port = PortProber.findFreePort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class NodeTimeOutTest {
private Wait<Object> wait = new FluentWait<Object>("").withTimeout(Duration.ofSeconds(8));

@Before
public void setup() throws Exception {
public void setup() {
hub = GridTestHelper.getHub();

// register a selenium 1
Expand Down
2 changes: 1 addition & 1 deletion java/server/test/org/openqa/grid/e2e/node/SlowServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SlowServlet(GridRegistry registry) {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
throws IOException {
try {
Thread.sleep(100000);
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ private RegistrationRequest getRequestOfNSlots(int n, String name) {
config.port = 4444;
config.capabilities.add(new DesiredCapabilities(ff));

RegistrationRequest request = new RegistrationRequest(config);

return request;
return new RegistrationRequest(config);
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.grid.common.SeleniumProtocol;
import org.openqa.grid.internal.mock.GridHelper;
import org.openqa.grid.internal.mock.MockedRequestHandler;
import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;
Expand Down Expand Up @@ -77,7 +76,7 @@ public void basic() {
public void requestIsremovedFromTheQeueAfterItcrashes() {
// should work
try {
SeleniumBasedRequest newSession = GridHelper.createNewSessionRequest(registry, SeleniumProtocol.WebDriver, ff);
SeleniumBasedRequest newSession = GridHelper.createNewSessionRequest(registry, ff);
MockedRequestHandler newSessionRequest =
new MockedBuggyNewSessionRequestHandler(newSession,null,registry);
newSessionRequest.process();
Expand Down
2 changes: 0 additions & 2 deletions java/server/test/org/openqa/grid/internal/PriorityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public int compareTo(Map<String, Object> a, Map<String, Object> b) {

/**
* create a hub with 1 FF
*
* @throws InterruptedException
*/
@Before
public void setup() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public int compareTo(Map<String, Object> a, Map<String, Object> b) {

/**
* create a hub with 1 FF
*
* @throws InterruptedException
*/
@Before
public void setup() throws Exception {
Expand Down
4 changes: 2 additions & 2 deletions java/server/test/org/openqa/grid/internal/RegistryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void addProxy() throws Exception {
registry.add(p2);
registry.add(p3);
registry.add(p4);
assertTrue(registry.getAllProxies().size() == 4);
assertEquals(4, registry.getAllProxies().size());
} finally {
registry.stop();
}
Expand All @@ -84,7 +84,7 @@ public void addDuppedProxy() throws Exception {
registry.add(p3);
registry.add(p4);
registry.add(p4);
assertTrue(registry.getAllProxies().size() == 4);
assertEquals(4, registry.getAllProxies().size());
} finally {
registry.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -150,7 +151,7 @@ public void testTimeoutSlow() throws InterruptedException {
newSessionRequest2.process();
TestSession session2 = newSessionRequest2.getSession();
assertNotNull(session2);
assertFalse(session2.equals(session));
assertNotEquals(session2, session);

} finally {
registry.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void testHubGetSpecifiedConfig() throws IOException {
assertTrue((Boolean) o.get("success"));
assertEquals(12345L, o.get("timeout"));
assertNull(o.get("I'm not a valid key"));
assertTrue(((Collection) o.get("servlets")).size() == 0);
assertEquals(0, ((Collection) o.get("servlets")).size());
assertNull(o.get("capabilityMatcher"));
}

Expand All @@ -268,7 +268,7 @@ public void testHubGetSpecifiedConfigWithQueryString() throws IOException {
assertTrue((Boolean) o.get("success"));
assertEquals(12345L, o.get("timeout"));
assertNull(o.get("I'm not a valid key"));
assertTrue(((Collection<?>) o.get("servlets")).size() == 0);
assertEquals(0, ((Collection<?>) o.get("servlets")).size());
assertFalse(o.containsKey("capabilityMatcher"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.grid.internal.listener;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -160,7 +161,7 @@ public void registerSomeSlow() {
// the registry yet
assertEquals(registry.getAllProxies().size(), 1);
// check onRegistration has not run yet.
assertEquals(slowRemoteUp, false);
assertFalse(slowRemoteUp);
// should return right away, as RemoteProxy is fast.
RequestHandler req =GridHelper.createNewSessionHandler(registry, app1);
req.process();
Expand All @@ -171,7 +172,7 @@ public void registerSomeSlow() {
// the registry yet
assertEquals(registry.getAllProxies().size(), 1);
// check onRegistration has not run yet.
assertEquals(false, slowRemoteUp);
assertFalse(slowRemoteUp);

// will block until MySlowRemoteProxy is fully registered.
RequestHandler req2 = GridHelper.createNewSessionHandler(registry, app1);
Expand Down
15 changes: 6 additions & 9 deletions java/server/test/org/openqa/grid/internal/mock/GridHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import static org.mockito.Mockito.mock;

import org.openqa.grid.common.SeleniumProtocol;
import org.openqa.grid.internal.ExternalSessionKey;
import org.openqa.grid.internal.GridRegistry;
import org.openqa.grid.internal.TestSession;
Expand All @@ -41,22 +40,20 @@ public class GridHelper {
public static MockedRequestHandler createNewSessionHandler(GridRegistry registry,
Map<String, Object> desiredCapability) {
SeleniumBasedRequest request =
createNewSessionRequest(registry, SeleniumProtocol.WebDriver, desiredCapability);
MockedRequestHandler handler = new MockedRequestHandler(request, null, registry);
return handler;
createNewSessionRequest(registry, desiredCapability);
return new MockedRequestHandler(request, null, registry);
}


public static MockedRequestHandler createStopSessionHandler(GridRegistry registry, TestSession session) {
SeleniumBasedRequest request =
createMockedRequest(registry, SeleniumProtocol.WebDriver, RequestType.STOP_SESSION, null);
SeleniumBasedRequest request = createMockedRequest(registry, RequestType.STOP_SESSION, null);
MockedRequestHandler handler = new MockedRequestHandler(request, null, registry);
handler.setSession(session);
return handler;
}

public static SeleniumBasedRequest createMockedRequest(GridRegistry registry,
SeleniumProtocol protocol, RequestType type, Map<String, Object> desiredCapability) {
RequestType type, Map<String, Object> desiredCapability) {
HttpServletRequest request = mock(HttpServletRequest.class);
return new SeleniumBasedRequest(request, registry, type, desiredCapability) {

Expand All @@ -78,7 +75,7 @@ public Map<String, Object> extractDesiredCapability() {
}

public static SeleniumBasedRequest createNewSessionRequest(GridRegistry registry,
SeleniumProtocol protocol, Map<String, Object> desiredCapability) {
return createMockedRequest(registry, protocol, RequestType.START_SESSION, desiredCapability);
Map<String, Object> desiredCapability) {
return createMockedRequest(registry, RequestType.START_SESSION, desiredCapability);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void setSession(TestSession session) {
}

@Override
protected void forwardRequest(TestSession session, RequestHandler handler) throws IOException {
protected void forwardRequest(TestSession session, RequestHandler handler) {
// do nothing
}

Expand Down

0 comments on commit 85f900d

Please sign in to comment.