Skip to content

Commit

Permalink
Remove some static cling from the Grid tests.
Browse files Browse the repository at this point in the history
I'm attempting to get these working with Buck, and there's something
very quirky going on. In the process of debugging, I noticed that we
were using static a little too freely. Replaced with instance fields
  • Loading branch information
shs96c committed Sep 8, 2015
1 parent 8bb8a03 commit 6d92e12
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import static org.junit.Assert.assertNotNull;
import static org.openqa.grid.common.RegistrationRequest.APP;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.grid.internal.listeners.Prioritizer;
import org.openqa.grid.internal.mock.GridHelper;
Expand All @@ -40,28 +40,27 @@ public class DefaultToFIFOPriorityTest {

private final static int MAX = 50;

private static Registry registry;
private Registry registry;

// priority rule : nothing defined = FIFO
private static Prioritizer fifo = null;
private Prioritizer fifo = null;

private static Map<String, Object> ff = new HashMap<>();
private static RemoteProxy p1;
private static List<MockedRequestHandler> requests = Collections
.synchronizedList(new ArrayList<MockedRequestHandler>());
private static TestSession session = null;
private Map<String, Object> ff = new HashMap<>();
private List<MockedRequestHandler> requests =
Collections.synchronizedList(new ArrayList<MockedRequestHandler>());

/**
* create a hub with 1 FF
*
* @throws InterruptedException
*/
@BeforeClass
public static void setup() throws InterruptedException {
@Before
public void setup() throws InterruptedException {
registry = Registry.newInstance();
registry.setPrioritizer(fifo);
ff.put(APP, "FF");
p1 = RemoteProxyFactory.getNewBasicRemoteProxy(ff, "http://machine1:4444", registry);
RemoteProxy p1 =
RemoteProxyFactory.getNewBasicRemoteProxy(ff, "http://machine1:4444", registry);
registry.add(p1);

for (int i = 1; i <= MAX; i++) {
Expand All @@ -76,7 +75,7 @@ public static void setup() throws InterruptedException {
// use all the spots ( so 1 ) of the grid so that a queue builds up
MockedRequestHandler newSessionRequest =GridHelper.createNewSessionHandler(registry, ff);
newSessionRequest.process();
session = newSessionRequest.getSession();
TestSession session = newSessionRequest.getSession();

// fill the queue with MAX requests.
for (MockedRequestHandler h : requests) {
Expand Down Expand Up @@ -114,8 +113,8 @@ public void validateRequestAreHandledFIFO() throws InterruptedException {
assertEquals(1, requests.get(0).getRequest().getDesiredCapabilities().get("_priority"));
}

@AfterClass
public static void teardown() {
@After
public void teardown() {
registry.stop();
}

Expand Down
16 changes: 7 additions & 9 deletions java/server/test/org/openqa/grid/internal/RegistryStateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static org.openqa.grid.common.RegistrationRequest.MAX_SESSION;
import static org.openqa.grid.common.RegistrationRequest.REMOTE_HOST;

import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Test;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.internal.mock.GridHelper;
Expand All @@ -38,17 +38,16 @@

public class RegistryStateTest {


static RegistrationRequest req = null;
static Map<String, Object> app1 = new HashMap<>();
static Map<String, Object> app2 = new HashMap<>();
private RegistrationRequest req = null;
private Map<String, Object> app1 = new HashMap<>();
private Map<String, Object> app2 = new HashMap<>();

/**
* create a proxy than can host up to 5 tests at the same time. - of type app1 ( max 5 tests at
* the same time ) could be Firefox for instance - of type app2 ( max 1 test ) could be IE
*/
@BeforeClass
public static void prepareReqRequest() {
@Before
public void prepareReqRequest() {

Map<String, Object> config = new HashMap<>();
app1.put(APP, "app1");
Expand All @@ -73,7 +72,6 @@ public void sessionIsRemoved() {

RemoteProxy p1 = new DetachedRemoteProxy(req, registry);


try {
registry.add(p1);

Expand All @@ -89,7 +87,7 @@ public void sessionIsRemoved() {
}

@Test(timeout = 5000)
public void basichecks() {
public void basiChecks() {
Registry registry = Registry.newInstance();
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static org.openqa.grid.common.RegistrationRequest.APP;
import static org.openqa.grid.common.RegistrationRequest.REMOTE_HOST;

import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Test;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.internal.DetachedRemoteProxy;
Expand All @@ -39,9 +39,9 @@

public class RegistrationListenerTest {

private static boolean serverUp = false;
private boolean serverUp = false;

static class MyRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {
private class MyRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {

public MyRemoteProxy(RegistrationRequest request, Registry registry) {
super(request, registry);
Expand All @@ -57,11 +57,11 @@ public void beforeRegistration() {
}
}

static RegistrationRequest req = null;
static Map<String, Object> app1 = new HashMap<>();
private RegistrationRequest req = null;
private Map<String, Object> app1 = new HashMap<>();

@BeforeClass
public static void prepareReqRequest() {
@Before
public void prepareReqRequest() {
Map<String, Object> config = new HashMap<>();
app1.put(APP, "app1");
config.put(REMOTE_HOST, "http://machine1:4444");
Expand All @@ -83,21 +83,22 @@ public void testRegistration() {
assertTrue(serverUp);
}

private static Boolean firstRun = true;
private final Object lock = new Object();
private Boolean firstRun = true;

/**
* this proxy will throw an exception on registration the first time.
*
* @author François Reynaud
*/
static class MyBuggyRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {
private class MyBuggyRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {

public MyBuggyRemoteProxy(RegistrationRequest request, Registry registry) {
super(request, registry);
}

public void beforeRegistration() {
synchronized (firstRun) {
synchronized (lock) {
if (firstRun) {
firstRun = false;
throw new NullPointerException();
Expand All @@ -118,9 +119,9 @@ public void testBugRegistration() {
assertEquals(registry.getAllProxies().size(), 1);
}

static boolean slowRemoteUp = false;
private boolean slowRemoteUp = false;

static class MySlowRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {
private class MySlowRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {

public MySlowRemoteProxy(RegistrationRequest request, Registry registry) {
super(request, registry);
Expand Down

0 comments on commit 6d92e12

Please sign in to comment.