How to use MemoizedConfig class of org.openqa.selenium.grid.config package

Best Selenium code snippet using org.openqa.selenium.grid.config.MemoizedConfig

Source:DeploymentTypes.java Github

copy

Full Screen

...21import org.openqa.selenium.grid.commands.Standalone;22import org.openqa.selenium.grid.config.CompoundConfig;23import org.openqa.selenium.grid.config.Config;24import org.openqa.selenium.grid.config.MapConfig;25import org.openqa.selenium.grid.config.MemoizedConfig;26import org.openqa.selenium.grid.config.TomlConfig;27import org.openqa.selenium.grid.distributor.httpd.DistributorServer;28import org.openqa.selenium.grid.node.httpd.NodeServer;29import org.openqa.selenium.grid.router.httpd.RouterServer;30import org.openqa.selenium.grid.server.Server;31import org.openqa.selenium.grid.sessionmap.httpd.SessionMapServer;32import org.openqa.selenium.grid.sessionqueue.httpd.NewSessionQueueServer;33import org.openqa.selenium.grid.web.Values;34import org.openqa.selenium.json.Json;35import org.openqa.selenium.json.JsonOutput;36import org.openqa.selenium.net.PortProber;37import org.openqa.selenium.remote.http.HttpClient;38import org.openqa.selenium.remote.http.HttpRequest;39import org.openqa.selenium.remote.http.HttpResponse;40import org.openqa.selenium.support.ui.FluentWait;41import org.openqa.selenium.testing.Safely;42import org.openqa.selenium.testing.TearDownFixture;43import java.io.IOException;44import java.io.StringReader;45import java.io.UncheckedIOException;46import java.net.ConnectException;47import java.time.Duration;48import java.util.Arrays;49import java.util.List;50import java.util.Map;51import static org.openqa.selenium.json.Json.MAP_TYPE;52import static org.openqa.selenium.remote.http.HttpMethod.GET;53public enum DeploymentTypes {54 STANDALONE {55 @Override56 public Deployment start(Capabilities capabilities, Config additionalConfig) {57 StringBuilder rawCaps = new StringBuilder();58 try (JsonOutput out = new Json().newOutput(rawCaps)) {59 out.setPrettyPrint(false).write(capabilities);60 }61 String[] rawConfig = new String[]{62 "[network]",63 "relax-checks = true",64 "",65 "[server]",66 "registration-secret = \"provolone\"",67 "",68 "[sessionqueue]",69 "session-request-timeout = 100",70 "session-retry-interval = 1"71 };72 Config config = new MemoizedConfig(73 new CompoundConfig(74 additionalConfig,75 new TomlConfig(new StringReader(String.join("\n", rawConfig)))));76 Server<?> server = new Standalone().asServer(new CompoundConfig(setRandomPort(), config)).start();77 waitUntilReady(server, Duration.ofSeconds(5));78 return new Deployment(server, server::stop);79 }80 },81 HUB_AND_NODE {82 @Override83 public Deployment start(Capabilities capabilities, Config additionalConfig) {84 StringBuilder rawCaps = new StringBuilder();85 try (JsonOutput out = new Json().newOutput(rawCaps)) {86 out.setPrettyPrint(false).write(capabilities);87 }88 int publish = PortProber.findFreePort();89 int subscribe = PortProber.findFreePort();90 String[] rawConfig = new String[] {91 "[events]",92 "publish = \"tcp://localhost:" + publish + "\"",93 "subscribe = \"tcp://localhost:" + subscribe + "\"",94 "",95 "[network]",96 "relax-checks = true",97 "",98 "[server]",99 "registration-secret = \"feta\"",100 "",101 "[sessionqueue]",102 "session-request-timeout = 100",103 "session-retry-interval = 1"104 };105 Config baseConfig = new MemoizedConfig(106 new CompoundConfig(107 additionalConfig,108 new TomlConfig(new StringReader(String.join("\n", rawConfig)))));109 Config hubConfig = new MemoizedConfig(110 new CompoundConfig(111 setRandomPort(),112 new MapConfig(Map.of("events", Map.of("bind", true))),113 baseConfig));114 Server<?> hub = new Hub().asServer(hubConfig).start();115 Config nodeConfig = new MemoizedConfig(116 new CompoundConfig(117 setRandomPort(),118 baseConfig));119 Server<?> node = new NodeServer().asServer(nodeConfig).start();120 waitUntilReady(node, Duration.ofSeconds(5));121 waitUntilReady(hub, Duration.ofSeconds(5));122 return new Deployment(hub, hub::stop, node::stop);123 }124 },125 DISTRIBUTED {126 @Override127 public Deployment start(Capabilities capabilities, Config additionalConfig) {128 StringBuilder rawCaps = new StringBuilder();129 try (JsonOutput out = new Json().newOutput(rawCaps)) {130 out.setPrettyPrint(false).write(capabilities);131 }132 int publish = PortProber.findFreePort();133 int subscribe = PortProber.findFreePort();134 String[] rawConfig = new String[] {135 "[events]",136 "publish = \"tcp://localhost:" + publish + "\"",137 "subscribe = \"tcp://localhost:" + subscribe + "\"",138 "bind = false",139 "",140 "[network]",141 "relax-checks = true",142 "",143 "[server]",144 "",145 "registration-secret = \"colby\"",146 "",147 "[sessionqueue]",148 "session-request-timeout = 100",149 "session-retry-interval = 1"150 };151 Config sharedConfig = new MemoizedConfig(152 new CompoundConfig(153 additionalConfig,154 new TomlConfig(new StringReader(String.join("\n", rawConfig)))));155 Server<?> eventServer = new EventBusCommand()156 .asServer(new MemoizedConfig(new CompoundConfig(157 new TomlConfig(new StringReader(String.join("\n", new String[] {158 "[events]",159 "publish = \"tcp://localhost:" + publish + "\"",160 "subscribe = \"tcp://localhost:" + subscribe + "\"",161 "bind = true"}))),162 setRandomPort(),163 sharedConfig)))164 .start();165 waitUntilReady(eventServer, Duration.ofSeconds(5));166 Server<?> newSessionQueueServer = new NewSessionQueueServer()167 .asServer(new MemoizedConfig(new CompoundConfig(setRandomPort(), sharedConfig))).start();168 waitUntilReady(newSessionQueueServer, Duration.ofSeconds(5));169 Config newSessionQueueServerConfig = new TomlConfig(new StringReader(String.join(170 "\n",171 new String[] {172 "[sessionqueue]",173 "hostname = \"localhost\"",174 "port = " + newSessionQueueServer.getUrl().getPort()175 }176 )));177 Server<?> sessionMapServer = new SessionMapServer()178 .asServer(new MemoizedConfig(new CompoundConfig(setRandomPort(), sharedConfig))).start();179 Config sessionMapConfig = new TomlConfig(new StringReader(String.join(180 "\n",181 new String[] {182 "[sessions]",183 "hostname = \"localhost\"",184 "port = " + sessionMapServer.getUrl().getPort()185 }186 )));187 Server<?> distributorServer = new DistributorServer()188 .asServer(new MemoizedConfig(new CompoundConfig(189 setRandomPort(),190 sessionMapConfig,191 newSessionQueueServerConfig,192 sharedConfig)))193 .start();194 Config distributorConfig = new TomlConfig(new StringReader(String.join(195 "\n",196 new String[] {197 "[distributor]",198 "hostname = \"localhost\"",199 "port = " + distributorServer.getUrl().getPort()200 }201 )));202 Server<?> router = new RouterServer()203 .asServer(new MemoizedConfig(new CompoundConfig(204 setRandomPort(),205 sessionMapConfig,206 distributorConfig,207 newSessionQueueServerConfig,208 sharedConfig)))209 .start();210 Server<?> nodeServer = new NodeServer()211 .asServer(new MemoizedConfig(new CompoundConfig(212 setRandomPort(),213 sharedConfig,214 sessionMapConfig,215 distributorConfig,216 newSessionQueueServerConfig)))217 .start();218 waitUntilReady(nodeServer, Duration.ofSeconds(5));219 waitUntilReady(router, Duration.ofSeconds(5));220 return new Deployment(221 router,222 router::stop,223 nodeServer::stop,224 distributorServer::stop,225 sessionMapServer::stop,...

Full Screen

Full Screen

Source:NodeServer.java Github

copy

Full Screen

...25import org.openqa.selenium.events.EventBus;26import org.openqa.selenium.grid.TemplateGridServerCommand;27import org.openqa.selenium.grid.config.CompoundConfig;28import org.openqa.selenium.grid.config.Config;29import org.openqa.selenium.grid.config.MemoizedConfig;30import org.openqa.selenium.grid.config.Role;31import org.openqa.selenium.grid.data.NodeAddedEvent;32import org.openqa.selenium.grid.data.NodeDrainComplete;33import org.openqa.selenium.grid.data.NodeStatusEvent;34import org.openqa.selenium.grid.log.LoggingOptions;35import org.openqa.selenium.grid.node.HealthCheck;36import org.openqa.selenium.grid.node.Node;37import org.openqa.selenium.grid.node.ProxyNodeCdp;38import org.openqa.selenium.grid.node.config.NodeOptions;39import org.openqa.selenium.grid.server.BaseServerOptions;40import org.openqa.selenium.grid.server.EventBusOptions;41import org.openqa.selenium.grid.server.NetworkOptions;42import org.openqa.selenium.grid.server.Server;43import org.openqa.selenium.internal.Require;44import org.openqa.selenium.netty.server.NettyServer;45import org.openqa.selenium.remote.http.Contents;46import org.openqa.selenium.remote.http.HttpClient;47import org.openqa.selenium.remote.http.HttpHandler;48import org.openqa.selenium.remote.http.HttpResponse;49import org.openqa.selenium.remote.http.Route;50import org.openqa.selenium.remote.tracing.Tracer;51import java.time.Duration;52import java.time.temporal.ChronoUnit;53import java.util.Collections;54import java.util.Set;55import java.util.concurrent.Executors;56import java.util.logging.Logger;57import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;58import static java.net.HttpURLConnection.HTTP_NO_CONTENT;59import static org.openqa.selenium.grid.config.StandardGridRoles.EVENT_BUS_ROLE;60import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE;61import static org.openqa.selenium.grid.config.StandardGridRoles.NODE_ROLE;62import static org.openqa.selenium.grid.data.Availability.DOWN;63import static org.openqa.selenium.remote.http.Route.get;64@AutoService(CliCommand.class)65public class NodeServer extends TemplateGridServerCommand {66 private static final Logger LOG = Logger.getLogger(NodeServer.class.getName());67 private Node node;68 private EventBus bus;69 @Override70 public String getName() {71 return "node";72 }73 @Override74 public String getDescription() {75 return "Adds this server as a node in the selenium grid.";76 }77 @Override78 public Set<Role> getConfigurableRoles() {79 return ImmutableSet.of(EVENT_BUS_ROLE, HTTPD_ROLE, NODE_ROLE);80 }81 @Override82 public Set<Object> getFlagObjects() {83 return Collections.emptySet();84 }85 @Override86 protected String getSystemPropertiesConfigPrefix() {87 return "node";88 }89 @Override90 protected Config getDefaultConfig() {91 return new DefaultNodeConfig();92 }93 @Override94 protected Handlers createHandlers(Config config) {95 LoggingOptions loggingOptions = new LoggingOptions(config);96 Tracer tracer = loggingOptions.getTracer();97 EventBusOptions events = new EventBusOptions(config);98 this.bus = events.getEventBus();99 NetworkOptions networkOptions = new NetworkOptions(config);100 HttpClient.Factory clientFactory = networkOptions.getHttpClientFactory(tracer);101 BaseServerOptions serverOptions = new BaseServerOptions(config);102 LOG.info("Reporting self as: " + serverOptions.getExternalUri());103 NodeOptions nodeOptions = new NodeOptions(config);104 this.node = nodeOptions.getNode();105 HttpHandler readinessCheck = req -> {106 if (node.getStatus().hasCapacity()) {107 return new HttpResponse()108 .setStatus(HTTP_NO_CONTENT);109 }110 return new HttpResponse()111 .setStatus(HTTP_INTERNAL_ERROR)112 .setHeader("Content-Type", MediaType.PLAIN_TEXT_UTF_8.toString())113 .setContent(Contents.utf8String("No capacity available"));114 };115 bus.addListener(NodeAddedEvent.listener(nodeId -> {116 if (node.getId().equals(nodeId)) {117 LOG.info("Node has been added");118 }119 }));120 bus.addListener(NodeDrainComplete.listener(nodeId -> {121 if (!node.getId().equals(nodeId)) {122 return;123 }124 // Wait a beat before shutting down so the final response from the125 // node can escape.126 new Thread(127 () -> {128 try {129 Thread.sleep(1000);130 } catch (InterruptedException e) {131 // Swallow, the next thing we're doing is shutting down132 }133 LOG.info("Shutting down");134 System.exit(0);135 },136 "Node shutdown: " + nodeId)137 .start();138 }));139 Route httpHandler = Route.combine(140 node,141 get("/readyz").to(() -> readinessCheck));142 return new Handlers(httpHandler, new ProxyNodeCdp(clientFactory, node));143 }144 @Override145 public Server<?> asServer(Config initialConfig) {146 Require.nonNull("Config", initialConfig);147 Config config = new MemoizedConfig(new CompoundConfig(initialConfig, getDefaultConfig()));148 Handlers handler = createHandlers(config);149 return new NettyServer(150 new BaseServerOptions(config),151 handler.httpHandler,152 handler.websocketHandler) {153 @Override154 public NettyServer start() {155 super.start();156 // Unlimited attempts, initial 5 seconds interval, backoff rate of 1.0005, max interval of 5 minutes157 RetryPolicy<Object> registrationPolicy = new RetryPolicy<>()158 .withMaxAttempts(-1)159 .handleResultIf(result -> true)160 .withBackoff(Duration.ofSeconds(5).getSeconds(), Duration.ofMinutes(5).getSeconds(), ChronoUnit.SECONDS, 1.0005);161 LOG.info("Starting registration process for node id " + node.getId());...

Full Screen

Full Screen

Source:NettyAppServer.java Github

copy

Full Screen

...18import com.google.common.collect.ImmutableMap;19import org.openqa.selenium.grid.config.CompoundConfig;20import org.openqa.selenium.grid.config.Config;21import org.openqa.selenium.grid.config.MapConfig;22import org.openqa.selenium.grid.config.MemoizedConfig;23import org.openqa.selenium.grid.server.BaseServerOptions;24import org.openqa.selenium.grid.server.Server;25import org.openqa.selenium.internal.Require;26import org.openqa.selenium.io.TemporaryFilesystem;27import org.openqa.selenium.json.Json;28import org.openqa.selenium.net.PortProber;29import org.openqa.selenium.netty.server.NettyServer;30import org.openqa.selenium.remote.http.Contents;31import org.openqa.selenium.remote.http.HttpClient;32import org.openqa.selenium.remote.http.HttpHandler;33import org.openqa.selenium.remote.http.HttpMethod;34import org.openqa.selenium.remote.http.HttpRequest;35import org.openqa.selenium.remote.http.HttpResponse;36import java.io.File;37import java.io.IOException;38import java.io.UncheckedIOException;39import java.net.MalformedURLException;40import java.net.URL;41import static com.google.common.net.HttpHeaders.CONTENT_TYPE;42import static java.nio.charset.StandardCharsets.UTF_8;43import static java.util.Collections.singletonMap;44import static org.openqa.selenium.json.Json.JSON_UTF_8;45import static org.openqa.selenium.remote.http.Contents.bytes;46import static org.openqa.selenium.remote.http.Contents.string;47public class NettyAppServer implements AppServer {48 private final static Config sslConfig = new MapConfig(49 singletonMap("server", singletonMap("https-self-signed", true)));50 private final Server<?> server;51 private final Server<?> secure;52 public NettyAppServer() {53 Config config = createDefaultConfig();54 BaseServerOptions options = new BaseServerOptions(config);55 File tempDir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("generated", "pages");56 HttpHandler handler = new HandlersForTests(57 options.getHostname().orElse("localhost"),58 options.getPort(),59 tempDir.toPath());60 server = new NettyServer(options, handler);61 Config secureConfig = new CompoundConfig(sslConfig, createDefaultConfig());62 BaseServerOptions secureOptions = new BaseServerOptions(secureConfig);63 HttpHandler secureHandler = new HandlersForTests(64 secureOptions.getHostname().orElse("localhost"),65 secureOptions.getPort(),66 tempDir.toPath());67 secure = new NettyServer(secureOptions, secureHandler);68 }69 public NettyAppServer(HttpHandler handler) {70 this(71 createDefaultConfig(),72 Require.nonNull("Handler", handler));73 }74 private NettyAppServer(Config config, HttpHandler handler) {75 Require.nonNull("Config", config);76 Require.nonNull("Handler", handler);77 server = new NettyServer(new BaseServerOptions(new MemoizedConfig(config)), handler);78 secure = null;79 }80 private static Config createDefaultConfig() {81 return new MemoizedConfig(new MapConfig(82 singletonMap("server", singletonMap("port", PortProber.findFreePort()))));83 }84 @Override85 public void start() {86 server.start();87 if (secure != null) {88 secure.start();89 }90 }91 @Override92 public void stop() {93 server.stop();94 if (secure != null) {95 secure.stop();96 }97 }98 @Override99 public String whereIs(String relativeUrl) {100 return createUrl(server, "http", getHostName(), relativeUrl);101 }102 @Override103 public String whereElseIs(String relativeUrl) {104 return createUrl(server, "http", getAlternateHostName(), relativeUrl);105 }106 @Override107 public String whereIsSecure(String relativeUrl) {108 if (secure == null) {109 throw new IllegalStateException("Server not configured to return HTTPS url");110 }111 return createUrl(secure, "https", getHostName(), relativeUrl);112 }113 @Override114 public String whereIsWithCredentials(String relativeUrl, String user, String password) {115 return String.format(116 "http://%s:%s@%s:%d/%s",117 user,118 password,119 getHostName(),120 server.getUrl().getPort(),121 relativeUrl);122 }123 private String createUrl(Server<?> server, String protocol, String hostName, String relativeUrl) {124 if (!relativeUrl.startsWith("/")) {125 relativeUrl = "/" + relativeUrl;126 }127 try {128 return new URL(129 protocol,130 hostName,131 server.getUrl().getPort(),132 relativeUrl133 ).toString();134 } catch (MalformedURLException e) {135 throw new UncheckedIOException(e);136 }137 }138 @Override139 public String create(Page page) {140 try (HttpClient client = HttpClient.Factory.createDefault().createClient(new URL(whereIs("/")))) {141 HttpRequest request = new HttpRequest(HttpMethod.POST, "/common/createPage");142 request.setHeader(CONTENT_TYPE, JSON_UTF_8);143 request.setContent(Contents.asJson(ImmutableMap.of("content", page.toString())));144 HttpResponse response = client.execute(request);145 return string(response);146 } catch (IOException ex) {147 throw new RuntimeException(ex);148 }149 }150 @Override151 public String getHostName() {152 return AppServer.detectHostname();153 }154 @Override155 public String getAlternateHostName() {156 return AppServer.detectAlternateHostname();157 }158 public static void main(String[] args) {159 MemoizedConfig config = new MemoizedConfig(new MapConfig(singletonMap("server", singletonMap("port", 2310))));160 BaseServerOptions options = new BaseServerOptions(config);161 HttpHandler handler = new HandlersForTests(162 options.getHostname().orElse("localhost"),163 options.getPort(),164 TemporaryFilesystem.getDefaultTmpFS().createTempDir("netty", "server").toPath());165 NettyAppServer server = new NettyAppServer(166 config,167 handler);168 server.start();169 System.out.printf("Server started. Root URL: %s%n", server.whereIs("/"));170 }171}...

Full Screen

Full Screen

Source:EventBusCommand.java Github

copy

Full Screen

...27import org.openqa.selenium.grid.TemplateGridCommand;28import org.openqa.selenium.grid.config.CompoundConfig;29import org.openqa.selenium.grid.config.Config;30import org.openqa.selenium.grid.config.MapConfig;31import org.openqa.selenium.grid.config.MemoizedConfig;32import org.openqa.selenium.grid.config.Role;33import org.openqa.selenium.grid.server.BaseServerOptions;34import org.openqa.selenium.grid.server.EventBusOptions;35import org.openqa.selenium.grid.server.Server;36import org.openqa.selenium.internal.Require;37import org.openqa.selenium.netty.server.NettyServer;38import org.openqa.selenium.remote.http.HttpResponse;39import org.openqa.selenium.remote.http.Route;40import java.util.Collections;41import java.util.Set;42import java.util.concurrent.CountDownLatch;43import java.util.concurrent.TimeUnit;44import java.util.logging.Logger;45import static java.net.HttpURLConnection.HTTP_NO_CONTENT;46import static org.openqa.selenium.grid.config.StandardGridRoles.EVENT_BUS_ROLE;47import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE;48import static org.openqa.selenium.json.Json.JSON_UTF_8;49import static org.openqa.selenium.remote.http.Contents.asJson;50@AutoService(CliCommand.class)51public class EventBusCommand extends TemplateGridCommand {52 private static final Logger LOG = Logger.getLogger(EventBusCommand.class.getName());53 @Override54 public String getName() {55 return "event-bus";56 }57 @Override58 public String getDescription() {59 return "Standalone instance of the event bus.";60 }61 @Override62 public Set<Role> getConfigurableRoles() {63 return ImmutableSet.of(EVENT_BUS_ROLE, HTTPD_ROLE);64 }65 @Override66 public boolean isShown() {67 return false;68 }69 @Override70 public Set<Object> getFlagObjects() {71 return Collections.emptySet();72 }73 @Override74 protected String getSystemPropertiesConfigPrefix() {75 return "selenium";76 }77 @Override78 protected Config getDefaultConfig() {79 return new MapConfig(ImmutableMap.of(80 "events", ImmutableMap.of(81 "bind", true,82 "publish", "tcp://*:4442",83 "subscribe", "tcp://*:4443"),84 "server", ImmutableMap.of(85 "port", 5557)));86 }87 public Server<?> asServer(Config initialConfig) {88 Require.nonNull("Config", initialConfig);89 Config config = new MemoizedConfig(new CompoundConfig(initialConfig, getDefaultConfig()));90 EventBusOptions events = new EventBusOptions(config);91 EventBus bus = events.getEventBus();92 BaseServerOptions serverOptions = new BaseServerOptions(config);93 return new NettyServer(94 serverOptions,95 Route.combine(96 Route.get("/status").to(() -> req -> {97 CountDownLatch latch = new CountDownLatch(1);98 EventName healthCheck = new EventName("healthcheck");99 bus.addListener(new EventListener<>(healthCheck, Object.class, obj -> latch.countDown()));100 bus.fire(new Event(healthCheck, "ping"));101 try {102 if (latch.await(5, TimeUnit.SECONDS)) {103 return httpResponse(true, "Event bus running");...

Full Screen

Full Screen

Source:TemplateGridCommand.java Github

copy

Full Screen

...26import org.openqa.selenium.grid.config.Config;27import org.openqa.selenium.grid.config.ConfigFlags;28import org.openqa.selenium.grid.config.EnvConfig;29import org.openqa.selenium.grid.config.HasRoles;30import org.openqa.selenium.grid.config.MemoizedConfig;31import org.openqa.selenium.grid.log.LoggingOptions;32import org.openqa.selenium.grid.server.HelpFlags;33import java.io.PrintStream;34import java.util.LinkedHashSet;35import java.util.ServiceLoader;36import java.util.Set;37import java.util.stream.StreamSupport;38public abstract class TemplateGridCommand implements CliCommand {39 @Override40 public final Executable configure(PrintStream out, PrintStream err, String... args) {41 HelpFlags helpFlags = new HelpFlags();42 ConfigFlags configFlags = new ConfigFlags();43 Set<Object> allFlags = new LinkedHashSet<>();44 allFlags.add(helpFlags);45 allFlags.add(configFlags);46 StreamSupport.stream(ServiceLoader.load(HasRoles.class).spliterator(), true)47 .filter(flags -> !Sets.intersection(getConfigurableRoles(), flags.getRoles()).isEmpty())48 .forEach(allFlags::add);49 allFlags.addAll(getFlagObjects());50 JCommander.Builder builder = JCommander.newBuilder().programName(getName());51 allFlags.forEach(builder::addObject);52 JCommander commander = builder.build();53 commander.setConsole(new DefaultConsole(out));54 return () -> {55 try {56 commander.parse(args);57 } catch (ParameterException e) {58 err.println(e.getMessage());59 commander.usage();60 return;61 }62 if (helpFlags.displayHelp(commander, out)) {63 return;64 }65 Set<Config> allConfigs = new LinkedHashSet<>();66 allConfigs.add(new EnvConfig());67 allConfigs.add(new ConcatenatingConfig(getSystemPropertiesConfigPrefix(), '.', System.getProperties()));68 allFlags.forEach(flags -> allConfigs.add(new AnnotatedConfig(flags)));69 allConfigs.add(configFlags.readConfigFiles());70 allConfigs.add(getDefaultConfig());71 Config config = new MemoizedConfig(new CompoundConfig(allConfigs.toArray(new Config[0])));72 if (configFlags.dumpConfig(config, out)) {73 return;74 }75 if (configFlags.dumpConfigHelp(config, getConfigurableRoles(), out)) {76 return;77 }78 LoggingOptions loggingOptions = new LoggingOptions(config);79 loggingOptions.configureLogging();80 execute(config);81 };82 }83 protected abstract String getSystemPropertiesConfigPrefix();84 protected abstract Config getDefaultConfig();85 protected abstract void execute(Config config);...

Full Screen

Full Screen

Source:TemplateGridServerCommand.java Github

copy

Full Screen

...16// under the License.17package org.openqa.selenium.grid;18import org.openqa.selenium.grid.config.CompoundConfig;19import org.openqa.selenium.grid.config.Config;20import org.openqa.selenium.grid.config.MemoizedConfig;21import org.openqa.selenium.grid.server.BaseServerOptions;22import org.openqa.selenium.grid.server.Server;23import org.openqa.selenium.internal.Require;24import org.openqa.selenium.netty.server.NettyServer;25import org.openqa.selenium.remote.http.HttpHandler;26import org.openqa.selenium.remote.http.Message;27import java.util.Optional;28import java.util.function.BiFunction;29import java.util.function.Consumer;30public abstract class TemplateGridServerCommand extends TemplateGridCommand {31 public Server<?> asServer(Config initialConfig) {32 Require.nonNull("Config", initialConfig);33 Config config = new MemoizedConfig(new CompoundConfig(initialConfig, getDefaultConfig()));34 Handlers handler = createHandlers(config);35 return new NettyServer(36 new BaseServerOptions(config),37 handler.httpHandler,38 handler.websocketHandler);39 }40 protected abstract Handlers createHandlers(Config config);41 public static class Handlers {42 public final HttpHandler httpHandler;43 public final BiFunction<String, Consumer<Message>, Optional<Consumer<Message>>> websocketHandler;44 public Handlers(HttpHandler http, BiFunction<String, Consumer<Message>, Optional<Consumer<Message>>> websocketHandler) {45 this.httpHandler = Require.nonNull("HTTP handler", http);46 this.websocketHandler = websocketHandler == null ? (str, sink) -> Optional.empty() : websocketHandler;47 }...

Full Screen

Full Screen

MemoizedConfig

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium.grid.config;2import com.google.auto.service.AutoService;3import com.google.common.collect.ImmutableMap;4import com.google.common.collect.ImmutableSet;5import com.google.common.collect.ImmutableSortedSet;6import com.google.common.collect.Maps;7import com.google.common.collect.Sets;8import java.util.Collection;9import java.util.Collections;10import java.util.Map;11import java.util.Set;12import java.util.SortedSet;13import java.util.stream.Collectors;14import static com.google.common.base.Preconditions.checkArgument;15import static com.google.common.base.Preconditions.checkNotNull;16 * A {@link Config} that caches the results of all lookups, so that subsequent17@AutoService(Config.class)18public class MemoizedConfig implements Config {19 private final Config delegate;20 private final Map<String, String> stringValues = Maps.newHashMap();21 private final Map<String, Boolean> booleanValues = Maps.newHashMap();22 private final Map<String, Set<String>> stringSetValues = Maps.newHashMap();23 private final Map<String, SortedSet<String>> sortedStringSetValues = Maps.newHashMap();24 private final Map<String, Map<String, String>> stringMapValues = Maps.newHashMap();25 public MemoizedConfig(Config delegate) {26 this.delegate = checkNotNull(delegate, "Delegate config must be set.");27 }28 public String get(String name) {29 return stringValues.computeIfAbsent(name, delegate::get);30 }31 public boolean getBool(String name) {32 return booleanValues.computeIfAbsent(name, delegate::getBool);33 }34 public Set<String> getSet(String name) {35 return stringSetValues.computeIfAbsent(name, delegate::getSet);36 }37 public SortedSet<String> getSortedSet(String name) {38 return sortedStringSetValues.computeIfAbsent(name, delegate::getSortedSet);39 }40 public Map<String, String> getMap(String name) {41 return stringMapValues.computeIfAbsent(name, delegate::getMap);42 }43 public Config derive(Map<String, String> newValues) {44 return new MemoizedConfig(delegate.derive(newValues));45 }46 public Config derive(String name, String value) {47 return new MemoizedConfig(delegate.derive(name

Full Screen

Full Screen

MemoizedConfig

Using AI Code Generation

copy

Full Screen

1public class MemoizedConfig {2 private final Config config;3 private final Map<String, String> cache = new ConcurrentHashMap<>();4 public MemoizedConfig(Config config) {5 this.config = config;6 }7 public String get(String name) {8 return cache.computeIfAbsent(name, config::get);9 }10 public String get(String name, String defaultValue) {11 return cache.computeIfAbsent(name, (key) -> config.get(key, defaultValue));12 }13 public String get(String name, Supplier<String> defaultValue) {14 return cache.computeIfAbsent(name, (key) -> config.get(key, defaultValue));15 }16 public Duration getDuration(String name) {17 return cache.computeIfAbsent(name, config::getDuration);18 }19 public Duration getDuration(String name, Duration defaultValue) {20 return cache.computeIfAbsent(name, (key) -> config.getDuration(key, defaultValue));21 }22 public Duration getDuration(String name, Supplier<Duration> defaultValue) {23 return cache.computeIfAbsent(name, (key) -> config.getDuration(key, defaultValue));24 }25 public int getInt(String name) {26 return cache.computeIfAbsent(name, config::getInt);27 }28 public int getInt(String name, int defaultValue) {29 return cache.computeIfAbsent(name, (key) -> config.getInt(key, defaultValue));30 }31 public int getInt(String name, Supplier<Integer> defaultValue) {32 return cache.computeIfAbsent(name, (key) -> config.getInt(key, defaultValue));33 }34 public boolean getBool(String name) {35 return cache.computeIfAbsent(name, config::getBool);36 }37 public boolean getBool(String name, boolean defaultValue) {38 return cache.computeIfAbsent(name, (key) -> config.getBool(key, defaultValue));39 }40 public boolean getBool(String name, Supplier<Boolean> defaultValue) {41 return cache.computeIfAbsent(name, (key) -> config.getBool(key, defaultValue));42 }43 public List<String> getAll(String name) {44 return cache.computeIfAbsent(name, config::getAll);45 }46 public List<String> getAll(String name, List<String> defaultValue) {47 return cache.computeIfAbsent(name, (key) -> config.getAll(key, defaultValue));48 }49 public List<String> getAll(String name, Supplier<List<String>> defaultValue) {50 return cache.computeIfAbsent(name, (key) -> config.getAll(key, defaultValue));51 }

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in MemoizedConfig

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful