Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions java/src/org/openqa/selenium/grid/distributor/DrainNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,10 +38,10 @@ class StatusHandler implements HttpHandler {
public HttpResponse execute(HttpRequest req) {
DistributorStatus status = distributor.getStatus();

ImmutableMap<String, Object> report =
ImmutableMap.of(
Map<String, Object> report =
Map.of(
"value",
ImmutableMap.of(
Map.of(
"ready",
status.hasCapacity(),
"message",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,7 +68,7 @@ public String getDescription() {

@Override
public Set<Role> getConfigurableRoles() {
return ImmutableSet.of(
return Set.of(
DISTRIBUTOR_ROLE, EVENT_BUS_ROLE, HTTPD_ROLE, SESSION_MAP_ROLE, SESSION_QUEUE_ROLE);
}

Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -360,7 +359,7 @@ public Set<NodeStatus> getSnapshot() {
Lock readLock = this.lock.readLock();
readLock.lock();
try {
return ImmutableSet.copyOf(nodes);
return Set.copyOf(nodes);
} finally {
readLock.unlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -306,11 +304,11 @@ public void updateNodeAvailability(URI nodeUri, NodeId id, Availability availabi

@Override
public void runHealthChecks() {
ImmutableMap<NodeId, Runnable> nodeHealthChecks;
Map<NodeId, Runnable> nodeHealthChecks;
Lock readLock = this.lock.readLock();
readLock.lock();
try {
nodeHealthChecks = ImmutableMap.copyOf(allChecks);
nodeHealthChecks = Map.copyOf(allChecks);
} finally {
readLock.unlock();
}
Expand Down Expand Up @@ -363,7 +361,7 @@ public Set<NodeStatus> 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();
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,7 +71,11 @@ public Set<SlotId> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,6 +71,9 @@ public Set<SlotId> 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))));
}
}
Loading