How to use NodeStatus class of org.openqa.selenium.grid.data package

Best Selenium code snippet using org.openqa.selenium.grid.data.NodeStatus

Source:GridModel.java Github

copy

Full Screen

...22import org.openqa.selenium.grid.data.NodeDrainStarted;23import org.openqa.selenium.grid.data.NodeId;24import org.openqa.selenium.grid.data.NodeRejectedEvent;25import org.openqa.selenium.grid.data.NodeRemovedEvent;26import org.openqa.selenium.grid.data.NodeStatus;27import org.openqa.selenium.grid.data.NodeStatusEvent;28import org.openqa.selenium.grid.data.Session;29import org.openqa.selenium.grid.data.SessionClosedEvent;30import org.openqa.selenium.grid.data.Slot;31import org.openqa.selenium.grid.data.SlotId;32import org.openqa.selenium.grid.security.Secret;33import org.openqa.selenium.internal.Require;34import org.openqa.selenium.remote.SessionId;35import java.time.Instant;36import java.util.HashSet;37import java.util.Iterator;38import java.util.Map;39import java.util.Objects;40import java.util.Optional;41import java.util.Set;42import java.util.concurrent.ConcurrentHashMap;43import java.util.concurrent.locks.Lock;44import java.util.concurrent.locks.ReadWriteLock;45import java.util.concurrent.locks.ReentrantReadWriteLock;46import java.util.logging.Logger;47import static org.openqa.selenium.grid.data.Availability.DOWN;48import static org.openqa.selenium.grid.data.Availability.DRAINING;49import static org.openqa.selenium.grid.data.Availability.UP;50public class GridModel {51 private static final Logger LOG = Logger.getLogger(GridModel.class.getName());52 private static final SessionId RESERVED = new SessionId("reserved");53 private final ReadWriteLock lock = new ReentrantReadWriteLock(/* fair */ true);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);148 LOG.info(String.format(149 "Switching node %s (uri: %s) from %s to %s",150 id,151 availabilityAndNode.status.getUri(),152 availabilityAndNode.availability,153 availability));154 return availabilityAndNode.availability;155 } finally {156 writeLock.unlock();157 }158 }159 public boolean reserve(SlotId slotId) {160 Lock writeLock = lock.writeLock();161 writeLock.lock();162 try {163 AvailabilityAndNode node = findNode(slotId.getOwningNodeId());164 if (node == null) {165 LOG.warning(String.format("Asked to reserve slot on node %s, but unable to find node", slotId.getOwningNodeId()));166 return false;167 }168 if (!UP.equals(node.availability)) {169 LOG.warning(String.format(170 "Asked to reserve a slot on node %s, but not is %s",171 slotId.getOwningNodeId(),172 node.availability));173 return false;174 }175 Optional<Slot> maybeSlot = node.status.getSlots().stream()176 .filter(slot -> slotId.equals(slot.getId()))177 .findFirst();178 if (!maybeSlot.isPresent()) {179 LOG.warning(String.format(180 "Asked to reserve slot on node %s, but no slot with id %s found",181 node.status.getId(),182 slotId));183 return false;184 }185 reserve(node.status, maybeSlot.get());186 return true;187 } finally {188 writeLock.unlock();189 }190 }191 public Set<NodeStatus> getSnapshot() {192 Lock readLock = this.lock.readLock();193 readLock.lock();194 try {195 ImmutableSet.Builder<NodeStatus> snapshot = ImmutableSet.builder();196 for (Map.Entry<Availability, Set<NodeStatus>> entry : nodes.entrySet()) {197 entry.getValue().stream()198 .map(status -> rewrite(status, entry.getKey()))199 .forEach(snapshot::add);200 }201 return snapshot.build();202 } finally {203 readLock.unlock();204 }205 }206 private Set<NodeStatus> nodes(Availability availability) {207 return nodes.computeIfAbsent(availability, ignored -> new HashSet<>());208 }209 private AvailabilityAndNode findNode(NodeId id) {210 for (Map.Entry<Availability, Set<NodeStatus>> entry : nodes.entrySet()) {211 for (NodeStatus nodeStatus : entry.getValue()) {212 if (id.equals(nodeStatus.getId())) {213 return new AvailabilityAndNode(entry.getKey(), nodeStatus);214 }215 }216 }217 return null;218 }219 private NodeStatus rewrite(NodeStatus status, Availability availability) {220 return new NodeStatus(221 status.getId(),222 status.getUri(),223 status.getMaxSessionCount(),224 status.getSlots(),225 availability,226 status.getRegistrationSecret() == null ? null : new Secret(status.getRegistrationSecret()));227 }228 private void release(SessionId id) {229 if (id == null) {230 return;231 }232 Lock writeLock = lock.writeLock();233 writeLock.lock();234 try {235 for (Map.Entry<Availability, Set<NodeStatus>> entry : nodes.entrySet()) {236 for (NodeStatus node : entry.getValue()) {237 for (Slot slot : node.getSlots()) {238 if (!slot.getSession().isPresent()) {239 continue;240 }241 if (id.equals(slot.getSession().get().getId())) {242 Slot released = new Slot(243 slot.getId(),244 slot.getStereotype(),245 slot.getLastStarted(),246 Optional.empty());247 amend(entry.getKey(), node, released);248 return;249 }250 }251 }252 }253 } finally {254 writeLock.unlock();255 }256 }257 private void reserve(NodeStatus status, Slot slot) {258 Instant now = Instant.now();259 Slot reserved = new Slot(260 slot.getId(),261 slot.getStereotype(),262 now,263 Optional.of(new Session(264 RESERVED,265 status.getUri(),266 slot.getStereotype(),267 slot.getStereotype(),268 now)));269 amend(UP, status, reserved);270 }271 public void setSession(SlotId slotId, Session session) {272 Require.nonNull("Slot ID", slotId);273 AvailabilityAndNode node = findNode(slotId.getOwningNodeId());274 if (node == null) {275 LOG.warning("Grid model and reality have diverged. Unable to find node " + slotId.getOwningNodeId());276 return;277 }278 Optional<Slot> maybeSlot = node.status.getSlots().stream()279 .filter(slot -> slotId.equals(slot.getId()))280 .findFirst();281 if (!maybeSlot.isPresent()) {282 LOG.warning("Grid model and reality have diverged. Unable to find slot " + slotId);283 return;284 }285 Slot slot = maybeSlot.get();286 Optional<Session> maybeSession = slot.getSession();287 if (!maybeSession.isPresent()) {288 LOG.warning("Grid model and reality have diverged. Slot is not reserved. " + slotId);289 return;290 }291 Session current = maybeSession.get();292 if (!RESERVED.equals(current.getId())) {293 LOG.warning("Gid model and reality have diverged. Slot has session and is not reserved. " + slotId);294 return;295 }296 Slot updated = new Slot(297 slot.getId(),298 slot.getStereotype(),299 session == null ? slot.getLastStarted() : session.getStartTime(),300 Optional.ofNullable(session));301 amend(node.availability, node.status, updated);302 }303 private void amend(Availability availability, NodeStatus status, Slot slot) {304 Set<Slot> newSlots = new HashSet<>(status.getSlots());305 newSlots.removeIf(s -> s.getId().equals(slot.getId()));306 newSlots.add(slot);307 nodes(availability).remove(status);308 nodes(availability).add(new NodeStatus(309 status.getId(),310 status.getUri(),311 status.getMaxSessionCount(),312 newSlots,313 status.getAvailability(),314 status.getRegistrationSecret() == null ? null : new Secret(status.getRegistrationSecret())));315 }316 private static class AvailabilityAndNode {317 public final Availability availability;318 public final NodeStatus status;319 public AvailabilityAndNode(Availability availability, NodeStatus status) {320 this.availability = availability;321 this.status = status;322 }323 }324}...

