Skip to content

Commit

Permalink
Deleting JsonKey, it's a useless abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Oct 10, 2015
1 parent 52b52f4 commit f4a8391
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

package org.openqa.grid.internal.utils;

import static org.openqa.grid.internal.utils.ServerJsonValues.BROWSER_TIMEOUT;
import static org.openqa.grid.internal.utils.ServerJsonValues.CLIENT_TIMEOUT;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -190,11 +187,11 @@ public void loadFromCommandLine(String[] args) {
if (helper.isParamPresent("-cleanUpCycle")) {
cleanupCycle = Integer.parseInt(helper.getParamValue("-cleanUpCycle"));
}
if (helper.isParamPresent(CLIENT_TIMEOUT.getAsParam())) {
setTimeout(Integer.parseInt(helper.getParamValue(CLIENT_TIMEOUT.getAsParam())) * 1000);
if (helper.isParamPresent("-timeout")) {
setTimeout(Integer.parseInt(helper.getParamValue("-timeout")) * 1000);
}
if (helper.isParamPresent(BROWSER_TIMEOUT.getAsParam())) {
setBrowserTimeout(Integer.parseInt(helper.getParamValue(BROWSER_TIMEOUT.getAsParam())) * 1000);
if (helper.isParamPresent("-browserTimeout")) {
setBrowserTimeout(Integer.parseInt(helper.getParamValue("-browserTimeout")) * 1000);
}
if (helper.isParamPresent("-newSessionWaitTimeout")) {
newSessionWaitTimeout = Integer.parseInt(helper.getParamValue("-newSessionWaitTimeout"));
Expand Down Expand Up @@ -352,15 +349,15 @@ public int getCleanupCycle() {
}

public int getTimeout() {
return getIntWith0Default(CLIENT_TIMEOUT);
return getIntWith0Default(RegistrationRequest.TIME_OUT);
}

public int getBrowserTimeout() {
return getIntWith0Default(BROWSER_TIMEOUT);
return getIntWith0Default(RegistrationRequest.BROWSER_TIME_OUT);
}

public void setBrowserTimeout(int browserTimeout) {
put(BROWSER_TIMEOUT, browserTimeout);
put(RegistrationRequest.BROWSER_TIME_OUT, browserTimeout);
}

public int getNewSessionWaitTimeout() {
Expand Down Expand Up @@ -404,21 +401,16 @@ public void setCleanupCycle(int cleanupCycle) {
}

public void setTimeout(int timeout) {
put(CLIENT_TIMEOUT, timeout);
}

private void put(JsonKey key, Object value){
allParams.put(key.getKey(), value);
put(RegistrationRequest.TIME_OUT, timeout);
}

private <T> T get(JsonKey jsonKey) {
//noinspection unchecked
return (T) allParams.get(jsonKey.getKey());
private void put(String key, Object value){
allParams.put(key, value);
}

private Integer getIntWith0Default(JsonKey jsonKey) {
private Integer getIntWith0Default(String jsonKey) {
//noinspection unchecked
final Object o = allParams.get(jsonKey.getKey());
final Object o = allParams.get(jsonKey);
if (o instanceof String){
return Integer.parseInt((String) o);
}
Expand Down
46 changes: 0 additions & 46 deletions java/server/src/org/openqa/grid/internal/utils/JsonKey.java

This file was deleted.

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

import static org.openqa.grid.common.RegistrationRequest.AUTO_REGISTER;
import static org.openqa.grid.internal.utils.ServerJsonValues.BROWSER_TIMEOUT;
import static org.openqa.grid.internal.utils.ServerJsonValues.CLIENT_TIMEOUT;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -96,12 +94,12 @@ public void startRemoteServer() throws Exception {

try {
JsonObject hubParameters = getHubConfiguration();
if (hubParameters.has(CLIENT_TIMEOUT.getKey())){
int timeout = hubParameters.get(CLIENT_TIMEOUT.getKey()).getAsInt() / 1000;
if (hubParameters.has(RegistrationRequest.TIME_OUT)){
int timeout = hubParameters.get(RegistrationRequest.TIME_OUT).getAsInt() / 1000;
remoteControlConfiguration.setTimeoutInSeconds(timeout);
}
if (hubParameters.has(BROWSER_TIMEOUT.getKey())) {
int browserTimeout = hubParameters.get(BROWSER_TIMEOUT.getKey()).getAsInt();
if (hubParameters.has(RegistrationRequest.BROWSER_TIME_OUT)) {
int browserTimeout = hubParameters.get(RegistrationRequest.BROWSER_TIME_OUT).getAsInt();
remoteControlConfiguration.setBrowserTimeoutInMs(browserTimeout);
}
} catch (Exception e) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
package org.openqa.grid.internal.utils;

import static com.thoughtworks.selenium.SeleneseTestBase.assertEquals;
import static org.openqa.grid.internal.utils.ServerJsonValues.BROWSER_TIMEOUT;
import static org.openqa.grid.internal.utils.ServerJsonValues.CLIENT_TIMEOUT;

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

public class GridHubConfigurationTest {

Expand All @@ -31,7 +30,7 @@ public void testGetTimeout() throws Exception {
assertEquals(300000, gridHubConfiguration.getTimeout()); // From DefaultHub.json file
gridHubConfiguration.setTimeout(123);
assertEquals(123, gridHubConfiguration.getTimeout());
assertEquals(123,gridHubConfiguration.getAllParams().get(CLIENT_TIMEOUT.getKey()));
assertEquals(123,gridHubConfiguration.getAllParams().get(RegistrationRequest.TIME_OUT));
}

@Test
Expand All @@ -40,7 +39,7 @@ public void testGetBrowserTimeout() throws Exception {
assertEquals(0, gridHubConfiguration.getBrowserTimeout());// From DefaultHub.json file
gridHubConfiguration.setBrowserTimeout(1233);
assertEquals(1233, gridHubConfiguration.getBrowserTimeout());
assertEquals(1233,gridHubConfiguration.getAllParams().get(BROWSER_TIMEOUT.getKey()));
assertEquals(1233,gridHubConfiguration.getAllParams().get(RegistrationRequest.BROWSER_TIME_OUT));

}

Expand Down

0 comments on commit f4a8391

Please sign in to comment.