diff --git a/java/src/org/openqa/selenium/grid/sessionqueue/config/NewSessionQueueFlags.java b/java/src/org/openqa/selenium/grid/sessionqueue/config/NewSessionQueueFlags.java index 13484433c3027..6fd92db6fccea 100644 --- a/java/src/org/openqa/selenium/grid/sessionqueue/config/NewSessionQueueFlags.java +++ b/java/src/org/openqa/selenium/grid/sessionqueue/config/NewSessionQueueFlags.java @@ -86,6 +86,15 @@ public class NewSessionQueueFlags implements HasRoles { @ConfigValue(section = SESSION_QUEUE_SECTION, name = "sessionqueue-batch-size", example = "20") private int batchSize = DEFAULT_BATCH_SIZE; + @Parameter( + names = {"--sessionqueue-implementation"}, + description = "Full classname of the non-default session queue implementation.") + @ConfigValue( + section = SESSION_QUEUE_SECTION, + name = "implementation", + example = "\"org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue\"") + private String sessionQueueImplementation; + @Parameter( names = {"--sessionqueue-backend-url"}, description = diff --git a/java/src/org/openqa/selenium/grid/sessionqueue/httpd/BUILD.bazel b/java/src/org/openqa/selenium/grid/sessionqueue/httpd/BUILD.bazel index 55c443be94687..15ee7884845b7 100644 --- a/java/src/org/openqa/selenium/grid/sessionqueue/httpd/BUILD.bazel +++ b/java/src/org/openqa/selenium/grid/sessionqueue/httpd/BUILD.bazel @@ -7,6 +7,7 @@ java_library( visibility = [ "//java/src/org/openqa/selenium/grid:__pkg__", "//java/test/org/openqa/selenium/grid/router:__pkg__", + "//java/test/org/openqa/selenium/grid/sessionqueue/httpd:__pkg__", ], deps = [ "//java:auto-service", @@ -18,6 +19,7 @@ java_library( "//java/src/org/openqa/selenium/grid/sessionqueue", "//java/src/org/openqa/selenium/grid/sessionqueue/config", "//java/src/org/openqa/selenium/grid/sessionqueue/local", + "//java/src/org/openqa/selenium/grid/sessionqueue/redis", "//java/src/org/openqa/selenium/json", "//java/src/org/openqa/selenium/netty/server", artifact("com.beust:jcommander"), diff --git a/java/test/org/openqa/selenium/grid/sessionqueue/config/BUILD.bazel b/java/test/org/openqa/selenium/grid/sessionqueue/config/BUILD.bazel new file mode 100644 index 0000000000000..37e75fdf98858 --- /dev/null +++ b/java/test/org/openqa/selenium/grid/sessionqueue/config/BUILD.bazel @@ -0,0 +1,15 @@ +load("@rules_jvm_external//:defs.bzl", "artifact") +load("//java:defs.bzl", "JUNIT5_DEPS", "java_test_suite") + +java_test_suite( + name = "SmallTests", + size = "small", + srcs = glob(["*Test.java"]), + deps = [ + "//java/src/org/openqa/selenium/grid/config", + "//java/src/org/openqa/selenium/grid/sessionqueue/config", + artifact("com.beust:jcommander"), + artifact("org.junit.jupiter:junit-jupiter-api"), + artifact("org.assertj:assertj-core"), + ] + JUNIT5_DEPS, +) diff --git a/java/test/org/openqa/selenium/grid/sessionqueue/config/NewSessionQueueFlagsTest.java b/java/test/org/openqa/selenium/grid/sessionqueue/config/NewSessionQueueFlagsTest.java new file mode 100644 index 0000000000000..8391b1b8c4925 --- /dev/null +++ b/java/test/org/openqa/selenium/grid/sessionqueue/config/NewSessionQueueFlagsTest.java @@ -0,0 +1,67 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.openqa.selenium.grid.sessionqueue.config; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; + +import com.beust.jcommander.JCommander; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.grid.config.AnnotatedConfig; +import org.openqa.selenium.grid.config.Config; + +class NewSessionQueueFlagsTest { + + private NewSessionQueueFlags flags; + + @BeforeEach + void setUp() { + flags = new NewSessionQueueFlags(); + } + + @Test + void sessionQueueImplementationFlagIsAccepted() { + String impl = "org.openqa.selenium.grid.sessionqueue.redis.RedisBackedNewSessionQueue"; + + assertThatCode( + () -> + JCommander.newBuilder() + .addObject(flags) + .build() + .parse("--sessionqueue-implementation", impl)) + .doesNotThrowAnyException(); + } + + @Test + void sessionQueueImplementationFlagPopulatesConfig() { + String impl = "org.openqa.selenium.grid.sessionqueue.redis.RedisBackedNewSessionQueue"; + JCommander.newBuilder().addObject(flags).build().parse("--sessionqueue-implementation", impl); + + Config config = new AnnotatedConfig(flags); + + assertThat(config.get("sessionqueue", "implementation")).contains(impl); + } + + @Test + void sessionQueueImplementationIsAbsentWhenFlagNotSet() { + Config config = new AnnotatedConfig(flags); + + assertThat(config.get("sessionqueue", "implementation")).isEmpty(); + } +} diff --git a/java/test/org/openqa/selenium/grid/sessionqueue/httpd/BUILD.bazel b/java/test/org/openqa/selenium/grid/sessionqueue/httpd/BUILD.bazel new file mode 100644 index 0000000000000..007860afb07fc --- /dev/null +++ b/java/test/org/openqa/selenium/grid/sessionqueue/httpd/BUILD.bazel @@ -0,0 +1,18 @@ +load("@rules_jvm_external//:defs.bzl", "artifact") +load("//java:defs.bzl", "JUNIT5_DEPS", "java_test_suite") +load("//java:version.bzl", "TOOLS_JAVA_VERSION") + +java_test_suite( + name = "small-tests", + size = "small", + srcs = glob(["*.java"]), + javacopts = [ + "--release", + TOOLS_JAVA_VERSION, + ], + deps = [ + "//java/src/org/openqa/selenium/grid/sessionqueue/httpd", + artifact("org.assertj:assertj-core"), + artifact("org.junit.jupiter:junit-jupiter-api"), + ] + JUNIT5_DEPS, +) diff --git a/java/test/org/openqa/selenium/grid/sessionqueue/httpd/NewSessionQueueServerTest.java b/java/test/org/openqa/selenium/grid/sessionqueue/httpd/NewSessionQueueServerTest.java new file mode 100644 index 0000000000000..a7044982750d3 --- /dev/null +++ b/java/test/org/openqa/selenium/grid/sessionqueue/httpd/NewSessionQueueServerTest.java @@ -0,0 +1,43 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.openqa.selenium.grid.sessionqueue.httpd; + +import static org.assertj.core.api.Assertions.assertThatCode; + +import org.junit.jupiter.api.Test; + +class NewSessionQueueServerTest { + + // These classes are loaded via Class.forName() at runtime. This test verifies they are bundled + // into the httpd target so that --sessionqueue-implementation works without --ext. + @Test + void localImplementationIsOnClasspath() { + assertThatCode( + () -> Class.forName("org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue")) + .doesNotThrowAnyException(); + } + + @Test + void redisImplementationIsOnClasspath() { + assertThatCode( + () -> + Class.forName( + "org.openqa.selenium.grid.sessionqueue.redis.RedisBackedNewSessionQueue")) + .doesNotThrowAnyException(); + } +}