Full Screen

Full Screen

Source:AddingNodesTest.java Github

copy

Full Screen

...29import org.openqa.selenium.grid.component.HealthCheck;30import org.openqa.selenium.grid.data.CreateSessionRequest;31import org.openqa.selenium.grid.data.CreateSessionResponse;32import org.openqa.selenium.grid.data.DistributorStatus;33import org.openqa.selenium.grid.data.NodeStatus;34import org.openqa.selenium.grid.data.NodeStatusEvent;35import org.openqa.selenium.grid.data.Session;36import org.openqa.selenium.grid.data.SessionClosedEvent;37import org.openqa.selenium.grid.distributor.local.LocalDistributor;38import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;39import org.openqa.selenium.grid.node.CapabilityResponseEncoder;40import org.openqa.selenium.grid.node.Node;41import org.openqa.selenium.grid.node.local.LocalNode;42import org.openqa.selenium.events.local.GuavaEventBus;43import org.openqa.selenium.grid.testing.TestSessionFactory;44import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;45import org.openqa.selenium.grid.web.CombinedHandler;46import org.openqa.selenium.grid.web.RoutableHttpClientFactory;47import org.openqa.selenium.remote.SessionId;48import org.openqa.selenium.remote.http.HttpClient;49import org.openqa.selenium.remote.http.HttpRequest;50import org.openqa.selenium.remote.http.HttpResponse;51import org.openqa.selenium.remote.tracing.DistributedTracer;52import org.openqa.selenium.support.ui.FluentWait;53import org.openqa.selenium.support.ui.Wait;54import java.net.MalformedURLException;55import java.net.URI;56import java.net.URISyntaxException;57import java.net.URL;58import java.time.Duration;59import java.util.HashSet;60import java.util.Objects;61import java.util.Optional;62import java.util.Set;63import java.util.UUID;64import java.util.function.Function;65public class AddingNodesTest {66 private static final Capabilities CAPS = new ImmutableCapabilities("cheese", "gouda");67 private Distributor distributor;68 private DistributedTracer tracer;69 private EventBus bus;70 private HttpClient.Factory clientFactory;71 private Wait<Object> wait;72 private URL externalUrl;73 private CombinedHandler handler;74 @Before75 public void setUpDistributor() throws MalformedURLException {76 tracer = DistributedTracer.builder().build();77 bus = new GuavaEventBus();78 handler = new CombinedHandler();79 externalUrl = new URL("http://example.com");80 clientFactory = new RoutableHttpClientFactory(81 externalUrl,82 handler,83 HttpClient.Factory.createDefault());84 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);85 Distributor local = new LocalDistributor(tracer, bus, clientFactory, sessions);86 handler.addHandler(local);87 distributor = new RemoteDistributor(tracer, clientFactory, externalUrl);88 wait = new FluentWait<>(new Object()).withTimeout(Duration.ofSeconds(2));89 }90 @Test91 public void shouldBeAbleToRegisterALocalNode() throws URISyntaxException {92 URI sessionUri = new URI("http://example:1234");93 Node node = LocalNode.builder(tracer, bus, clientFactory, externalUrl.toURI())94 .add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, caps)))95 .build();96 handler.addHandler(node);97 distributor.add(node);98 wait.until(obj -> distributor.getStatus().hasCapacity());99 DistributorStatus.NodeSummary summary = getOnlyElement(distributor.getStatus().getNodes());100 assertEquals(1, summary.getStereotypes().get(CAPS).intValue());101 }102 @Test103 public void shouldBeAbleToRegisterACustomNode() throws URISyntaxException {104 URI sessionUri = new URI("http://example:1234");105 Node node = new CustomNode(106 tracer,107 bus,108 UUID.randomUUID(),109 externalUrl.toURI(),110 c -> new Session(new SessionId(UUID.randomUUID()), sessionUri, c));111 handler.addHandler(node);112 distributor.add(node);113 wait.until(obj -> distributor.getStatus().hasCapacity());114 DistributorStatus.NodeSummary summary = getOnlyElement(distributor.getStatus().getNodes());115 assertEquals(1, summary.getStereotypes().get(CAPS).intValue());116 }117 @Test118 public void shouldBeAbleToRegisterNodesByListeningForEvents() throws URISyntaxException {119 URI sessionUri = new URI("http://example:1234");120 Node node = LocalNode.builder(tracer, bus, clientFactory, externalUrl.toURI())121 .add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, caps)))122 .build();123 handler.addHandler(node);124 bus.fire(new NodeStatusEvent(node.getStatus()));125 wait.until(obj -> distributor.getStatus().hasCapacity());126 DistributorStatus.NodeSummary summary = getOnlyElement(distributor.getStatus().getNodes());127 assertEquals(1, summary.getStereotypes().get(CAPS).intValue());128 }129 @Test130 public void distributorShouldUpdateStateOfExistingNodeWhenNodePublishesStateChange()131 throws URISyntaxException {132 URI sessionUri = new URI("http://example:1234");133 Node node = LocalNode.builder(tracer, bus, clientFactory, externalUrl.toURI())134 .add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, caps)))135 .build();136 handler.addHandler(node);137 bus.fire(new NodeStatusEvent(node.getStatus()));138 // Start empty139 wait.until(obj -> distributor.getStatus().hasCapacity());140 DistributorStatus.NodeSummary summary = getOnlyElement(distributor.getStatus().getNodes());141 assertEquals(1, summary.getStereotypes().get(CAPS).intValue());142 // Craft a status that makes it look like the node is busy, and post it on the bus.143 NodeStatus status = node.getStatus();144 NodeStatus crafted = new NodeStatus(145 status.getNodeId(),146 status.getUri(),147 status.getMaxSessionCount(),148 status.getStereotypes(),149 ImmutableSet.of(new NodeStatus.Active(CAPS, new SessionId(UUID.randomUUID()), CAPS)));150 bus.fire(new NodeStatusEvent(crafted));151 // We claimed the only slot is filled. Life is good.152 wait.until(obj -> !distributor.getStatus().hasCapacity());153 }154 static class CustomNode extends Node {155 private final EventBus bus;156 private final Function<Capabilities, Session> factory;157 private Session running;158 protected CustomNode(159 DistributedTracer tracer,160 EventBus bus,161 UUID nodeId,162 URI uri,163 Function<Capabilities, Session> factory) {164 super(tracer, nodeId, uri);165 this.bus = bus;166 this.factory = Objects.requireNonNull(factory);167 }168 @Override169 public Optional<CreateSessionResponse> newSession(CreateSessionRequest sessionRequest) {170 Objects.requireNonNull(sessionRequest);171 if (running != null) {172 return Optional.empty();173 }174 Session session = factory.apply(sessionRequest.getCapabilities());175 running = session;176 return Optional.of(177 new CreateSessionResponse(178 session,179 CapabilityResponseEncoder.getEncoder(W3C).apply(session)));180 }181 @Override182 public void executeWebDriverCommand(HttpRequest req, HttpResponse resp) {183 throw new UnsupportedOperationException("executeWebDriverCommand");184 }185 @Override186 public Session getSession(SessionId id) throws NoSuchSessionException {187 if (running == null || !running.getId().equals(id)) {188 throw new NoSuchSessionException();189 }190 return running;191 }192 @Override193 public void stop(SessionId id) throws NoSuchSessionException {194 getSession(id);195 running = null;196 bus.fire(new SessionClosedEvent(id));197 }198 @Override199 protected boolean isSessionOwner(SessionId id) {200 return running != null && running.getId().equals(id);201 }202 @Override203 public boolean isSupporting(Capabilities capabilities) {204 return Objects.equals("cake", capabilities.getCapability("cheese"));205 }206 @Override207 public NodeStatus getStatus() {208 Set<NodeStatus.Active> actives = new HashSet<>();209 if (running != null) {210 actives.add(new NodeStatus.Active(CAPS, running.getId(), running.getCapabilities()));211 }212 return new NodeStatus(213 getId(),214 getUri(),215 1,216 ImmutableMap.of(CAPS, 1),217 actives);218 }219 @Override220 public HealthCheck getHealthCheck() {221 return () -> new HealthCheck.Result(true, "tl;dr");222 }223 }224}...

Full Screen

Full Screen

NodeStatus

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.NodeStatus;2import org.openqa.selenium.grid.data.Session;3import org.openqa.selenium.grid.data.SessionId;4import org.openqa.selenium.grid.data.SessionRequest;5import org.openqa.selenium.grid.data.SessionRequest.SessionRequestOptions;6import org.openqa.selenium.grid.data.SessionRequest.SessionRequestOptions.SessionRequestOptionsBuilder;7import org.openqa.selenium.grid.data.SessionRequest.SessionRequestType;8import org.openqa.selenium.grid.data.SessionRequest.SessionRequestType.SessionRequestTypeBuilder;9import org.openqa.selenium.grid.data.SessionRequest.SessionRequestType.SessionRequestTypeBuilder.SessionRequestTypeBuilderBuilder;10import org.openqa.selenium.grid.data.SessionRequest.SessionRequestType.SessionRequestTypeBuilder.SessionRequestTypeBuilderBuilder.SessionRequestTypeBuilderBuilderBuilder;11import org.openqa.selenium.grid.data.SessionRequest.SessionRequestType.SessionRequestTypeBuilder.SessionRequestTypeBuilderBuilder.SessionRequestTypeBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilder;12import org.openqa.selenium.grid.data.SessionRequest.SessionRequestType.SessionRequestTypeBuilder.SessionRequestTypeBuilderBuilder.SessionRequestTypeBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilderBuilder;13import org.openqa.selenium.grid.data.SessionRequest.SessionRequestType.SessionRequestTypeBuilder.SessionRequestTypeBuilderBuilder.SessionRequestTypeBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilderBuilderBuilder;14import org.openqa.selenium.grid.data.SessionRequest.SessionRequestType.SessionRequestTypeBuilder.SessionRequestTypeBuilderBuilder.SessionRequestTypeBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilderBuilderBuilderBuilder;15import org.openqa.selenium.grid.data.SessionRequest.SessionRequestType.SessionRequestTypeBuilder.SessionRequestTypeBuilderBuilder.SessionRequestTypeBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilderBuilderBuilderBuilder;16import org.openqa.selenium.grid.data.SessionRequest.SessionRequestType.SessionRequestTypeBuilder.SessionRequestTypeBuilderBuilder.SessionRequestTypeBuilderBuilderBuilder.SessionRequestTypeBuilderBuilderBuilderBuilder.SessionRequest

Full Screen

Full Screen

NodeStatus

Using AI Code Generation

copy

Full Screen

1package com.automationrhapsody.selenium.grid;2import org.openqa.selenium.grid.data.NodeStatus;3import org.openqa.selenium.grid.data.NodeStatusEvent;4import org.openqa.selenium.grid.data.NodeStatusEvent.NodeStatusListener;5import org.openqa.selenium.grid.distributor.local.LocalDistributor;6import org.openqa.selenium.grid.distributor.local.StickyStrategy;7import org.openqa.selenium.grid.node.local.LocalNode;8import org.openqa.selenium.net.PortProber;9import org.openqa.selenium.remote.http.HttpClient;10import org.openqa.selenium.remote.http.HttpClient.Factory;11import org.openqa.selenium.remote.http.HttpMethod;12import org.openqa.selenium.remote.http.HttpRequest;13import org.openqa.selenium.remote.http.HttpResponse;14import org.openqa.selenium.remote.tracing.DefaultTestTracer;15import org.openqa.selenium.remote.tracing.Tracer;16import java.io.IOException;17import java.net.URI;18import java.net.URISyntaxException;19import java.util.concurrent.TimeUnit;20import java.util.concurrent.TimeoutException;21public class DistributorNodeStatusExample {22 public static void main(String[] args) throws URISyntaxException, IOException, TimeoutException, InterruptedException {23 Tracer tracer = DefaultTestTracer.createTracer();24 Factory factory = HttpClient.Factory.createDefault();25 int distributorPort = PortProber.findFreePort();26 LocalDistributor distributor = new LocalDistributor(tracer, factory, distributorUri, new StickyStrategy());27 distributor.start();28 int nodePort = PortProber.findFreePort();29 LocalNode node = LocalNode.builder(tracer, factory, nodeUri)30 .add(caps -> true, req -> HttpResponse.notFound())31 .build();32 node.start();33 HttpRequest registerRequest = new HttpRequest(HttpMethod.POST, "/session/node");34 registerRequest.setContent(nodeUri.toURL());35 HttpResponse registerResponse = factory.createClient(distributorUri).execute(registerRequest);36 if (registerResponse.getStatus() != 200) {37 throw new IllegalStateException("Unable to register the node to the distributor.");38 }39 distributor.addListener(new NodeStatusListener() {40 public void onSessionCreated(NodeStatusEvent event) {41 NodeStatus nodeStatus = event.getNodeStatus();42 System.out.println("Node " + nodeStatus.getId() + " has created a session.");43 }

Full Screen

Full Screen

NodeStatus

Using AI Code Generation

copy

Full Screen

1NodeStatus nodeStatus = new NodeStatus(2 new NodeId("nodeId"),3 new NodeStatus.State("UP"),4 ImmutableMap.of(),5 new SlotCount(1),6 new SlotCount(1));7System.out.println(nodeStatus.toJson());8{9 "id" : {10 },11 "maxSessionCount" : {12 },13 "sessionCount" : {14 }15}16The following code shows how to use the toJson() method:17NodeStatus nodeStatus = new NodeStatus(18 new NodeId("nodeId"),19 new NodeStatus.State("UP"),20 ImmutableMap.of(),21 new SlotCount(1),22 new SlotCount(1));23System.out.println(nodeStatus.toJson());24{25 "id" : {26 },27 "maxSessionCount" : {28 },29 "sessionCount" : {30 }31}32The following code shows how to use the fromJson() method:33NodeStatus nodeStatus = new NodeStatus(34 new NodeId("nodeId"),35 new NodeStatus.State("UP"),36 ImmutableMap.of(),

Full Screen

Full Screen
copy
1Map<String,String> sample = new HashMap<>();2sample.put("A","Apple");3sample.put("B", "Ball");4
Full Screen
copy
1HashMap<Integer,Integer> hm = new HashMap<Integer, Integer>();2/*3 * Logic to put the Key,Value pair in your HashMap hm4 */56// Print the key value pair in one line.78hm.forEach((k, v) -> System.out.println("key: " + k + " value:" + v));910// Just copy and paste above line to your code.11
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.

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