Skip to content

Commit 6336abb

Browse files
committed
[grid] Removing NewSessionRequestEvent
No component except some tests listens to it.
1 parent 6f1b689 commit 6336abb

5 files changed

Lines changed: 150 additions & 175 deletions

File tree

java/src/org/openqa/selenium/grid/data/NewSessionRequestEvent.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

java/src/org/openqa/selenium/grid/sessionqueue/local/LocalNewSessionQueue.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package org.openqa.selenium.grid.sessionqueue.local;
22

3-
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
4-
import static java.util.concurrent.TimeUnit.MILLISECONDS;
5-
import static org.openqa.selenium.concurrent.ExecutorServices.shutdownGracefully;
6-
73
import com.google.common.annotations.VisibleForTesting;
84
import com.google.common.collect.ImmutableMap;
95
import com.google.common.collect.ImmutableSet;
@@ -16,7 +12,6 @@
1612
import org.openqa.selenium.grid.data.CreateSessionResponse;
1713
import org.openqa.selenium.grid.data.NewSessionErrorResponse;
1814
import org.openqa.selenium.grid.data.NewSessionRejectedEvent;
19-
import org.openqa.selenium.grid.data.NewSessionRequestEvent;
2015
import org.openqa.selenium.grid.data.RequestId;
2116
import org.openqa.selenium.grid.data.SessionRequest;
2217
import org.openqa.selenium.grid.data.SessionRequestCapability;
@@ -61,15 +56,17 @@
6156
import java.util.function.Predicate;
6257
import java.util.stream.Collectors;
6358

59+
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
60+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
61+
import static org.openqa.selenium.concurrent.ExecutorServices.shutdownGracefully;
62+
6463
/**
6564
* An in-memory implementation of the list of new session requests.
6665
* <p>
6766
* The lifecycle of a request can be described as:
6867
* <ol>
6968
* <li>User adds an item on to the queue using {@link #addToQueue(SessionRequest)}. This
7069
* will block until the request completes in some way.
71-
* <li>After being added, a {@link NewSessionRequestEvent} is fired. Listeners should use
72-
* this as an indication to call {@link #remove(RequestId)} to get the session request.
7370
* <li>If the session request is completed, then {@link #complete(RequestId, Either)} must
7471
* be called. This will not only ensure that {@link #addToQueue(SessionRequest)}
7572
* returns, but will also fire a {@link NewSessionRejectedEvent} if the session was
@@ -240,8 +237,6 @@ Data injectIntoQueue(SessionRequest request) {
240237
writeLock.unlock();
241238
}
242239

243-
bus.fire(new NewSessionRequestEvent(request.getRequestId()));
244-
245240
return data;
246241
}
247242

@@ -269,9 +264,6 @@ public boolean retryAddToQueue(SessionRequest request) {
269264
writeLock.unlock();
270265
}
271266

272-
if (added) {
273-
bus.fire(new NewSessionRequestEvent(request.getRequestId()));
274-
}
275267
return added;
276268
}
277269
}

java/src/org/openqa/selenium/net/PortProber.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
public class PortProber {
3333

34+
public static final int HIGHEST_PORT = 65535;
35+
public static final int START_OF_USER_PORTS = 1024;
3436
private static final Random random = new Random();
3537
private static final EphemeralPortRangeDetector ephemeralRangeDetector;
3638

@@ -46,9 +48,6 @@ public class PortProber {
4648
}
4749
}
4850

49-
public static final int HIGHEST_PORT = 65535;
50-
public static final int START_OF_USER_PORTS = 1024;
51-
5251
private PortProber() {
5352
// Utility class
5453
}
@@ -101,7 +100,7 @@ private static int checkPortIsFree(int port) {
101100
socket.bind(new InetSocketAddress("localhost", port));
102101
return socket.getLocalPort();
103102
} catch (IOException e) {
104-
return -1;
103+
return port;
105104
}
106105
}
107106

java/test/org/openqa/selenium/grid/graphql/GraphqlHandlerTest.java

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

1818
package org.openqa.selenium.grid.graphql;
1919

20-
import static java.util.Collections.singletonList;
21-
import static java.util.Collections.singletonMap;
22-
import static java.util.concurrent.TimeUnit.SECONDS;
23-
import static org.assertj.core.api.Assertions.assertThat;
24-
import static org.assertj.core.api.Assertions.fail;
25-
import static org.assertj.core.api.InstanceOfAssertFactories.LIST;
26-
import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
27-
import static org.openqa.selenium.json.Json.MAP_TYPE;
28-
import static org.openqa.selenium.remote.Dialect.OSS;
29-
import static org.openqa.selenium.remote.Dialect.W3C;
30-
import static org.openqa.selenium.remote.http.HttpMethod.GET;
31-
3220
import com.google.common.collect.ImmutableMap;
3321

3422
import org.junit.Before;
@@ -42,7 +30,6 @@
4230
import org.openqa.selenium.grid.data.CreateSessionRequest;
4331
import org.openqa.selenium.grid.data.CreateSessionResponse;
4432
import org.openqa.selenium.grid.data.DefaultSlotMatcher;
45-
import org.openqa.selenium.grid.data.NewSessionRequestEvent;
4633
import org.openqa.selenium.grid.data.RequestId;
4734
import org.openqa.selenium.grid.data.Session;
4835
import org.openqa.selenium.grid.data.SessionRequest;
@@ -81,7 +68,17 @@
8168
import java.util.Map;
8269
import java.util.Set;
8370
import java.util.UUID;
84-
import java.util.concurrent.CountDownLatch;
71+
72+
import static java.util.Collections.singletonList;
73+
import static java.util.Collections.singletonMap;
74+
import static org.assertj.core.api.Assertions.assertThat;
75+
import static org.assertj.core.api.Assertions.fail;
76+
import static org.assertj.core.api.InstanceOfAssertFactories.LIST;
77+
import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
78+
import static org.openqa.selenium.json.Json.MAP_TYPE;
79+
import static org.openqa.selenium.remote.Dialect.OSS;
80+
import static org.openqa.selenium.remote.Dialect.W3C;
81+
import static org.openqa.selenium.remote.http.HttpMethod.GET;
8582

8683
public class GraphqlHandlerTest {
8784

@@ -168,15 +165,13 @@ public void shouldBeAbleToGetGridVersion() {
168165

169166
private void continueOnceAddedToQueue(SessionRequest request) {
170167
// Add to the queue in the background
171-
CountDownLatch latch = new CountDownLatch(1);
172-
events.addListener(NewSessionRequestEvent.listener(id -> latch.countDown()));
173168
new Thread(() -> queue.addToQueue(request)).start();
174-
try {
175-
assertThat(latch.await(5, SECONDS)).isTrue();
176-
} catch (InterruptedException e) {
177-
Thread.currentThread().interrupt();
178-
throw new RuntimeException(e);
179-
}
169+
new FluentWait<>(request)
170+
.withTimeout(Duration.ofSeconds(5))
171+
.until(
172+
r -> queue.getQueueContents().stream()
173+
.anyMatch(sessionRequestCapability ->
174+
sessionRequestCapability.getRequestId().equals(r.getRequestId())));
180175
}
181176

182177
@Test

0 commit comments

Comments
 (0)