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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf;
import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Objects;
import org.openqa.selenium.grid.data.Session;
import org.openqa.selenium.internal.Require;
Expand Down Expand Up @@ -61,7 +61,7 @@ public HttpResponse execute(HttpRequest req) {

sessions.add(session);

return new HttpResponse().setContent(asJson(ImmutableMap.of("value", true)));
return new HttpResponse().setContent(asJson(Map.of("value", true)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf;
import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.openqa.selenium.grid.data.Session;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.SessionId;
Expand Down Expand Up @@ -56,7 +56,7 @@ public HttpResponse execute(HttpRequest req) {
CAPABILITIES.accept(span, session.getCapabilities());
span.setAttribute("session.uri", session.getUri().toString());

return new HttpResponse().setContent(asJson(ImmutableMap.of("value", session)));
return new HttpResponse().setContent(asJson(Map.of("value", session)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@

package org.openqa.selenium.grid.sessionmap.httpd;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.openqa.selenium.grid.config.MapConfig;

class DefaultSessionMapConfig extends MapConfig {

public DefaultSessionMapConfig() {
super(
ImmutableMap.of(
Map.of(
"events",
ImmutableMap.of(
Map.of(
"publish", "tcp://*:4442",
"subscribe", "tcp://*:4443"),
"sessions",
ImmutableMap.of(
Map.of(
"implementation", "org.openqa.selenium.grid.sessionmap.local.LocalSessionMap"),
"server", ImmutableMap.of("port", 5556)));
"server", Map.of("port", 5556)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
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 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 @@ -64,7 +63,7 @@ public String getDescription() {

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

@Override
Expand Down Expand Up @@ -100,9 +99,9 @@ protected Handlers createHandlers(Config config) {
.addHeader("Content-Type", JSON_UTF_8)
.setContent(
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 @@ -23,12 +23,12 @@
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID_EVENT;
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;

import com.google.common.collect.ImmutableMap;
import io.lettuce.core.KeyValue;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
Expand Down Expand Up @@ -139,7 +139,7 @@ public boolean add(Session session) {

span.addEvent("Inserted into the database", attributeMap);
connection.mset(
ImmutableMap.of(
Map.of(
uriKey, uriValue,
stereotypeKey, stereotypeJson,
capabilitiesKey, capabilitiesJson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;
import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.http.HttpHandler;
import org.openqa.selenium.remote.http.HttpRequest;
Expand Down Expand Up @@ -56,14 +56,14 @@ public HttpResponse execute(HttpRequest req) {
if (value != 0) {
response.setContent(
asJson(
ImmutableMap.of(
Map.of(
"value", value,
"message", "Cleared the new session request queue",
"cleared_requests", value)));
} else {
response.setContent(
asJson(
ImmutableMap.of(
Map.of(
"value",
value,
"message",
Expand All @@ -81,7 +81,7 @@ public HttpResponse execute(HttpRequest req) {
.setStatus((HTTP_INTERNAL_ERROR))
.setContent(
asJson(
ImmutableMap.of(
Map.of(
"value",
0,
"message",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.openqa.selenium.grid.sessionqueue.httpd;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.openqa.selenium.grid.config.MapConfig;

class DefaultNewSessionQueueConfig extends MapConfig {

DefaultNewSessionQueueConfig() {
super(ImmutableMap.of("server", ImmutableMap.of("port", 5559)));
super(Map.of("server", Map.of("port", 5559)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
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 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 @@ -65,7 +64,7 @@ public String getDescription() {

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

@Override
Expand Down Expand Up @@ -100,9 +99,9 @@ protected Handlers createHandlers(Config config) {
.addHeader("Content-Type", JSON_UTF_8)
.setContent(
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 @@ -22,13 +22,13 @@
import static org.openqa.selenium.concurrent.ExecutorServices.shutdownGracefully;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.io.Closeable;
import java.time.Duration;
import java.time.Instant;
import java.util.Collections;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -180,7 +180,10 @@ private void timeoutSessions() {
sessionRequest.getRequestId().equals(entry.getKey())))
.filter(entry -> isTimedOut(now, entry.getValue()))
.map(Map.Entry::getKey)
.collect(ImmutableSet.toImmutableSet());
.collect(
Collectors.collectingAndThen(
Collectors.toCollection(LinkedHashSet::new),
set -> Collections.unmodifiableSet(new LinkedHashSet<>(set))));
} finally {
readLock.unlock();
}
Expand Down Expand Up @@ -258,9 +261,9 @@ public HttpResponse addToQueue(SessionRequest request) {
res.setStatus(HTTP_INTERNAL_ERROR)
.setContent(
Contents.asJson(
ImmutableMap.of(
Map.of(
"value",
ImmutableMap.of(
Map.of(
"error", "session not created",
"message", result.left().getMessage(),
"stacktrace", result.left().getStackTrace()))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.MediaType;
import java.util.Map;
import java.util.Set;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.http.Contents;
Expand All @@ -36,18 +35,17 @@ public class CheckContentTypeHeader implements Filter {
.setStatus(HTTP_INTERNAL_ERROR)
.setContent(
Contents.asJson(
ImmutableMap.of(
Map.of(
"value",
ImmutableMap.of(
Map.of(
"error", "unknown error",
"message", "Content-Type header is missing",
"stacktrace", ""))));

private final Set<String> skipChecksOn;

public CheckContentTypeHeader(Set<String> skipChecksOn) {
this.skipChecksOn =
ImmutableSet.copyOf(Require.nonNull("URLs where checks are skipped", skipChecksOn));
this.skipChecksOn = Set.copyOf(Require.nonNull("URLs where checks are skipped", skipChecksOn));
}

@Override
Expand Down Expand Up @@ -81,9 +79,9 @@ private HttpResponse badType(String type) {
.setStatus(HTTP_INTERNAL_ERROR)
.setContent(
Contents.asJson(
ImmutableMap.of(
Map.of(
"value",
ImmutableMap.of(
Map.of(
"error", "unknown error",
"message",
"Content-Type header does not indicate utf-8 encoded json: " + type,
Expand Down
12 changes: 5 additions & 7 deletions java/src/org/openqa/selenium/grid/web/CheckOriginHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
import static org.openqa.selenium.json.Json.JSON_UTF_8;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.http.Contents;
Expand All @@ -37,9 +36,8 @@ public class CheckOriginHeader implements Filter {

public CheckOriginHeader(Collection<String> allowedOriginHosts, Set<String> skipChecksOn) {
Require.nonNull("Allowed origins list", allowedOriginHosts);
allowedHosts = ImmutableSet.copyOf(allowedOriginHosts);
this.skipChecksOn =
ImmutableSet.copyOf(Require.nonNull("URLs where checks are skipped", skipChecksOn));
allowedHosts = Set.copyOf(allowedOriginHosts);
this.skipChecksOn = Set.copyOf(Require.nonNull("URLs where checks are skipped", skipChecksOn));
}

@Override
Expand All @@ -58,9 +56,9 @@ public HttpHandler apply(HttpHandler httpHandler) {
.addHeader("Content-Type", JSON_UTF_8)
.setContent(
Contents.asJson(
ImmutableMap.of(
Map.of(
"value",
ImmutableMap.of(
Map.of(
"error", "unknown error",
"message", "Origin not allowed: " + origin,
"stacktrace", ""))));
Expand Down
11 changes: 8 additions & 3 deletions java/src/org/openqa/selenium/grid/web/JarFileResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

package org.openqa.selenium.grid.web;

import com.google.common.collect.ImmutableSet;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.Set;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import org.openqa.selenium.internal.Require;

Expand Down Expand Up @@ -88,7 +90,7 @@ public boolean isDirectory() {
@Override
public Set<Resource> list() {
if (!isDirectory()) {
return ImmutableSet.of();
return Set.of();
}

String prefix = entryName.endsWith("/") ? entryName : entryName + "/";
Expand All @@ -100,7 +102,10 @@ public Set<Resource> list() {
.filter(e -> !e.getName().equals(prefix))
.filter(e -> e.getName().split("/").length == count)
.map(e -> new JarFileResource(jarFile, e.getName(), prefix))
.collect(ImmutableSet.toImmutableSet());
.collect(
Collectors.collectingAndThen(
Collectors.toCollection(LinkedHashSet::new),
set -> Collections.unmodifiableSet(new LinkedHashSet<>(set))));
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions java/src/org/openqa/selenium/grid/web/MergedResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

package org.openqa.selenium.grid.web;

import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.Set;
import org.openqa.selenium.internal.Require;
Expand Down Expand Up @@ -66,10 +67,9 @@ public boolean isDirectory() {

@Override
public Set<Resource> list() {
ImmutableSet.Builder<Resource> resources = ImmutableSet.builder();
resources.addAll(base.list());
Set<Resource> resources = new LinkedHashSet<>(base.list());
next.ifPresent(res -> resources.addAll(res.list()));
return resources.build();
return Collections.unmodifiableSet(new LinkedHashSet<>(resources));
}

@Override
Expand Down
Loading
Loading