Skip to content

Commit 6d92e12

Browse files
committed
Remove some static cling from the Grid tests.
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
1 parent 8bb8a03 commit 6d92e12

File tree

3 files changed

+34
-36
lines changed

3 files changed

+34
-36
lines changed

java/server/test/org/openqa/grid/internal/DefaultToFIFOPriorityTest.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import static org.junit.Assert.assertNotNull;
2222
import static org.openqa.grid.common.RegistrationRequest.APP;
2323

24-
import org.junit.AfterClass;
25-
import org.junit.BeforeClass;
24+
import org.junit.After;
25+
import org.junit.Before;
2626
import org.junit.Test;
2727
import org.openqa.grid.internal.listeners.Prioritizer;
2828
import org.openqa.grid.internal.mock.GridHelper;
@@ -40,28 +40,27 @@ public class DefaultToFIFOPriorityTest {
4040

4141
private final static int MAX = 50;
4242

43-
private static Registry registry;
43+
private Registry registry;
4444

4545
// priority rule : nothing defined = FIFO
46-
private static Prioritizer fifo = null;
46+
private Prioritizer fifo = null;
4747

48-
private static Map<String, Object> ff = new HashMap<>();
49-
private static RemoteProxy p1;
50-
private static List<MockedRequestHandler> requests = Collections
51-
.synchronizedList(new ArrayList<MockedRequestHandler>());
52-
private static TestSession session = null;
48+
private Map<String, Object> ff = new HashMap<>();
49+
private List<MockedRequestHandler> requests =
50+
Collections.synchronizedList(new ArrayList<MockedRequestHandler>());
5351

5452
/**
5553
* create a hub with 1 FF
5654
*
5755
* @throws InterruptedException
5856
*/
59-
@BeforeClass
60-
public static void setup() throws InterruptedException {
57+
@Before
58+
public void setup() throws InterruptedException {
6159
registry = Registry.newInstance();
6260
registry.setPrioritizer(fifo);
6361
ff.put(APP, "FF");
64-
p1 = RemoteProxyFactory.getNewBasicRemoteProxy(ff, "http://machine1:4444", registry);
62+
RemoteProxy p1 =
63+
RemoteProxyFactory.getNewBasicRemoteProxy(ff, "http://machine1:4444", registry);
6564
registry.add(p1);
6665

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

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

117-
@AfterClass
118-
public static void teardown() {
116+
@After
117+
public void teardown() {
119118
registry.stop();
120119
}
121120

java/server/test/org/openqa/grid/internal/RegistryStateTest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import static org.openqa.grid.common.RegistrationRequest.MAX_SESSION;
2626
import static org.openqa.grid.common.RegistrationRequest.REMOTE_HOST;
2727

28-
import org.junit.BeforeClass;
28+
import org.junit.Before;
2929
import org.junit.Test;
3030
import org.openqa.grid.common.RegistrationRequest;
3131
import org.openqa.grid.internal.mock.GridHelper;
@@ -38,17 +38,16 @@
3838

3939
public class RegistryStateTest {
4040

41-
42-
static RegistrationRequest req = null;
43-
static Map<String, Object> app1 = new HashMap<>();
44-
static Map<String, Object> app2 = new HashMap<>();
41+
private RegistrationRequest req = null;
42+
private Map<String, Object> app1 = new HashMap<>();
43+
private Map<String, Object> app2 = new HashMap<>();
4544

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

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

7473
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);
7574

76-
7775
try {
7876
registry.add(p1);
7977

@@ -89,7 +87,7 @@ public void sessionIsRemoved() {
8987
}
9088

9189
@Test(timeout = 5000)
92-
public void basichecks() {
90+
public void basiChecks() {
9391
Registry registry = Registry.newInstance();
9492
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);
9593

java/server/test/org/openqa/grid/internal/listener/RegistrationListenerTest.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import static org.openqa.grid.common.RegistrationRequest.APP;
2424
import static org.openqa.grid.common.RegistrationRequest.REMOTE_HOST;
2525

26-
import org.junit.BeforeClass;
26+
import org.junit.Before;
2727
import org.junit.Test;
2828
import org.openqa.grid.common.RegistrationRequest;
2929
import org.openqa.grid.internal.DetachedRemoteProxy;
@@ -39,9 +39,9 @@
3939

4040
public class RegistrationListenerTest {
4141

42-
private static boolean serverUp = false;
42+
private boolean serverUp = false;
4343

44-
static class MyRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {
44+
private class MyRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {
4545

4646
public MyRemoteProxy(RegistrationRequest request, Registry registry) {
4747
super(request, registry);
@@ -57,11 +57,11 @@ public void beforeRegistration() {
5757
}
5858
}
5959

60-
static RegistrationRequest req = null;
61-
static Map<String, Object> app1 = new HashMap<>();
60+
private RegistrationRequest req = null;
61+
private Map<String, Object> app1 = new HashMap<>();
6262

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

86-
private static Boolean firstRun = true;
86+
private final Object lock = new Object();
87+
private Boolean firstRun = true;
8788

8889
/**
8990
* this proxy will throw an exception on registration the first time.
9091
*
9192
* @author François Reynaud
9293
*/
93-
static class MyBuggyRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {
94+
private class MyBuggyRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {
9495

9596
public MyBuggyRemoteProxy(RegistrationRequest request, Registry registry) {
9697
super(request, registry);
9798
}
9899

99100
public void beforeRegistration() {
100-
synchronized (firstRun) {
101+
synchronized (lock) {
101102
if (firstRun) {
102103
firstRun = false;
103104
throw new NullPointerException();
@@ -118,9 +119,9 @@ public void testBugRegistration() {
118119
assertEquals(registry.getAllProxies().size(), 1);
119120
}
120121

121-
static boolean slowRemoteUp = false;
122+
private boolean slowRemoteUp = false;
122123

123-
static class MySlowRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {
124+
private class MySlowRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {
124125

125126
public MySlowRemoteProxy(RegistrationRequest request, Registry registry) {
126127
super(request, registry);

0 commit comments

Comments
 (0)