How to use setAvailability method of org.openqa.selenium.grid.distributor.GridModel class

Best Selenium code snippet using org.openqa.selenium.grid.distributor.GridModel.setAvailability

Source:GridModel.java Github

copy

Full Screen

...54 private final Map<Availability, Set<NodeStatus>> nodes = new ConcurrentHashMap<>();55 private final EventBus events;56 public GridModel(EventBus events, Secret registrationSecret) {57 this.events = Require.nonNull("Event bus", events);58 events.addListener(NodeDrainStarted.listener(nodeId -> setAvailability(nodeId, DRAINING)));59 events.addListener(NodeDrainComplete.listener(this::remove));60 events.addListener(NodeRemovedEvent.listener(this::remove));61 events.addListener(NodeStatusEvent.listener(status -> refresh(registrationSecret, status)));62 events.addListener(SessionClosedEvent.listener(this::release));63 }64 public GridModel add(NodeStatus node) {65 Require.nonNull("Node", node);66 Lock writeLock = lock.writeLock();67 writeLock.lock();68 try {69 // If we've already added the node, remove it.70 for (Set<NodeStatus> nodes : nodes.values()) {71 Iterator<NodeStatus> iterator = nodes.iterator();72 while (iterator.hasNext()) {73 NodeStatus next = iterator.next();74 // If the ID is the same, we're re-adding a node. If the URI is the same a node probably restarted75 if (next.getId().equals(node.getId()) || next.getUri().equals(node.getUri())) {76 LOG.info(String.format("Re-adding node with id %s and URI %s.", node.getId(), node.getUri()));77 iterator.remove();78 }79 }80 }81 // Nodes are initially added in the "down" state until something changes their availability82 nodes(DOWN).add(node);83 } finally {84 writeLock.unlock();85 }86 return this;87 }88 public GridModel refresh(Secret registrationSecret, NodeStatus status) {89 Require.nonNull("Node status", status);90 Secret statusSecret = status.getRegistrationSecret() == null ? null : new Secret(status.getRegistrationSecret());91 if (!Objects.equals(registrationSecret, statusSecret)) {92 LOG.severe(String.format("Node at %s failed to send correct registration secret. Node NOT refreshed.", status.getUri()));93 events.fire(new NodeRejectedEvent(status.getUri()));94 return this;95 }96 Lock writeLock = lock.writeLock();97 writeLock.lock();98 try {99 AvailabilityAndNode availabilityAndNode = findNode(status.getId());100 if (availabilityAndNode == null) {101 return this;102 }103 // if the node was marked as "down", keep it down until a healthcheck passes:104 // just because the node can hit the event bus doesn't mean it's reachable105 if (DOWN.equals(availabilityAndNode.availability)) {106 nodes(DOWN).remove(availabilityAndNode.status);107 nodes(DOWN).add(status);108 return this;109 }110 // But do trust the node if it tells us it's draining111 nodes(availabilityAndNode.availability).remove(availabilityAndNode.status);112 nodes(status.getAvailability()).add(status);113 return this;114 } finally {115 writeLock.unlock();116 }117 }118 public GridModel remove(NodeId id) {119 Require.nonNull("Node ID", id);120 Lock writeLock = lock.writeLock();121 writeLock.lock();122 try {123 AvailabilityAndNode availabilityAndNode = findNode(id);124 if (availabilityAndNode == null) {125 return this;126 }127 nodes(availabilityAndNode.availability).remove(availabilityAndNode.status);128 return this;129 } finally {130 writeLock.unlock();131 }132 }133 public Availability setAvailability(NodeId id, Availability availability) {134 Require.nonNull("Node ID", id);135 Require.nonNull("Availability", availability);136 Lock writeLock = lock.writeLock();137 writeLock.lock();138 try {139 AvailabilityAndNode availabilityAndNode = findNode(id);140 if (availabilityAndNode == null) {141 return DOWN;142 }143 if (availability.equals(availabilityAndNode.availability)) {144 return availability;145 }146 nodes(availabilityAndNode.availability).remove(availabilityAndNode.status);147 nodes(availability).add(availabilityAndNode.status);...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

...165 }166 Lock writeLock = lock.writeLock();167 writeLock.lock();168 try {169 model.setAvailability(id, result.getAvailability());170 } finally {171 writeLock.unlock();172 }173 };174 }175 @Override176 public boolean drain(NodeId nodeId) {177 Node node = nodes.get(nodeId);178 if (node == null) {179 LOG.info("Asked to drain unregistered node " + nodeId);180 return false;181 }182 Lock writeLock = lock.writeLock();183 writeLock.lock();184 try {185 node.drain();186 model.setAvailability(nodeId, DRAINING);187 } finally {188 writeLock.unlock();189 }190 return node.isDraining();191 }192 public void remove(NodeId nodeId) {193 Lock writeLock = lock.writeLock();194 writeLock.lock();195 try {196 model.remove(nodeId);197 Runnable runnable = allChecks.remove(nodeId);198 if (runnable != null) {199 hostChecker.remove(runnable);200 }...

Full Screen

Full Screen

setAvailability

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.distributor.GridModel2import org.openqa.selenium.grid.distributor.local.LocalDistributor3import org.openqa.selenium.grid.config.Config4import org.openqa.selenium.grid.config.MemoizedConfig5import org.openqa.selenium.grid.config.ConfigException6import org.openqa.selenium.grid.config.MapConfig7import org.openqa.selenium.grid.config.TomlConfig8import org.openqa.selenium.grid.data.Availability9import org.openqa.selenium.grid.data.AvailabilityType10import org.openqa.selenium.grid.data.DistributorStatus11import org.openqa.selenium.grid.data.NodeId12import org.openqa.selenium.grid.data.NodeStatus13import org.openqa.selenium.grid.data.Session14import org.openqa.selenium.grid.data.SessionId15import org.openqa.selenium.grid.data.SessionRequest16import org.openqa.selenium.grid.data.SessionRequestListener17import org.openqa.selenium.grid.data.SessionResponse18import org.openqa.selenium.grid.data.SlotId19import org.openqa.selenium.grid.distributor.Distributor20import org.openqa.selenium.grid.distributor.DistributorStatus21import org.openqa.selenium.grid.distributor.DistributorStatusEvent22import org.openqa.selenium.grid.distributor.DistributorStatusListener23import org.openqa.selenium.grid.distributor.DistributorStatusSource24import org.openqa.selenium.grid.distributor.local.LocalDistributor25import org.openqa.selenium.grid.distributor.selector.Prioritizer26import org.openqa.selenium.grid.distributor.selector.SlotSelector27import org.openqa.selenium.grid.distributor.selector.StickyPrioritizer28import org.openqa.selenium.grid.distributor.selector.StickySelector29import org.openqa.selenium.grid.graphql.GraphqlHandler30import org.openqa.selenium.grid.log.LoggingOptions31import org.openqa.selenium.grid.node.local.LocalNode32import org.openqa.selenium.grid.server.BaseServerOptions33import org.openqa.selenium.grid.server.Server34import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions35import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap36import org.openqa.selenium.grid.web.CommandHandler37import org.openqa.selenium.grid.web.Routable38import org.openqa.selenium.grid.web.Routes39import org.openqa.selenium.internal.Require40import org.openqa.selenium.json.Json41import org.openqa.selenium.json.JsonOutput42import org.openqa.selenium.remote.http.HttpMethod43import org.openqa.selenium.remote.http.HttpRequest44import org.openqa.selenium.remote.http.HttpResponse45import org.openqa.selenium.remote.http.Route46import org.openqa.selenium.remote.tracing.Tracer47import org.openqa.selenium.remote.tracing.TracerProvider48import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracerProvider49import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetry

Full Screen

Full Screen

setAvailability

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.distributor.model.GridModel;2import org.openqa.selenium.grid.distributor.model.Host;3import org.openqa.selenium.grid.distributor.model.Hosts;4import org.openqa.selenium.grid.distributor.model.HostStatus;5import org.openqa.selenium.grid.distributor.model.Hosts.HostsSupplier;6import org.openqa.selenium.grid.distributor.model.HostsSupplier;7import org.openqa.selenium.remote.tracing.DefaultTestTracer;8import org.openqa.selenium.remote.tracer.DefaultTestTracer;9import org.openqa.selenium.remote.tracer.Tracer;10import org.openqa.selenium.remote.tracer.Tracer;11import java.util.Map;12import java.util.Optional;13import java.util.stream.Stream;14import static org.openqa.selenium.grid.distributor.model.HostStatus.DOWN;15public class GridModelSetAvailability {16 public static void main(String[] args) {17 Tracer tracer = DefaultTestTracer.createTracer();18 HostsSupplier hostsSupplier = () -> Stream.of(19 Hosts hosts = new Hosts(tracer, hostsSupplier);20 GridModel model = new GridModel(tracer, hosts);21 System.out.println(host);22 }23}

Full Screen

Full Screen

setAvailability

Using AI Code Generation

copy

Full Screen

1import java.io.IOException;2import java.net.URL;3import java.util.HashMap;4import java.util.Map;5import java.util.concurrent.TimeUnit;6import org.openqa.selenium.By;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.remote.DesiredCapabilities;10import org.openqa.selenium.remote.RemoteWebDriver;11public class GridAvailability {12public static void main(String[] args) throws IOException {13 DesiredCapabilities dc = new DesiredCapabilities();14 dc.setBrowserName("chrome");15 dc.setPlatform(org.openqa.selenium.Platform.WINDOWS);16 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);17 WebElement searchBox = driver.findElement(By.name("q"));18 searchBox.sendKeys("Selenium");19 driver.quit();20 Map<String, Object> params = new HashMap<>();21 params.put("id", "b8a2f2e2-1b6d-4cf8-9a2b-2a1c5d0d5b8a");22 params.put("available", false);23 driver.executeScript("sauce: setAvailability", params);24}25}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful