How to use equals method of org.openqa.selenium.grid.data.NodeId class

Best Selenium code snippet using org.openqa.selenium.grid.data.NodeId.equals

Source:AddingNodesTest.java Github

copy

Full Screen

...279 throw new UnsupportedOperationException("uploadFile");280 }281 @Override282 public Session getSession(SessionId id) throws NoSuchSessionException {283 if (running == null || !running.getId().equals(id)) {284 throw new NoSuchSessionException();285 }286 return running;287 }288 @Override289 public void stop(SessionId id) throws NoSuchSessionException {290 getSession(id);291 running = null;292 bus.fire(new SessionClosedEvent(id));293 }294 @Override295 public boolean isSessionOwner(SessionId id) {296 return running != null && running.getId().equals(id);297 }298 @Override299 public boolean isSupporting(Capabilities capabilities) {300 return Objects.equals("cake", capabilities.getCapability("cheese"));301 }302 @Override303 public NodeStatus getStatus() {304 Session sess = null;305 if (running != null) {306 try {307 sess = new Session(308 running.getId(),309 new URI("http://localhost:14568"),310 CAPS,311 running.getCapabilities(),312 Instant.now());313 } catch (URISyntaxException e) {314 throw new RuntimeException(e);...

Full Screen

Full Screen

Source:GridModel.java Github

copy

Full Screen

...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) {...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

...116 }117 private void register(Secret registrationSecret, NodeStatus status) {118 Require.nonNull("Node", status);119 Secret nodeSecret = status.getRegistrationSecret() == null ? null : new Secret(status.getRegistrationSecret());120 if (!Objects.equals(registrationSecret, nodeSecret)) {121 LOG.severe(String.format("Node at %s failed to send correct registration secret. Node NOT registered.", status.getUri()));122 bus.fire(new NodeRejectedEvent(status.getUri()));123 return;124 }125 Lock writeLock = lock.writeLock();126 writeLock.lock();127 try {128 if (nodes.containsKey(status.getId())) {129 return;130 }131 Set<Capabilities> capabilities = status.getSlots().stream()132 .map(Slot::getStereotype)133 .map(ImmutableCapabilities::copyOf)134 .collect(toImmutableSet());135 // A new node! Add this as a remote node, since we've not called add136 RemoteNode remoteNode = new RemoteNode(137 tracer,138 clientFactory,139 status.getId(),140 status.getUri(),141 registrationSecret,142 capabilities);143 add(remoteNode);144 } finally {145 writeLock.unlock();146 }147 }148 @Override149 public LocalDistributor add(Node node) {150 Require.nonNull("Node", node);151 LOG.info(String.format("Added node %s at %s.", node.getId(), node.getUri()));152 nodes.put(node.getId(), node);153 model.add(node.getStatus());154 // Extract the health check155 Runnable runnableHealthCheck = asRunnableHealthCheck(node);156 allChecks.put(node.getId(), runnableHealthCheck);157 hostChecker.submit(runnableHealthCheck, Duration.ofMinutes(5), Duration.ofSeconds(30));158 bus.fire(new NodeAddedEvent(node.getId()));159 return this;160 }161 private Runnable asRunnableHealthCheck(Node node) {162 HealthCheck healthCheck = node.getHealthCheck();163 NodeId id = node.getId();164 return () -> {165 HealthCheck.Result result;166 try {167 result = healthCheck.check();168 } catch (Exception e) {169 LOG.log(Level.WARNING, "Unable to process node " + id, e);170 result = new HealthCheck.Result(DOWN, "Unable to run healthcheck. Assuming down");171 }172 Lock writeLock = lock.writeLock();173 writeLock.lock();174 try {175 model.setAvailability(id, result.getAvailability());176 } finally {177 writeLock.unlock();178 }179 };180 }181 @Override182 public boolean drain(NodeId nodeId) {183 Node node = nodes.get(nodeId);184 if (node == null) {185 LOG.info("Asked to drain unregistered node " + nodeId);186 return false;187 }188 Lock writeLock = lock.writeLock();189 writeLock.lock();190 try {191 node.drain();192 model.setAvailability(nodeId, DRAINING);193 } finally {194 writeLock.unlock();195 }196 return node.isDraining();197 }198 public void remove(NodeId nodeId) {199 Lock writeLock = lock.writeLock();200 writeLock.lock();201 try {202 model.remove(nodeId);203 Runnable runnable = allChecks.remove(nodeId);204 if (runnable != null) {205 hostChecker.remove(runnable);206 }207 } finally {208 writeLock.unlock();209 bus.fire(new NodeRemovedEvent(nodeId));210 }211 }212 @Override213 public DistributorStatus getStatus() {214 Lock readLock = this.lock.readLock();215 readLock.lock();216 try {217 return new DistributorStatus(model.getSnapshot());218 } finally {219 readLock.unlock();220 }221 }222 @Beta223 public void refresh() {224 List<Runnable> allHealthChecks = new ArrayList<>();225 Lock readLock = this.lock.readLock();226 readLock.lock();227 try {228 allHealthChecks.addAll(allChecks.values());229 } finally {230 readLock.unlock();231 }232 allHealthChecks.parallelStream().forEach(Runnable::run);233 }234 @Override235 protected Set<NodeStatus> getAvailableNodes() {236 Lock readLock = this.lock.readLock();237 readLock.lock();238 try {239 return model.getSnapshot().stream()240 .filter(node -> !DOWN.equals(node.getAvailability()))241 .collect(toImmutableSet());242 } finally {243 readLock.unlock();244 }245 }246 @Override247 protected Supplier<CreateSessionResponse> reserve(SlotId slotId, CreateSessionRequest request) {248 Require.nonNull("Slot ID", slotId);249 Require.nonNull("New Session request", request);250 Lock writeLock = this.lock.writeLock();251 writeLock.lock();252 try {253 Node node = nodes.get(slotId.getOwningNodeId());254 if (node == null) {...

Full Screen

Full Screen

Source:Host.java Github

copy

Full Screen

...218 public int hashCode() {219 return Objects.hash(nodeId, uri);220 }221 @Override222 public boolean equals(Object obj) {223 if (!(obj instanceof Host)) {224 return false;225 }226 Host that = (Host) obj;227 return this.node.equals(that.node);228 }229}...

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1public class NodeIdTest {2 public static void main(String[] args) {3 NodeId nodeId = new NodeId(UUID.randomUUID());4 NodeId nodeId2 = new NodeId(UUID.randomUUID());5 System.out.println(nodeId.equals(nodeId2));6 }7}

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.NodeId;2public class NodeIdEqualsExample {3 public static void main(String[] args) {4 NodeId nodeId1 = new NodeId("node1");5 NodeId nodeId2 = new NodeId("node1");6 NodeId nodeId3 = new NodeId("node2");7 System.out.println("nodeId1 equals nodeId2: " + nodeId1.equals(nodeId2));8 System.out.println("nodeId1 equals nodeId3: " + nodeId1.equals(nodeId3));9 }10}

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1NodeId id1 = new NodeId(UUID.randomUUID());2NodeId id2 = new NodeId(UUID.randomUUID());3System.out.println("id1: " + id1 + " id2: " + id2);4System.out.println("id1.equals(id2): " + id1.equals(id2));5System.out.println("id1.equals(id1): " + id1.equals(id1));6id1.equals(id2): false7id1.equals(id1): true8SessionId id1 = new SessionId(UUID.randomUUID());9SessionId id2 = new SessionId(UUID.randomUUID());10System.out.println("id1: " + id1 + " id2: " + id2);11System.out.println("id1.equals(id2): " + id1.equals(id2));12System.out.println("id1.equals(id1): " + id1.equals(id1));13id1.equals(id2): false14id1.equals(id1): true15SlotId id1 = new SlotId(UUID.randomUUID());16SlotId id2 = new SlotId(UUID.randomUUID());17System.out.println("id1: " + id1 + " id2: " + id2);18System.out.println("id1.equals(id2): " + id1.equals(id2));19System.out.println("id1.equals(id1): " + id1.equals(id1));

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1NodeId nodeId = new NodeId(UUID.randomUUID());2NodeId nodeId2 = new NodeId(UUID.randomUUID());3System.out.println(nodeId.equals(nodeId2));4SessionId sessionId = new SessionId(UUID.randomUUID());5SessionId sessionId2 = new SessionId(UUID.randomUUID());6System.out.println(sessionId.equals(sessionId2));7SlotId slotId = new SlotId(UUID.randomUUID());8SlotId slotId2 = new SlotId(UUID.randomUUID());9System.out.println(slotId.equals(slotId2));10SessionRequest sessionRequest = new SessionRequest(UUID.randomUUID(), new ImmutableCapabilities(), new ImmutableCapabilities(), new ImmutableCapabilities());11SessionRequest sessionRequest2 = new SessionRequest(UUID.randomUUID(), new ImmutableCapabilities(), new ImmutableCapabilities(), new ImmutableCapabilities());12System.out.println(sessionRequest.equals(sessionRequest2));13Session session = new Session(UUID.randomUUID(), new ImmutableCapabilities(), new ImmutableCapabilities(), new ImmutableCapabilities());14Session session2 = new Session(UUID.randomUUID(), new ImmutableCapabilities(), new ImmutableCapabilities(), new ImmutableCapabilities());15System.out.println(session.equals(session2));16Slot slot = new Slot(new SlotId(UUID.randomUUID()), new NodeId(UUID.randomUUID()), new ImmutableCapabilities(), new ImmutableCapabilities(), new ImmutableCapabilities());17Slot slot2 = new Slot(new SlotId(UUID.randomUUID()), new NodeId(UUID.randomUUID()), new ImmutableCapabilities(), new ImmutableCapabilities(), new ImmutableCapabilities());18System.out.println(slot.equals(slot2));19NewSessionQueuedEvent newSessionQueuedEvent = new NewSessionQueuedEvent(UUID.randomUUID(), new ImmutableCapabilities(), new ImmutableCapabilities(), new ImmutableCapabilities());20NewSessionQueuedEvent newSessionQueuedEvent2 = new NewSessionQueuedEvent(UUID.randomUUID(), new ImmutableCapabilities(), new ImmutableCapabilities(), new ImmutableCapabilities());21System.out.println(newSessionQueuedEvent.equals(newSessionQueuedEvent2));

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 NodeId

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful