How to use add method of org.openqa.selenium.grid.distributor.Distributor class

Best Selenium code snippet using org.openqa.selenium.grid.distributor.Distributor.add

Source:Host.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.distributor.local;18import static java.util.stream.Collectors.groupingBy;19import static java.util.stream.Collectors.summingInt;20import static org.openqa.selenium.grid.data.SessionClosedEvent.SESSION_CLOSED;21import static org.openqa.selenium.grid.distributor.local.Host.Status.DOWN;22import static org.openqa.selenium.grid.distributor.local.Host.Status.DRAINING;23import static org.openqa.selenium.grid.distributor.local.Host.Status.UP;24import static org.openqa.selenium.grid.distributor.local.Slot.Status.ACTIVE;25import static org.openqa.selenium.grid.distributor.local.Slot.Status.AVAILABLE;26import com.google.common.annotations.VisibleForTesting;27import com.google.common.collect.ImmutableList;28import org.openqa.selenium.Capabilities;29import org.openqa.selenium.SessionNotCreatedException;30import org.openqa.selenium.events.EventBus;31import org.openqa.selenium.grid.component.HealthCheck;32import org.openqa.selenium.grid.data.CreateSessionRequest;33import org.openqa.selenium.grid.data.CreateSessionResponse;34import org.openqa.selenium.grid.data.DistributorStatus;35import org.openqa.selenium.grid.data.NodeStatus;36import org.openqa.selenium.grid.node.Node;37import org.openqa.selenium.remote.SessionId;38import java.net.URI;39import java.util.HashMap;40import java.util.List;41import java.util.Map;42import java.util.Objects;43import java.util.Set;44import java.util.UUID;45import java.util.concurrent.locks.Lock;46import java.util.concurrent.locks.ReadWriteLock;47import java.util.concurrent.locks.ReentrantReadWriteLock;48import java.util.function.Supplier;49import java.util.logging.Logger;50class Host {51 private static final Logger LOG = Logger.getLogger("Selenium Distributor");52 private final Node node;53 private final UUID nodeId;54 private final URI uri;55 private final Runnable performHealthCheck;56 // Used any time we need to read or modify the mutable state of this host57 private final ReadWriteLock lock = new ReentrantReadWriteLock(/* fair */ true);58 private Status status;59 private List<Slot> slots;60 private int maxSessionCount;61 public Host(EventBus bus, Node node) {62 this.node = Objects.requireNonNull(node);63 this.nodeId = node.getId();64 this.uri = node.getUri();65 this.status = Status.DOWN;66 this.slots = ImmutableList.of();67 HealthCheck healthCheck = node.getHealthCheck();68 this.performHealthCheck = () -> {69 HealthCheck.Result result = healthCheck.check();70 Host.Status current = result.isAlive() ? UP : DOWN;71 Host.Status previous = setHostStatus(current);72 if (previous == DRAINING) {73 // We want to continue to allow the node to drain.74 setHostStatus(DRAINING);75 return;76 }77 if (current != previous) {78 LOG.info(String.format(79 "Changing status of node %s from %s to %s. Reason: %s",80 node.getId(),81 previous,82 current,83 result.getMessage()));84 }85 };86 bus.addListener(SESSION_CLOSED, event -> {87 SessionId id = event.getData(SessionId.class);88 this.slots.forEach(slot -> slot.onEnd(id));89 });90 update(node.getStatus());91 }92 void update(NodeStatus status) {93 Objects.requireNonNull(status);94 Lock writeLock = lock.writeLock();95 writeLock.lock();96 try {97 // This is grossly inefficient. But we're on a modern processor and we're expecting 10s to 100s98 // of nodes, so this is probably ok.99 Set<NodeStatus.Active> sessions = status.getCurrentSessions();100 Map<Capabilities, Integer> actives = sessions.parallelStream().collect(101 groupingBy(NodeStatus.Active::getStereotype, summingInt(active -> 1)));102 ImmutableList.Builder<Slot> slots = ImmutableList.builder();103 status.getStereotypes().forEach((caps, count) -> {104 if (actives.containsKey(caps)) {105 Integer activeCount = actives.get(caps);106 for (int i = 0; i < activeCount; i++) {107 slots.add(new Slot(node, caps, ACTIVE));108 }109 count -= activeCount;110 }111 for (int i = 0; i < count; i++) {112 slots.add(new Slot(node, caps, AVAILABLE));113 }114 });115 this.slots = slots.build();116 // By definition, we can never have more sessions than we have slots available117 this.maxSessionCount = Math.min(this.slots.size(), status.getMaxSessionCount());118 } finally {119 writeLock.unlock();120 }121 }122 public UUID getId() {123 return nodeId;124 }125 public DistributorStatus.NodeSummary asSummary() {126 Map<Capabilities, Integer> stereotypes = new HashMap<>();...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.distributor.local;18import static com.google.common.collect.ImmutableList.toImmutableList;19import static org.openqa.selenium.grid.distributor.local.Host.Status.DOWN;20import static org.openqa.selenium.grid.distributor.local.Host.Status.DRAINING;21import static org.openqa.selenium.grid.distributor.local.Host.Status.UP;22import com.google.common.annotations.VisibleForTesting;23import com.google.common.collect.ImmutableList;24import org.openqa.selenium.Beta;25import org.openqa.selenium.Capabilities;26import org.openqa.selenium.SessionNotCreatedException;27import org.openqa.selenium.concurrent.Regularly;28import org.openqa.selenium.grid.component.HealthCheck;29import org.openqa.selenium.grid.data.Session;30import org.openqa.selenium.grid.distributor.Distributor;31import org.openqa.selenium.grid.distributor.DistributorStatus;32import org.openqa.selenium.grid.node.Node;33import org.openqa.selenium.grid.node.NodeStatus;34import org.openqa.selenium.json.Json;35import org.openqa.selenium.json.JsonOutput;36import org.openqa.selenium.remote.NewSessionPayload;37import org.openqa.selenium.remote.http.HttpClient;38import org.openqa.selenium.remote.tracing.DistributedTracer;39import org.openqa.selenium.remote.tracing.Span;40import java.time.Duration;41import java.util.ArrayList;42import java.util.Collection;43import java.util.Comparator;44import java.util.HashSet;45import java.util.Iterator;46import java.util.Map;47import java.util.Objects;48import java.util.Optional;49import java.util.Set;50import java.util.UUID;51import java.util.concurrent.ConcurrentHashMap;52import java.util.concurrent.locks.Lock;53import java.util.concurrent.locks.ReadWriteLock;54import java.util.concurrent.locks.ReentrantReadWriteLock;55import java.util.function.Supplier;56import java.util.logging.Logger;57public class LocalDistributor extends Distributor {58 private static final Json JSON = new Json();59 private static final Logger LOG = Logger.getLogger("Selenium Distributor");60 private final ReadWriteLock lock = new ReentrantReadWriteLock(/* fair */ true);61 private final Set<Host> hosts = new HashSet<>();62 private final DistributedTracer tracer;63 private final Regularly hostChecker = new Regularly("distributor host checker");64 private final Map<UUID, Collection<Runnable>> allChecks = new ConcurrentHashMap<>();65 public LocalDistributor(DistributedTracer tracer, HttpClient.Factory httpClientFactory) {66 super(tracer, httpClientFactory);67 this.tracer = Objects.requireNonNull(tracer);68 }69 @Override70 public Session newSession(NewSessionPayload payload) throws SessionNotCreatedException {71 Iterator<Capabilities> allCaps = payload.stream().iterator();72 if (!allCaps.hasNext()) {73 throw new SessionNotCreatedException("No capabilities found");74 }75 Capabilities caps = allCaps.next();76 Optional<Supplier<Session>> selected;77 Lock writeLock = this.lock.writeLock();78 writeLock.lock();79 try {80 selected = this.hosts.stream()81 .filter(host -> host.getHostStatus() == UP)82 // Find a host that supports this kind of thing83 .filter(host -> host.hasCapacity(caps))84 .min(85 // Now sort by node which has the lowest load (natural ordering)86 Comparator.comparingDouble(Host::getLoad)87 // Then last session created (oldest first), so natural ordering again88 .thenComparingLong(Host::getLastSessionCreated)89 // And use the host id as a tie-breaker.90 .thenComparing(Host::getId))91 // And reserve some space92 .map(host -> host.reserve(caps));93 } finally {94 writeLock.unlock();95 }96 return selected97 .orElseThrow(98 () -> new SessionNotCreatedException("Unable to find provider for session: " + allCaps))99 .get();100 }101 @Override102 public LocalDistributor add(Node node) {103 StringBuilder sb = new StringBuilder();104 Lock writeLock = this.lock.writeLock();105 writeLock.lock();106 try (Span span = tracer.createSpan("distributor.add", tracer.getActiveSpan());107 JsonOutput out = JSON.newOutput(sb)) {108 out.setPrettyPrint(false).write(node);109 span.addTag("node", sb.toString());110 // TODO: We should check to see what happens for duplicate nodes.111 Host host = new Host(node);112 hosts.add(host);113 LOG.info(String.format("Added node %s.", node.getId()));114 host.refresh();115 Runnable runnable = host::refresh;116 Collection<Runnable> nodeRunnables = allChecks.getOrDefault(node.getId(), new ArrayList<>());117 nodeRunnables.add(runnable);118 allChecks.put(node.getId(), nodeRunnables);119 hostChecker.submit(runnable, Duration.ofMinutes(5), Duration.ofSeconds(30));120 } finally {121 writeLock.unlock();122 }123 return this;124 }125 @Override126 public void remove(UUID nodeId) {127 Lock writeLock = lock.writeLock();128 writeLock.lock();129 try (Span span = tracer.createSpan("distributor.remove", tracer.getActiveSpan())) {130 span.addTag("node.id", nodeId);131 hosts.removeIf(host -> nodeId.equals(host.getId()));132 allChecks.getOrDefault(nodeId, new ArrayList<>()).forEach(hostChecker::remove);133 } finally {134 writeLock.unlock();135 }136 }137 @Override138 public DistributorStatus getStatus() {139 Lock readLock = this.lock.readLock();140 readLock.lock();141 try {142 ImmutableList<NodeStatus> nodesStatuses = this.hosts.stream()143 .map(Host::getStatus)144 .collect(toImmutableList());...

Full Screen

Full Screen

Source:DistributorServer.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.distributor.httpd;18import com.google.auto.service.AutoService;19import com.beust.jcommander.JCommander;20import com.beust.jcommander.ParameterException;21import org.openqa.selenium.cli.CliCommand;22import org.openqa.selenium.events.EventBus;23import org.openqa.selenium.grid.config.AnnotatedConfig;24import org.openqa.selenium.grid.config.CompoundConfig;25import org.openqa.selenium.grid.config.ConcatenatingConfig;26import org.openqa.selenium.grid.config.Config;27import org.openqa.selenium.grid.config.EnvConfig;28import org.openqa.selenium.grid.distributor.Distributor;29import org.openqa.selenium.grid.distributor.local.LocalDistributor;30import org.openqa.selenium.grid.log.LoggingOptions;31import org.openqa.selenium.grid.server.BaseServer;32import org.openqa.selenium.grid.server.BaseServerFlags;33import org.openqa.selenium.grid.server.BaseServerOptions;34import org.openqa.selenium.grid.server.EventBusConfig;35import org.openqa.selenium.grid.server.EventBusFlags;36import org.openqa.selenium.grid.server.HelpFlags;37import org.openqa.selenium.grid.server.Server;38import org.openqa.selenium.grid.server.W3CCommandHandler;39import org.openqa.selenium.grid.sessionmap.SessionMap;40import org.openqa.selenium.grid.sessionmap.config.SessionMapFlags;41import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;42import org.openqa.selenium.grid.web.Routes;43import org.openqa.selenium.remote.http.HttpClient;44import org.openqa.selenium.remote.tracing.DistributedTracer;45import org.openqa.selenium.remote.tracing.GlobalDistributedTracer;46@AutoService(CliCommand.class)47public class DistributorServer implements CliCommand {48 @Override49 public String getName() {50 return "distributor";51 }52 @Override53 public String getDescription() {54 return "Adds this server as the distributor in a selenium grid.";55 }56 @Override57 public Executable configure(String... args) {58 HelpFlags help = new HelpFlags();59 BaseServerFlags serverFlags = new BaseServerFlags(5553);60 SessionMapFlags sessionMapFlags = new SessionMapFlags();61 EventBusFlags eventBusFlags = new EventBusFlags();62 JCommander commander = JCommander.newBuilder()63 .programName(getName())64 .addObject(help)65 .addObject(eventBusFlags)66 .addObject(sessionMapFlags)67 .addObject(serverFlags)68 .build();69 return () -> {70 try {71 commander.parse(args);72 } catch (ParameterException e) {73 System.err.println(e.getMessage());74 commander.usage();75 return;76 }77 if (help.displayHelp(commander, System.out)) {78 return;79 }80 Config config = new CompoundConfig(81 new EnvConfig(),82 new ConcatenatingConfig("distributor", '.', System.getProperties()),83 new AnnotatedConfig(help),84 new AnnotatedConfig(eventBusFlags),85 new AnnotatedConfig(serverFlags),86 new AnnotatedConfig(sessionMapFlags),87 new DefaultDistributorConfig());88 LoggingOptions loggingOptions = new LoggingOptions(config);89 loggingOptions.configureLogging();90 DistributedTracer tracer = loggingOptions.getTracer();91 GlobalDistributedTracer.setInstance(tracer);92 EventBusConfig events = new EventBusConfig(config);93 EventBus bus = events.getEventBus();94 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();95 SessionMap sessions = new SessionMapOptions(config).getSessionMap(clientFactory);96 Distributor distributor = new LocalDistributor(97 tracer,98 bus,99 clientFactory,100 sessions);101 BaseServerOptions serverOptions = new BaseServerOptions(config);102 Server<?> server = new BaseServer<>(serverOptions);103 server.addRoute(104 Routes.matching(distributor).using(distributor).decorateWith(W3CCommandHandler::new));105 server.start();106 };107 }108}...

Full Screen

Full Screen

Source:RouterServer.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.router.httpd;18import com.google.auto.service.AutoService;19import com.beust.jcommander.JCommander;20import com.beust.jcommander.ParameterException;21import org.openqa.selenium.cli.CliCommand;22import org.openqa.selenium.grid.config.AnnotatedConfig;23import org.openqa.selenium.grid.config.CompoundConfig;24import org.openqa.selenium.grid.config.ConcatenatingConfig;25import org.openqa.selenium.grid.config.Config;26import org.openqa.selenium.grid.config.EnvConfig;27import org.openqa.selenium.grid.distributor.Distributor;28import org.openqa.selenium.grid.distributor.config.DistributorFlags;29import org.openqa.selenium.grid.distributor.config.DistributorOptions;30import org.openqa.selenium.grid.log.LoggingOptions;31import org.openqa.selenium.grid.router.Router;32import org.openqa.selenium.grid.server.BaseServer;33import org.openqa.selenium.grid.server.BaseServerFlags;34import org.openqa.selenium.grid.server.BaseServerOptions;35import org.openqa.selenium.grid.server.HelpFlags;36import org.openqa.selenium.grid.server.Server;37import org.openqa.selenium.grid.server.W3CCommandHandler;38import org.openqa.selenium.grid.sessionmap.SessionMap;39import org.openqa.selenium.grid.sessionmap.config.SessionMapFlags;40import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;41import org.openqa.selenium.grid.web.Routes;42import org.openqa.selenium.remote.http.HttpClient;43import org.openqa.selenium.remote.tracing.DistributedTracer;44import org.openqa.selenium.remote.tracing.GlobalDistributedTracer;45@AutoService(CliCommand.class)46public class RouterServer implements CliCommand {47 @Override48 public String getName() {49 return "router";50 }51 @Override52 public String getDescription() {53 return "Creates a router to front the selenium grid.";54 }55 @Override56 public Executable configure(String... args) {57 HelpFlags help = new HelpFlags();58 BaseServerFlags serverFlags = new BaseServerFlags(4444);59 SessionMapFlags sessionMapFlags = new SessionMapFlags();60 DistributorFlags distributorFlags = new DistributorFlags();61 JCommander commander = JCommander.newBuilder()62 .programName(getName())63 .addObject(help)64 .addObject(serverFlags)65 .addObject(sessionMapFlags)66 .addObject(distributorFlags)67 .build();68 return () -> {69 try {70 commander.parse(args);71 } catch (ParameterException e) {72 System.err.println(e.getMessage());73 commander.usage();74 return;75 }76 if (help.displayHelp(commander, System.out)) {77 return;78 }79 Config config = new CompoundConfig(80 new EnvConfig(),81 new ConcatenatingConfig("router", '.', System.getProperties()),82 new AnnotatedConfig(help),83 new AnnotatedConfig(serverFlags),84 new AnnotatedConfig(sessionMapFlags),85 new AnnotatedConfig(distributorFlags));86 LoggingOptions loggingOptions = new LoggingOptions(config);87 loggingOptions.configureLogging();88 DistributedTracer tracer = loggingOptions.getTracer();89 GlobalDistributedTracer.setInstance(tracer);90 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();91 SessionMapOptions sessionsOptions = new SessionMapOptions(config);92 SessionMap sessions = sessionsOptions.getSessionMap(clientFactory);93 BaseServerOptions serverOptions = new BaseServerOptions(config);94 DistributorOptions distributorOptions = new DistributorOptions(config);95 Distributor distributor = distributorOptions.getDistributor(tracer, clientFactory);96 Router router = new Router(tracer, clientFactory, sessions, distributor);97 Server<?> server = new BaseServer<>(serverOptions);98 server.addRoute(Routes.matching(router).using(router).decorateWith(W3CCommandHandler::new));99 server.start();100 };101 }102}...

Full Screen

Full Screen

add

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium.grid.distributor;2import org.openqa.selenium.grid.data.Session;3import org.openqa.selenium.grid.data.SessionRequest;4import org.openqa.selenium.grid.node.Node;5import org.openqa.selenium.grid.node.NodeId;6import org.openqa.selenium.grid.web.Routable;7import org.openqa.selenium.internal.Require;8import org.openqa.selenium.remote.http.Contents;9import org.openqa.selenium.remote.http.HttpHandler;10import org.openqa.selenium.remote.http.HttpRequest;11import org.openqa.selenium.remote.http.HttpResponse;12import java.util.Objects;13import java.util.UUID;14import java.util.function.Predicate;15import java.util.logging.Logger;16public class AddNode implements Routable {17 private static final Logger LOG = Logger.getLogger(AddNode.class.getName());18 private final Distributor distributor;19 public AddNode(Distributor distributor) {20 this.distributor = Require.nonNull("Distributor", distributor);21 }22 public Predicate<HttpRequest> getRoute() {23 return req -> req.getMethod().equals("POST") &&24 req.getUri().getPath().equals("/se/grid/distributor/node");25 }26 public HttpHandler execute(HttpRequest req) {27 return new HttpHandler() {28 public HttpResponse execute(HttpRequest req) throws Exception {29 Node node = Node.fromJSON(Contents.string(req));30 distributor.add(node);31 return new HttpResponse()32 .setStatus(200);33 }34 };35 }36}37package org.openqa.selenium.grid.distributor;38import org.openqa.selenium.grid.data.Session;39import org.openqa.selenium.grid.data.SessionRequest;40import org.openqa.selenium.grid.node.Node;41import org.openqa.selenium.grid.node.NodeId;42import org.openqa.selenium.grid.web.Routable;43import org.openqa.selenium.internal.Require;44import org.openqa.selenium.remote.http.Contents;45import org.openqa.selenium.remote.http.HttpHandler;46import org.openqa.selenium.remote.http.HttpRequest;47import org.openqa.selenium.remote.http.HttpResponse;48import java.util.Objects;49import java.util.UUID;50import java.util.function.Predicate;51import java.util.logging.Logger;52public class RemoveNode implements Routable {53 private static final Logger LOG = Logger.getLogger(RemoveNode.class.getName());54 private final Distributor distributor;55 public RemoveNode(Distributor distributor) {56 this.distributor = Require.nonNull("Distributor", distributor);57 }58 public Predicate<HttpRequest> getRoute() {59 return req -> req.getMethod().equals

Full Screen

Full Screen

add

Using AI Code Generation

copy

Full Screen

1 public void testDistributorAdd() {2 Distributor distributor = new Distributor();3 distributor.add(null);4 }5 public void testDistributorAdd() {6 Distributor distributor = new Distributor();7 distributor.add(null);8 }9 public void testDistributorAdd() {10 Distributor distributor = new Distributor();11 distributor.add(null);12 }13 public void testDistributorAdd() {14 Distributor distributor = new Distributor();15 distributor.add(null);16 }17 public void testDistributorAdd() {18 Distributor distributor = new Distributor();19 distributor.add(null);20 }21 public void testDistributorAdd() {22 Distributor distributor = new Distributor();23 distributor.add(null);24 }25 public void testDistributorAdd() {26 Distributor distributor = new Distributor();27 distributor.add(null);28 }29 public void testDistributorAdd() {30 Distributor distributor = new Distributor();31 distributor.add(null);32 }33 public void testDistributorAdd() {34 Distributor distributor = new Distributor();35 distributor.add(null);36 }37 public void testDistributorAdd() {38 Distributor distributor = new Distributor();39 distributor.add(null);40 }41 public void testDistributorAdd() {42 Distributor distributor = new Distributor();43 distributor.add(null);44 }

Full Screen

Full Screen

add

Using AI Code Generation

copy

Full Screen

1SessionRequest request = new SessionRequest(2 new SessionId(UUID.randomUUID()),3 new SessionRequest.Capabilities(4 ImmutableMap.of("browserName", "chrome")5);6Distributor distributor = new Distributor();7distributor.add(request);8System.out.println(distributor.size());9System.out.println(distributor.get(request.getId()));10distributor.remove(request.getId());11System.out.println(distributor.size());12System.out.println(distributor.get(request.getId()));

Full Screen

Full Screen

add

Using AI Code Generation

copy

Full Screen

1public static String addSession(Distributor distributor, SessionRequest sessionRequest) {2 if (distributor == null || sessionRequest == null) {3 return null;4 }5 Session session = distributor.add(sessionRequest);6 if (session == null) {7 return null;8 }9 return session.getId().toString();10}11public static boolean removeSession(Distributor distributor, String sessionId) {12 if (distributor == null || sessionId == null) {13 return false;14 }15 distributor.remove(new SessionId(sessionId));16 return true;17}18public static Session getSession(Distributor distributor, String sessionId) {19 if (distributor == null || sessionId == null) {20 return null;21 }22 return distributor.get(new SessionId(sessionId));23}24public static List<Session> getAllSessions(Distributor distributor) {25 if (distributor == null) {26 return null;27 }28 return distributor.getAll();29}30public static List<Session> getActiveSessions(Distributor distributor) {31 if (distributor == null) {32 return null;33 }

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 method in Distributor

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful