Skip to content

Commit ab529c4

Browse files
committed
[grid] Replace Guava map and set with Java equivalent for Distributor
1 parent 55f02a9 commit ab529c4

File tree

10 files changed

+27
-32
lines changed

10 files changed

+27
-32
lines changed

java/src/org/openqa/selenium/grid/distributor/DrainNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import static org.openqa.selenium.remote.http.Contents.asJson;
2121

22-
import com.google.common.collect.ImmutableMap;
2322
import java.io.UncheckedIOException;
23+
import java.util.Map;
2424
import java.util.Objects;
2525
import org.openqa.selenium.grid.data.NodeId;
2626
import org.openqa.selenium.remote.http.HttpHandler;
@@ -45,12 +45,12 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
4545
if (value) {
4646
response.setContent(
4747
asJson(
48-
ImmutableMap.of(
48+
Map.of(
4949
"value", value, "message", "Node status was successfully set to draining.")));
5050
} else {
5151
response.setContent(
5252
asJson(
53-
ImmutableMap.of(
53+
Map.of(
5454
"value",
5555
value,
5656
"message",

java/src/org/openqa/selenium/grid/distributor/GetDistributorStatus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import static org.openqa.selenium.remote.http.Contents.asJson;
2121

22-
import com.google.common.collect.ImmutableMap;
22+
import java.util.Map;
2323
import org.openqa.selenium.grid.data.DistributorStatus;
2424
import org.openqa.selenium.internal.Require;
2525
import org.openqa.selenium.remote.http.HttpHandler;
@@ -38,6 +38,6 @@ class GetDistributorStatus implements HttpHandler {
3838
public HttpResponse execute(HttpRequest req) {
3939
DistributorStatus status = distributor.getStatus();
4040

41-
return new HttpResponse().setContent(asJson(ImmutableMap.of("value", status)));
41+
return new HttpResponse().setContent(asJson(Map.of("value", status)));
4242
}
4343
}

java/src/org/openqa/selenium/grid/distributor/StatusHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import static org.openqa.selenium.remote.http.Contents.asJson;
2121

22-
import com.google.common.collect.ImmutableMap;
22+
import java.util.Map;
2323
import org.openqa.selenium.grid.data.DistributorStatus;
2424
import org.openqa.selenium.internal.Require;
2525
import org.openqa.selenium.remote.http.HttpHandler;
@@ -38,10 +38,10 @@ class StatusHandler implements HttpHandler {
3838
public HttpResponse execute(HttpRequest req) {
3939
DistributorStatus status = distributor.getStatus();
4040

41-
ImmutableMap<String, Object> report =
42-
ImmutableMap.of(
41+
Map<String, Object> report =
42+
Map.of(
4343
"value",
44-
ImmutableMap.of(
44+
Map.of(
4545
"ready",
4646
status.hasCapacity(),
4747
"message",

java/src/org/openqa/selenium/grid/distributor/httpd/DefaultDistributorConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717

1818
package org.openqa.selenium.grid.distributor.httpd;
1919

20-
import com.google.common.collect.ImmutableMap;
20+
import java.util.Map;
2121
import org.openqa.selenium.grid.config.MapConfig;
2222

2323
class DefaultDistributorConfig extends MapConfig {
2424

2525
DefaultDistributorConfig() {
2626
super(
27-
ImmutableMap.of(
27+
Map.of(
2828
"events",
29-
ImmutableMap.of(
29+
Map.of(
3030
"publish", "tcp://*:4442",
3131
"subscribe", "tcp://*:4443",
3232
"bind", true),
3333
"server",
34-
ImmutableMap.of("port", 5553)));
34+
Map.of("port", 5553)));
3535
}
3636
}

java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@
2828
import static org.openqa.selenium.remote.http.Route.get;
2929

3030
import com.google.auto.service.AutoService;
31-
import com.google.common.collect.ImmutableMap;
32-
import com.google.common.collect.ImmutableSet;
3331
import com.google.common.net.MediaType;
3432
import java.io.Closeable;
3533
import java.io.IOException;
3634
import java.io.UncheckedIOException;
3735
import java.util.Collections;
36+
import java.util.Map;
3837
import java.util.Set;
3938
import java.util.logging.Level;
4039
import java.util.logging.Logger;
@@ -69,7 +68,7 @@ public String getDescription() {
6968

7069
@Override
7170
public Set<Role> getConfigurableRoles() {
72-
return ImmutableSet.of(
71+
return Set.of(
7372
DISTRIBUTOR_ROLE, EVENT_BUS_ROLE, HTTPD_ROLE, SESSION_MAP_ROLE, SESSION_QUEUE_ROLE);
7473
}
7574

@@ -113,9 +112,9 @@ protected Handlers createHandlers(Config config) {
113112
new HttpResponse()
114113
.setContent(
115114
Contents.asJson(
116-
ImmutableMap.of(
115+
Map.of(
117116
"value",
118-
ImmutableMap.of(
117+
Map.of(
119118
"ready",
120119
true,
121120
"message",

java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;
2929

3030
import com.google.common.annotations.VisibleForTesting;
31-
import com.google.common.collect.ImmutableSet;
3231
import java.io.Closeable;
3332
import java.io.UncheckedIOException;
3433
import java.net.URI;
@@ -245,7 +244,7 @@ public static Distributor create(Config config) {
245244
@Override
246245
public boolean isReady() {
247246
try {
248-
return ImmutableSet.of(bus, sessions).parallelStream()
247+
return Set.of(bus, sessions).parallelStream()
249248
.map(HasReadyState::isReady)
250249
.reduce(true, Boolean::logicalAnd);
251250
} catch (RuntimeException e) {

java/src/org/openqa/selenium/grid/distributor/local/LocalGridModel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.openqa.selenium.grid.data.Availability.DRAINING;
2222
import static org.openqa.selenium.grid.data.Availability.UP;
2323

24-
import com.google.common.collect.ImmutableSet;
2524
import java.time.Instant;
2625
import java.util.Collections;
2726
import java.util.HashMap;
@@ -360,7 +359,7 @@ public Set<NodeStatus> getSnapshot() {
360359
Lock readLock = this.lock.readLock();
361360
readLock.lock();
362361
try {
363-
return ImmutableSet.copyOf(nodes);
362+
return Set.copyOf(nodes);
364363
} finally {
365364
readLock.unlock();
366365
}

java/src/org/openqa/selenium/grid/distributor/local/LocalNodeRegistry.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import static org.openqa.selenium.grid.data.Availability.UP;
2323
import static org.openqa.selenium.internal.Debug.getDebugLogLevel;
2424

25-
import com.google.common.collect.ImmutableMap;
26-
import com.google.common.collect.ImmutableSet;
2725
import java.net.URI;
2826
import java.time.Duration;
2927
import java.util.ArrayList;
@@ -306,11 +304,11 @@ public void updateNodeAvailability(URI nodeUri, NodeId id, Availability availabi
306304

307305
@Override
308306
public void runHealthChecks() {
309-
ImmutableMap<NodeId, Runnable> nodeHealthChecks;
307+
Map<NodeId, Runnable> nodeHealthChecks;
310308
Lock readLock = this.lock.readLock();
311309
readLock.lock();
312310
try {
313-
nodeHealthChecks = ImmutableMap.copyOf(allChecks);
311+
nodeHealthChecks = Map.copyOf(allChecks);
314312
} finally {
315313
readLock.unlock();
316314
}
@@ -363,7 +361,7 @@ public Set<NodeStatus> getAvailableNodes() {
363361
return model.getSnapshot().stream()
364362
// Filter nodes are UP and have capacity (available slots)
365363
.filter(node -> UP.equals(node.getAvailability()) && node.hasCapacity())
366-
.collect(ImmutableSet.toImmutableSet());
364+
.collect(Collectors.toUnmodifiableSet());
367365
} finally {
368366
readLock.unlock();
369367
}
@@ -405,7 +403,7 @@ public long getDownNodeCount() {
405403
@Override
406404
public boolean isReady() {
407405
try {
408-
return ImmutableSet.of(bus).parallelStream()
406+
return Set.of(bus).parallelStream()
409407
.map(HasReadyState::isReady)
410408
.reduce(true, Boolean::logicalAnd);
411409
} catch (RuntimeException e) {

java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
package org.openqa.selenium.grid.distributor.selector;
1919

20-
import static com.google.common.collect.ImmutableSet.toImmutableSet;
2120
import static org.openqa.selenium.grid.data.Availability.UP;
2221

2322
import com.google.common.annotations.VisibleForTesting;
2423
import java.util.Comparator;
2524
import java.util.Locale;
2625
import java.util.Set;
26+
import java.util.stream.Collectors;
2727
import org.openqa.selenium.Capabilities;
2828
import org.openqa.selenium.grid.config.Config;
2929
import org.openqa.selenium.grid.data.NodeStatus;
@@ -69,7 +69,7 @@ public Set<SlotId> selectSlot(
6969
.filter(slot -> slot.getSession() == null)
7070
.filter(slot -> slot.isSupporting(capabilities, slotMatcher))
7171
.map(Slot::getId))
72-
.collect(toImmutableSet());
72+
.collect(Collectors.toUnmodifiableSet());
7373
}
7474

7575
@VisibleForTesting

java/src/org/openqa/selenium/grid/distributor/selector/GreedySlotSelector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
package org.openqa.selenium.grid.distributor.selector;
1919

20-
import static com.google.common.collect.ImmutableSet.toImmutableSet;
2120
import static org.openqa.selenium.grid.data.Availability.UP;
2221

2322
import java.util.Comparator;
2423
import java.util.Set;
24+
import java.util.stream.Collectors;
2525
import org.openqa.selenium.Capabilities;
2626
import org.openqa.selenium.grid.config.Config;
2727
import org.openqa.selenium.grid.data.NodeStatus;
@@ -69,6 +69,6 @@ public Set<SlotId> selectSlot(
6969
.filter(slot -> slot.getSession() == null)
7070
.filter(slot -> slot.isSupporting(capabilities, slotMatcher))
7171
.map(Slot::getId))
72-
.collect(toImmutableSet());
72+
.collect(Collectors.toUnmodifiableSet());
7373
}
7474
}

0 commit comments

Comments
 (0)