Skip to content

Commit 1ecef25

Browse files
committed
[grid] Remove "Registry.getConfiguration"
1 parent 87c8732 commit 1ecef25

File tree

10 files changed

+62
-95
lines changed

10 files changed

+62
-95
lines changed

java/server/src/org/openqa/grid/internal/BaseGridRegistry.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.openqa.grid.internal;
1919

20-
import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;
2120
import org.openqa.grid.web.Hub;
2221
import org.openqa.selenium.remote.http.HttpClient;
2322
import org.openqa.selenium.remote.internal.ApacheHttpClient;
@@ -27,27 +26,13 @@
2726

2827
public abstract class BaseGridRegistry implements GridRegistry {
2928
protected final HttpClientFactory httpClientFactory;
30-
@Deprecated
31-
protected GridHubConfiguration configuration;
3229

3330
// The following needs to be volatile because we expose a public setters
3431
protected volatile Hub hub;
3532

3633
public BaseGridRegistry(Hub hub) {
3734
this.httpClientFactory = new HttpClientFactory();
3835
this.hub = hub;
39-
40-
this.configuration = (hub != null) ?
41-
hub.getConfiguration() : new GridHubConfiguration();
42-
}
43-
44-
/**
45-
* @see GridRegistry#getConfiguration()
46-
*/
47-
@Deprecated
48-
public GridHubConfiguration getConfiguration() {
49-
return (hub != null) ? hub.getConfiguration() :
50-
(configuration != null) ? configuration : new GridHubConfiguration();
5136
}
5237

5338
/**
@@ -62,9 +47,6 @@ public Hub getHub() {
6247
*/
6348
public void setHub(Hub hub) {
6449
this.hub = hub;
65-
if (hub != null) {
66-
this.configuration = hub.getConfiguration();
67-
}
6850
}
6951

7052
/**

java/server/src/org/openqa/grid/internal/DefaultGridRegistry.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ private void assignRequestToProxy() {
235235
try {
236236
testSessionAvailable.await(5, TimeUnit.SECONDS);
237237

238-
newSessionQueue.processQueue(this::takeRequestHandler, configuration.prioritizer);
238+
newSessionQueue.processQueue(
239+
this::takeRequestHandler,
240+
getHub().getConfiguration().prioritizer);
239241
// Just make sure we delete anything that is logged on this thread from memory
240242
LoggingManager.perSessionLogHandler().clearThreadTempLogs();
241243
} catch (InterruptedException e) {

java/server/src/org/openqa/grid/internal/GridRegistry.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@
3131
public interface GridRegistry {
3232
String KEY = GridRegistry.class.getName();
3333

34-
/**
35-
* @return the {@link GridHubConfiguration} for this registry
36-
* @deprecated use #getHub() to access the {@link GridHubConfiguration} instead.
37-
*/
38-
@Deprecated
39-
GridHubConfiguration getConfiguration();
40-
4134
/**
4235
* Ends this test session, releasing the resources in the registry. Resources should be released
4336
* on a separate thread so the call does not block. MUST honor listeners for the {@link TestSlot} which

java/server/src/org/openqa/grid/internal/TestSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public String toString() {
204204

205205
private HttpClient getClient(URL url) {
206206
GridRegistry reg = slot.getProxy().getRegistry();
207-
long browserTimeout = TimeUnit.SECONDS.toMillis(reg.getConfiguration().browserTimeout);
207+
long browserTimeout = TimeUnit.SECONDS.toMillis(reg.getHub().getConfiguration().browserTimeout);
208208
if (browserTimeout > 0) {
209209
final long selenium_server_cleanup_cycle = browserTimeout / 10;
210210
browserTimeout += (selenium_server_cleanup_cycle + MAX_NETWORK_LATENCY);

java/server/src/org/openqa/grid/web/Hub.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class Hub implements Stoppable {
6565

6666
private static final Logger log = Logger.getLogger(Hub.class.getName());
6767

68-
private GridHubConfiguration config;
68+
private final GridHubConfiguration config;
6969
private final GridRegistry registry;
7070
private final Map<String, Class<? extends Servlet>> extraServlet = Maps.newHashMap();
7171

@@ -85,7 +85,7 @@ public GridRegistry getRegistry() {
8585
}
8686

8787
public Hub(GridHubConfiguration gridHubConfiguration) {
88-
config = gridHubConfiguration;
88+
config = gridHubConfiguration == null ? new GridHubConfiguration() : gridHubConfiguration;
8989

9090
try {
9191
registry = (GridRegistry) Class.forName(config.registry).newInstance();

java/server/src/org/openqa/grid/web/servlet/HubStatusServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private Map<String, Object> getResponse(HttpServletRequest request) {
113113
}
114114

115115
GridRegistry registry = getRegistry();
116-
JsonElement config = registry.getConfiguration().toJson();
116+
JsonElement config = registry.getHub().getConfiguration().toJson();
117117
for (Map.Entry<String, JsonElement> entry : config.getAsJsonObject().entrySet()) {
118118
if (keysToReturn == null || keysToReturn.isEmpty() || keysToReturn.contains(entry.getKey())) {
119119
res.put(entry.getKey(), entry.getValue());

java/server/src/org/openqa/grid/web/servlet/handler/RequestHandler.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.openqa.grid.internal.TestSession;
2929
import org.openqa.grid.internal.exception.NewSessionException;
3030
import org.openqa.grid.internal.listeners.TestSessionListener;
31+
import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;
3132
import org.openqa.selenium.remote.DesiredCapabilities;
3233
import org.openqa.selenium.remote.NewSessionPayload;
3334

@@ -188,8 +189,9 @@ private void beforeSessionEvent() throws NewSessionException {
188189
public void waitForSessionBound() throws InterruptedException, TimeoutException {
189190
// Maintain compatibility with Grid 1.x, which had the ability to
190191
// specify how long to wait before canceling a request.
191-
Integer newSessionWaitTimeout = registry.getConfiguration().newSessionWaitTimeout != null ?
192-
registry.getConfiguration().newSessionWaitTimeout : 0;
192+
GridHubConfiguration configuration = getRegistry().getHub().getConfiguration();
193+
Integer newSessionWaitTimeout = configuration.newSessionWaitTimeout != null ?
194+
configuration.newSessionWaitTimeout : 0;
193195
if (newSessionWaitTimeout > 0) {
194196
if (!sessionAssigned.await(newSessionWaitTimeout.longValue(), TimeUnit.MILLISECONDS)) {
195197
throw new TimeoutException("Request timed out waiting for a node to become available.");
@@ -215,9 +217,11 @@ public HttpServletResponse getResponse() {
215217
}
216218

217219
public int compareTo(RequestHandler o) {
218-
if (registry.getConfiguration().prioritizer != null) {
219-
return registry.getConfiguration().prioritizer.compareTo(this.getRequest().getDesiredCapabilities(), o.getRequest()
220-
.getDesiredCapabilities());
220+
GridHubConfiguration configuration = getRegistry().getHub().getConfiguration();
221+
if (configuration.prioritizer != null) {
222+
return configuration.prioritizer.compareTo(
223+
this.getRequest().getDesiredCapabilities(),
224+
o.getRequest().getDesiredCapabilities());
221225
}
222226
return 0;
223227
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void setup() throws Exception {
4646
p1 = RemoteProxyFactory.getNewBasicRemoteProxy(ff, "http://machine1:4444", registry);
4747
registry.add(p1);
4848
// after 1 sec in the queue, request are kicked out.
49-
registry.getConfiguration().newSessionWaitTimeout = 1000;
49+
registry.getHub().getConfiguration().newSessionWaitTimeout = 1000;
5050
}
5151

5252
@Test(timeout = 5000)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ public void stupidConfig() throws InterruptedException {
237237
req.getConfiguration().cleanUpCycle = cycle;
238238
req.getConfiguration().host = "localhost";
239239

240-
registry.getConfiguration().cleanUpCycle = cycle;
241-
registry.getConfiguration().timeout = timeout;
240+
registry.getHub().getConfiguration().cleanUpCycle = cycle;
241+
registry.getHub().getConfiguration().timeout = timeout;
242242

243243
final MyStupidConfig proxy = new MyStupidConfig(req, registry);
244244
proxy.setupTimeoutListener();

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

Lines changed: 43 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,12 @@
1717

1818
package org.openqa.grid.internal.listener;
1919

20-
import static org.mockito.Mockito.any;
21-
import static org.mockito.Mockito.anyInt;
2220
import static org.mockito.Mockito.mock;
2321
import static org.mockito.Mockito.verify;
2422
import static org.mockito.Mockito.when;
2523

26-
import org.apache.http.Header;
27-
import org.apache.http.HttpEntity;
28-
import org.apache.http.HttpHost;
29-
import org.apache.http.HttpRequest;
30-
import org.apache.http.HttpResponse;
31-
import org.apache.http.StatusLine;
32-
import org.apache.http.client.HttpClient;
33-
import org.apache.http.protocol.HttpContext;
3424
import org.junit.Before;
3525
import org.junit.Test;
36-
import org.mockito.invocation.InvocationOnMock;
37-
import org.mockito.stubbing.Answer;
3826
import org.openqa.grid.common.RegistrationRequest;
3927
import org.openqa.grid.internal.BaseRemoteProxy;
4028
import org.openqa.grid.internal.DefaultGridRegistry;
@@ -50,10 +38,8 @@
5038
import org.openqa.grid.web.servlet.handler.SeleniumBasedResponse;
5139
import org.openqa.selenium.remote.CapabilityType;
5240
import org.openqa.selenium.remote.DesiredCapabilities;
53-
import org.openqa.selenium.remote.internal.HttpClientFactory;
5441

5542
import java.io.IOException;
56-
import java.io.InputStream;
5743
import java.net.MalformedURLException;
5844
import java.net.URL;
5945
import java.util.Collections;
@@ -96,49 +82,49 @@ public URL getRemoteHost() {
9682
return null;
9783
}
9884

99-
@Override
100-
public HttpClientFactory getHttpClientFactory() {
101-
// Create mocks for network traffic
102-
HttpClientFactory factory = mock(HttpClientFactory.class);
103-
HttpClient client = mock(HttpClient.class);
104-
HttpResponse response = mock(HttpResponse.class);
105-
HttpEntity entity = mock(HttpEntity.class);
106-
InputStream stream = mock(InputStream.class);
107-
StatusLine line = mock(StatusLine.class);
108-
109-
when(line.getStatusCode()).thenReturn(200);
110-
when(response.getStatusLine()).thenReturn(line);
111-
when(response.getAllHeaders()).thenReturn(new Header[0]);
112-
when(response.getEntity()).thenReturn(entity);
113-
try {
114-
// Create a fake stream that will only return the a single number
115-
Answer<Integer> answer = new Answer<Integer>() {
116-
boolean hasBeenRead = false;
117-
@Override
118-
public Integer answer(InvocationOnMock invocation) {
119-
if (hasBeenRead) {
120-
return -1;
121-
}
122-
hasBeenRead = true;
123-
return 1;
124-
}
125-
};
126-
127-
// Have all the methods return mocks so client.execute returns our
128-
// mocked objects
129-
when(stream.read(any(byte[].class))).thenAnswer(answer);
130-
when(entity.getContent()).thenReturn(stream);
131-
when(client.execute(
132-
any(HttpHost.class),
133-
any(HttpRequest.class), any(
134-
HttpContext.class))).thenReturn(response);
135-
when(factory.getGridHttpClient(anyInt(), anyInt())).thenReturn(client);
136-
} catch (Exception e) {
137-
e.printStackTrace();
138-
}
139-
140-
return factory;
141-
}
85+
// @Override
86+
// public HttpClientFactory getHttpClientFactory() {
87+
// // Create mocks for network traffic
88+
// HttpClientFactory factory = mock(HttpClientFactory.class);
89+
// HttpClient client = mock(HttpClient.class);
90+
// HttpResponse response = mock(HttpResponse.class);
91+
// HttpEntity entity = mock(HttpEntity.class);
92+
// InputStream stream = mock(InputStream.class);
93+
// StatusLine line = mock(StatusLine.class);
94+
//
95+
// when(line.getStatusCode()).thenReturn(200);
96+
// when(response.getStatusLine()).thenReturn(line);
97+
// when(response.getAllHeaders()).thenReturn(new Header[0]);
98+
// when(response.getEntity()).thenReturn(entity);
99+
// try {
100+
// // Create a fake stream that will only return the a single number
101+
// Answer<Integer> answer = new Answer<Integer>() {
102+
// boolean hasBeenRead = false;
103+
// @Override
104+
// public Integer answer(InvocationOnMock invocation) {
105+
// if (hasBeenRead) {
106+
// return -1;
107+
// }
108+
// hasBeenRead = true;
109+
// return 1;
110+
// }
111+
// };
112+
//
113+
// // Have all the methods return mocks so client.execute returns our
114+
// // mocked objects
115+
// when(stream.read(any(byte[].class))).thenAnswer(answer);
116+
// when(entity.getContent()).thenReturn(stream);
117+
// when(client.execute(
118+
// any(HttpHost.class),
119+
// any(HttpRequest.class), any(
120+
// HttpContext.class))).thenReturn(response);
121+
// when(factory.getGridHttpClient(anyInt(), anyInt())).thenReturn(client);
122+
// } catch (Exception e) {
123+
// e.printStackTrace();
124+
// }
125+
//
126+
// return factory;
127+
// }
142128
}
143129

144130
private RegistrationRequest req = null;

0 commit comments

Comments
 (0)