Skip to content

Commit

Permalink
[grid] Fix build due to SessionRequests renaming (#9397)
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani authored Apr 20, 2021
1 parent ca2c72a commit 1d31428
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 77 deletions.
4 changes: 2 additions & 2 deletions java/server/src/org/openqa/selenium/grid/commands/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.openqa.selenium.grid.sessionqueue.local.SessionRequests;
import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;
import org.openqa.selenium.grid.sessionqueue.config.SessionRequestOptions;
import org.openqa.selenium.grid.sessionqueue.local.LocalSessionRequests;
import org.openqa.selenium.grid.sessionqueue.local.SessionRequests;
import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;
import org.openqa.selenium.grid.web.CombinedHandler;
import org.openqa.selenium.grid.web.GridUiRoute;
Expand Down Expand Up @@ -144,7 +144,7 @@ protected Handlers createHandlers(Config config) {
networkOptions.getHttpClientFactory(tracer));

SessionRequestOptions sessionRequestOptions = new SessionRequestOptions(config);
SessionRequests sessionRequests = new LocalSessionRequests(
SessionRequests sessionRequests = new SessionRequests(
tracer,
bus,
sessionRequestOptions.getSessionRequestRetryInterval(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.openqa.selenium.grid.sessionqueue.local.SessionRequests;
import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;
import org.openqa.selenium.grid.sessionqueue.config.SessionRequestOptions;
import org.openqa.selenium.grid.sessionqueue.local.LocalSessionRequests;
import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;
import org.openqa.selenium.grid.web.CombinedHandler;
import org.openqa.selenium.grid.web.GridUiRoute;
Expand Down Expand Up @@ -141,7 +140,7 @@ protected Handlers createHandlers(Config config) {
combinedHandler.addHandler(sessions);

SessionRequestOptions sessionRequestOptions = new SessionRequestOptions(config);
SessionRequests sessionRequests = new LocalSessionRequests(
SessionRequests sessionRequests = new SessionRequests(
tracer,
bus,
sessionRequestOptions.getSessionRequestRetryInterval(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static NewSessionQueue create(Config config) {
EventBus bus = new EventBusOptions(config).getEventBus();
Duration retryInterval = new SessionRequestOptions(config).getSessionRequestRetryInterval();
Duration requestTimeout = new SessionRequestOptions(config).getSessionRequestTimeout();
SessionRequests sessionRequests = new LocalSessionRequests(
SessionRequests sessionRequests = new SessionRequests(
tracer,
bus,
retryInterval,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,28 @@

@ManagedService(objectName = "org.seleniumhq.grid:type=SessionQueue,name=LocalSessionQueue",
description = "New session queue")
public class LocalSessionRequests extends SessionRequests {
public class SessionRequests {

private static final Logger LOG = Logger.getLogger(LocalSessionRequests.class.getName());
private static final Logger LOG = Logger.getLogger(SessionRequests.class.getName());
private final EventBus bus;
private final Tracer tracer;
private final Duration retryInterval;
private final Duration requestTimeout;
private final Deque<SessionRequest> sessionRequests = new ConcurrentLinkedDeque<>();
private final ReadWriteLock lock = new ReentrantReadWriteLock(true);
private final ScheduledExecutorService executorService =
Executors.newSingleThreadScheduledExecutor();
private final Thread shutdownHook = new Thread(this::callExecutorShutdown);
private final String timedOutErrorMessage = String.format(
"New session request rejected after being in the queue for more than %s",
format(requestTimeout));

public LocalSessionRequests(

public SessionRequests(
Tracer tracer,
EventBus bus,
Duration retryInterval,
Duration requestTimeout) {
super(tracer, retryInterval, requestTimeout);
this.tracer = Require.nonNull("Tracer", tracer);
this.retryInterval = Require.nonNull("Session request retry interval", retryInterval);
this.requestTimeout = Require.nonNull("Session request timeout", requestTimeout);
this.bus = Require.nonNull("Event bus", bus);
Runtime.getRuntime().addShutdownHook(shutdownHook);

Expand All @@ -95,15 +98,13 @@ public static SessionRequests create(Config config) {
EventBus bus = new EventBusOptions(config).getEventBus();
Duration retryInterval = new SessionRequestOptions(config).getSessionRequestRetryInterval();
Duration requestTimeout = new SessionRequestOptions(config).getSessionRequestTimeout();
return new LocalSessionRequests(tracer, bus, retryInterval, requestTimeout);
return new SessionRequests(tracer, bus, retryInterval, requestTimeout);
}

@Override
public boolean isReady() {
return bus.isReady();
}

@Override
@ManagedAttribute(name = "NewSessionQueueSize")
public int getQueueSize() {
Lock readLock = lock.readLock();
Expand All @@ -115,7 +116,6 @@ public int getQueueSize() {
}
}

@Override
public List<Set<Capabilities>> getQueuedRequests() {
Lock readLock = lock.readLock();
readLock.lock();
Expand All @@ -128,7 +128,6 @@ public List<Set<Capabilities>> getQueuedRequests() {
}
}

@Override
public boolean offerLast(SessionRequest request) {
Require.nonNull("New Session request", request);

Expand All @@ -139,13 +138,13 @@ public boolean offerLast(SessionRequest request) {
try {
Map<String, EventAttributeValue> attributeMap = new HashMap<>();
attributeMap.put(
AttributeKey.LOGGER_CLASS.getKey(), EventAttribute.setValue(getClass().getName()));
AttributeKey.LOGGER_CLASS.getKey(), EventAttribute.setValue(getClass().getName()));

boolean added = sessionRequests.offerLast(request);

attributeMap.put(
AttributeKey.REQUEST_ID.getKey(),
EventAttribute.setValue(request.getRequestId().toString()));
AttributeKey.REQUEST_ID.getKey(),
EventAttribute.setValue(request.getRequestId().toString()));
attributeMap.put("request.added", EventAttribute.setValue(added));
span.addEvent("Add new session request to the queue", attributeMap);

Expand All @@ -160,7 +159,6 @@ public boolean offerLast(SessionRequest request) {
}
}

@Override
public boolean offerFirst(SessionRequest request) {
Require.nonNull("New Session request", request);
Lock writeLock = lock.writeLock();
Expand All @@ -169,7 +167,7 @@ public boolean offerFirst(SessionRequest request) {
boolean added = sessionRequests.offerFirst(request);
if (added) {
executorService.schedule(() -> retryRequest(request),
super.retryInterval.getSeconds(), TimeUnit.SECONDS);
retryInterval.getSeconds(), TimeUnit.SECONDS);
}
return added;
} finally {
Expand All @@ -186,7 +184,7 @@ private void retryRequest(SessionRequest sessionRequest) {
LOG.log(Level.INFO, "Request {0} timed out", requestId);
sessionRequests.remove(sessionRequest);
bus.fire(new NewSessionRejectedEvent(
new NewSessionErrorResponse(requestId, timedOutErrorMessage)));
new NewSessionErrorResponse(requestId, getTimeoutErrorMessage())));
} else {
LOG.log(Level.INFO,
"Adding request back to the queue. All slots are busy. Request: {0}",
Expand All @@ -198,7 +196,6 @@ private void retryRequest(SessionRequest sessionRequest) {
}
}

@Override
public Optional<SessionRequest> remove(RequestId id) {
Lock writeLock = lock.writeLock();
writeLock.lock();
Expand Down Expand Up @@ -229,7 +226,7 @@ public Optional<SessionRequest> remove(RequestId id) {
if (request.isPresent()) {
if (hasRequestTimedOut(request.get())) {
bus.fire(new NewSessionRejectedEvent(
new NewSessionErrorResponse(id, timedOutErrorMessage)));
new NewSessionErrorResponse(id, getTimeoutErrorMessage())));
return Optional.empty();
}
}
Expand All @@ -239,7 +236,6 @@ public Optional<SessionRequest> remove(RequestId id) {
}
}

@Override
public int clear() {
Lock writeLock = lock.writeLock();
writeLock.lock();
Expand Down Expand Up @@ -271,7 +267,7 @@ private void purgeTimedOutRequests() {
if (hasRequestTimedOut(sessionRequest)) {
iterator.remove();
bus.fire(new NewSessionRejectedEvent(
new NewSessionErrorResponse(sessionRequest.getRequestId(), timedOutErrorMessage)));
new NewSessionErrorResponse(sessionRequest.getRequestId(), getTimeoutErrorMessage())));
}
}
} finally {
Expand Down Expand Up @@ -307,5 +303,10 @@ private static String format(Duration duration) {
toReturn.append(secs).append("s");
return toReturn.toString();
}
}

private String getTimeoutErrorMessage() {
return String.format(
"New session request rejected after being in the queue for more than %s",
format(requestTimeout));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.openqa.selenium.grid.node.local.LocalNode;
import org.openqa.selenium.grid.security.Secret;
import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;
import org.openqa.selenium.grid.sessionqueue.local.LocalSessionRequests;
import org.openqa.selenium.grid.sessionqueue.local.SessionRequests;
import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;
import org.openqa.selenium.grid.testing.TestSessionFactory;
import org.openqa.selenium.grid.web.CombinedHandler;
Expand Down Expand Up @@ -106,7 +106,7 @@ public void setUpDistributor() throws MalformedURLException {
HttpClient.Factory.createDefault());

LocalSessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localNewSessionQueue = new LocalSessionRequests(
SessionRequests localNewSessionQueue = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.openqa.selenium.grid.sessionmap.SessionMap;
import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;
import org.openqa.selenium.grid.sessionqueue.SessionRequest;
import org.openqa.selenium.grid.sessionqueue.local.LocalSessionRequests;
import org.openqa.selenium.grid.sessionqueue.local.SessionRequests;
import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;
import org.openqa.selenium.grid.testing.EitherAssert;
import org.openqa.selenium.grid.testing.PassthroughHttpClient;
Expand Down Expand Up @@ -124,7 +124,7 @@ public void setUp() throws URISyntaxException {
tracer = DefaultTestTracer.createTracer();
bus = new GuavaEventBus();
LocalSessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localNewSessionQueue = new LocalSessionRequests(
SessionRequests localNewSessionQueue = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -156,7 +156,7 @@ public void creatingANewSessionWithoutANodeEndsInFailure() {
public void shouldStartHeartBeatOnNodeRegistration() {
EventBus bus = new GuavaEventBus();
LocalSessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localNewSessionQueue = new LocalSessionRequests(
SessionRequests localNewSessionQueue = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -207,7 +207,7 @@ public void shouldStartHeartBeatOnNodeRegistration() {
@Test
public void shouldBeAbleToAddANodeAndCreateASession() {
LocalSessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -248,7 +248,7 @@ public void shouldBeAbleToAddANodeAndCreateASession() {
@Test
public void creatingASessionAddsItToTheSessionMap() {
LocalSessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -291,7 +291,7 @@ public void creatingASessionAddsItToTheSessionMap() {
@Test
public void shouldBeAbleToRemoveANode() throws MalformedURLException {
LocalSessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -332,7 +332,7 @@ public void shouldBeAbleToRemoveANode() throws MalformedURLException {
@Test
public void testDrainingNodeDoesNotAcceptNewSessions() {
SessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -368,7 +368,7 @@ public void testDrainingNodeDoesNotAcceptNewSessions() {
@Test
public void testDrainedNodeShutsDownOnceEmpty() throws InterruptedException {
SessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -414,7 +414,7 @@ public void testDrainedNodeShutsDownOnceEmpty() throws InterruptedException {
@Test
public void drainedNodeDoesNotShutDownIfNotEmpty() throws InterruptedException {
SessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -460,7 +460,7 @@ public void drainedNodeDoesNotShutDownIfNotEmpty() throws InterruptedException {
@Test
public void drainedNodeShutsDownAfterSessionsFinish() throws InterruptedException {
SessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -535,7 +535,7 @@ public void theMostLightlyLoadedNodeIsSelectedFirst() {
// * reverse insertion order
// * sorted with most heavily used first
SessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -582,7 +582,7 @@ public void theMostLightlyLoadedNodeIsSelectedFirst() {
@Test
public void shouldUseLastSessionCreatedTimeAsTieBreaker() {
SessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -661,7 +661,7 @@ public void shouldIncludeHostsThatAreUpInHostList() {
CombinedHandler handler = new CombinedHandler();

SessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -717,7 +717,7 @@ public void shouldIncludeHostsThatAreUpInHostList() {
@Test
public void shouldNotScheduleAJobIfAllSlotsAreBeingUsed() {
SessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -757,7 +757,7 @@ public void shouldNotScheduleAJobIfAllSlotsAreBeingUsed() {
@Test
public void shouldReleaseSlotOnceSessionEnds() {
SessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -816,7 +816,7 @@ public void shouldNotStartASessionIfTheCapabilitiesAreNotSupported() {
CombinedHandler handler = new CombinedHandler();

LocalSessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -852,7 +852,7 @@ public void shouldNotStartASessionIfTheCapabilitiesAreNotSupported() {
@Test
public void attemptingToStartASessionWhichFailsMarksAsTheSlotAsAvailable() {
SessionMap sessions = new LocalSessionMap(tracer, bus);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -894,7 +894,7 @@ public void shouldReturnNodesThatWereDownToPoolOfNodesOnceTheyMarkTheirHealthChe
SessionMap sessions = new LocalSessionMap(tracer, bus);
handler.addHandler(sessions);
AtomicReference<Availability> isUp = new AtomicReference<>(DOWN);
LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down Expand Up @@ -969,7 +969,7 @@ public void shouldPrioritizeHostsWithTheMostSlotsAvailableForASessionType() {
SessionMap sessions = new LocalSessionMap(tracer, bus);
handler.addHandler(sessions);

LocalSessionRequests localSessionRequests = new LocalSessionRequests(
SessionRequests localSessionRequests = new SessionRequests(
tracer,
bus,
Duration.ofSeconds(2),
Expand Down
Loading

0 comments on commit 1d31428

Please sign in to comment.