diff --git a/java/src/org/openqa/selenium/grid/distributor/DrainNode.java b/java/src/org/openqa/selenium/grid/distributor/DrainNode.java index 7bf6bafa0c24c..782d55d6874d7 100644 --- a/java/src/org/openqa/selenium/grid/distributor/DrainNode.java +++ b/java/src/org/openqa/selenium/grid/distributor/DrainNode.java @@ -19,8 +19,8 @@ import static org.openqa.selenium.remote.http.Contents.asJson; -import com.google.common.collect.ImmutableMap; import java.io.UncheckedIOException; +import java.util.Map; import java.util.Objects; import org.openqa.selenium.grid.data.NodeId; import org.openqa.selenium.remote.http.HttpHandler; @@ -45,12 +45,11 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException { if (value) { response.setContent( asJson( - ImmutableMap.of( - "value", value, "message", "Node status was successfully set to draining."))); + Map.of("value", value, "message", "Node status was successfully set to draining."))); } else { response.setContent( asJson( - ImmutableMap.of( + Map.of( "value", value, "message", diff --git a/java/src/org/openqa/selenium/grid/distributor/GetDistributorStatus.java b/java/src/org/openqa/selenium/grid/distributor/GetDistributorStatus.java index 15c46cbbf7288..9586bf1a71787 100644 --- a/java/src/org/openqa/selenium/grid/distributor/GetDistributorStatus.java +++ b/java/src/org/openqa/selenium/grid/distributor/GetDistributorStatus.java @@ -19,7 +19,7 @@ import static org.openqa.selenium.remote.http.Contents.asJson; -import com.google.common.collect.ImmutableMap; +import java.util.Map; import org.openqa.selenium.grid.data.DistributorStatus; import org.openqa.selenium.internal.Require; import org.openqa.selenium.remote.http.HttpHandler; @@ -38,6 +38,6 @@ class GetDistributorStatus implements HttpHandler { public HttpResponse execute(HttpRequest req) { DistributorStatus status = distributor.getStatus(); - return new HttpResponse().setContent(asJson(ImmutableMap.of("value", status))); + return new HttpResponse().setContent(asJson(Map.of("value", status))); } } diff --git a/java/src/org/openqa/selenium/grid/distributor/StatusHandler.java b/java/src/org/openqa/selenium/grid/distributor/StatusHandler.java index 9e90095e3b725..00f075296e75a 100644 --- a/java/src/org/openqa/selenium/grid/distributor/StatusHandler.java +++ b/java/src/org/openqa/selenium/grid/distributor/StatusHandler.java @@ -19,7 +19,7 @@ import static org.openqa.selenium.remote.http.Contents.asJson; -import com.google.common.collect.ImmutableMap; +import java.util.Map; import org.openqa.selenium.grid.data.DistributorStatus; import org.openqa.selenium.internal.Require; import org.openqa.selenium.remote.http.HttpHandler; @@ -38,10 +38,10 @@ class StatusHandler implements HttpHandler { public HttpResponse execute(HttpRequest req) { DistributorStatus status = distributor.getStatus(); - ImmutableMap report = - ImmutableMap.of( + Map report = + Map.of( "value", - ImmutableMap.of( + Map.of( "ready", status.hasCapacity(), "message", diff --git a/java/src/org/openqa/selenium/grid/distributor/httpd/DefaultDistributorConfig.java b/java/src/org/openqa/selenium/grid/distributor/httpd/DefaultDistributorConfig.java index ccf2609b64b2e..65e10ef215467 100644 --- a/java/src/org/openqa/selenium/grid/distributor/httpd/DefaultDistributorConfig.java +++ b/java/src/org/openqa/selenium/grid/distributor/httpd/DefaultDistributorConfig.java @@ -17,20 +17,20 @@ package org.openqa.selenium.grid.distributor.httpd; -import com.google.common.collect.ImmutableMap; +import java.util.Map; import org.openqa.selenium.grid.config.MapConfig; class DefaultDistributorConfig extends MapConfig { DefaultDistributorConfig() { super( - ImmutableMap.of( + Map.of( "events", - ImmutableMap.of( + Map.of( "publish", "tcp://*:4442", "subscribe", "tcp://*:4443", "bind", true), "server", - ImmutableMap.of("port", 5553))); + Map.of("port", 5553))); } } diff --git a/java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java b/java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java index b48fc8c73131a..7ed444121aa0e 100644 --- a/java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java +++ b/java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java @@ -28,13 +28,12 @@ import static org.openqa.selenium.remote.http.Route.get; import com.google.auto.service.AutoService; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.common.net.MediaType; import java.io.Closeable; import java.io.IOException; import java.io.UncheckedIOException; import java.util.Collections; +import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -69,7 +68,7 @@ public String getDescription() { @Override public Set getConfigurableRoles() { - return ImmutableSet.of( + return Set.of( DISTRIBUTOR_ROLE, EVENT_BUS_ROLE, HTTPD_ROLE, SESSION_MAP_ROLE, SESSION_QUEUE_ROLE); } @@ -113,9 +112,9 @@ protected Handlers createHandlers(Config config) { new HttpResponse() .setContent( Contents.asJson( - ImmutableMap.of( + Map.of( "value", - ImmutableMap.of( + Map.of( "ready", true, "message", diff --git a/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java b/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java index 609a8a27a55fb..414cc4516e1ee 100644 --- a/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java +++ b/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java @@ -28,7 +28,6 @@ import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableSet; import java.io.Closeable; import java.io.UncheckedIOException; import java.net.URI; @@ -245,7 +244,7 @@ public static Distributor create(Config config) { @Override public boolean isReady() { try { - return ImmutableSet.of(bus, sessions).parallelStream() + return Set.of(bus, sessions).parallelStream() .map(HasReadyState::isReady) .reduce(true, Boolean::logicalAnd); } catch (RuntimeException e) { diff --git a/java/src/org/openqa/selenium/grid/distributor/local/LocalGridModel.java b/java/src/org/openqa/selenium/grid/distributor/local/LocalGridModel.java index 1d6483faf6633..0ebc760571c0b 100644 --- a/java/src/org/openqa/selenium/grid/distributor/local/LocalGridModel.java +++ b/java/src/org/openqa/selenium/grid/distributor/local/LocalGridModel.java @@ -21,7 +21,6 @@ import static org.openqa.selenium.grid.data.Availability.DRAINING; import static org.openqa.selenium.grid.data.Availability.UP; -import com.google.common.collect.ImmutableSet; import java.time.Instant; import java.util.Collections; import java.util.HashMap; @@ -360,7 +359,7 @@ public Set getSnapshot() { Lock readLock = this.lock.readLock(); readLock.lock(); try { - return ImmutableSet.copyOf(nodes); + return Set.copyOf(nodes); } finally { readLock.unlock(); } diff --git a/java/src/org/openqa/selenium/grid/distributor/local/LocalNodeRegistry.java b/java/src/org/openqa/selenium/grid/distributor/local/LocalNodeRegistry.java index 097657a3cc384..2a6f1b32e922d 100644 --- a/java/src/org/openqa/selenium/grid/distributor/local/LocalNodeRegistry.java +++ b/java/src/org/openqa/selenium/grid/distributor/local/LocalNodeRegistry.java @@ -22,8 +22,6 @@ import static org.openqa.selenium.grid.data.Availability.UP; import static org.openqa.selenium.internal.Debug.getDebugLogLevel; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import java.net.URI; import java.time.Duration; import java.util.ArrayList; @@ -306,11 +304,11 @@ public void updateNodeAvailability(URI nodeUri, NodeId id, Availability availabi @Override public void runHealthChecks() { - ImmutableMap nodeHealthChecks; + Map nodeHealthChecks; Lock readLock = this.lock.readLock(); readLock.lock(); try { - nodeHealthChecks = ImmutableMap.copyOf(allChecks); + nodeHealthChecks = Map.copyOf(allChecks); } finally { readLock.unlock(); } @@ -363,7 +361,7 @@ public Set getAvailableNodes() { return model.getSnapshot().stream() // Filter nodes are UP and have capacity (available slots) .filter(node -> UP.equals(node.getAvailability()) && node.hasCapacity()) - .collect(ImmutableSet.toImmutableSet()); + .collect(Collectors.toUnmodifiableSet()); } finally { readLock.unlock(); } @@ -405,7 +403,7 @@ public long getDownNodeCount() { @Override public boolean isReady() { try { - return ImmutableSet.of(bus).parallelStream() + return Set.of(bus).parallelStream() .map(HasReadyState::isReady) .reduce(true, Boolean::logicalAnd); } catch (RuntimeException e) { diff --git a/java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java b/java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java index c015415f61c7c..5901f1f66026c 100644 --- a/java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java +++ b/java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java @@ -17,13 +17,15 @@ package org.openqa.selenium.grid.distributor.selector; -import static com.google.common.collect.ImmutableSet.toImmutableSet; import static org.openqa.selenium.grid.data.Availability.UP; import com.google.common.annotations.VisibleForTesting; +import java.util.Collections; import java.util.Comparator; +import java.util.LinkedHashSet; import java.util.Locale; import java.util.Set; +import java.util.stream.Collectors; import org.openqa.selenium.Capabilities; import org.openqa.selenium.grid.config.Config; import org.openqa.selenium.grid.data.NodeStatus; @@ -69,7 +71,11 @@ public Set selectSlot( .filter(slot -> slot.getSession() == null) .filter(slot -> slot.isSupporting(capabilities, slotMatcher)) .map(Slot::getId)) - .collect(toImmutableSet()); + // Any collector used here needs to maintain the insertion order + .collect( + Collectors.collectingAndThen( + Collectors.toCollection(LinkedHashSet::new), + set -> Collections.unmodifiableSet(new LinkedHashSet<>(set)))); } @VisibleForTesting diff --git a/java/src/org/openqa/selenium/grid/distributor/selector/GreedySlotSelector.java b/java/src/org/openqa/selenium/grid/distributor/selector/GreedySlotSelector.java index 668d0742d827f..49a14fc748141 100644 --- a/java/src/org/openqa/selenium/grid/distributor/selector/GreedySlotSelector.java +++ b/java/src/org/openqa/selenium/grid/distributor/selector/GreedySlotSelector.java @@ -17,11 +17,13 @@ package org.openqa.selenium.grid.distributor.selector; -import static com.google.common.collect.ImmutableSet.toImmutableSet; import static org.openqa.selenium.grid.data.Availability.UP; +import java.util.Collections; import java.util.Comparator; +import java.util.LinkedHashSet; import java.util.Set; +import java.util.stream.Collectors; import org.openqa.selenium.Capabilities; import org.openqa.selenium.grid.config.Config; import org.openqa.selenium.grid.data.NodeStatus; @@ -69,6 +71,9 @@ public Set selectSlot( .filter(slot -> slot.getSession() == null) .filter(slot -> slot.isSupporting(capabilities, slotMatcher)) .map(Slot::getId)) - .collect(toImmutableSet()); + .collect( + Collectors.collectingAndThen( + Collectors.toCollection(LinkedHashSet::new), + set -> Collections.unmodifiableSet(new LinkedHashSet<>(set)))); } }