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

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

Source:KubernetesNode.java Github

copy

Full Screen

...124 var factories = createFactories(k8sOptions, tracer, clientFactory, bus, k8s);125 LOG.info("Creating kubernetes node");126 return new KubernetesNode(tracer, bus, secretOptions.getRegistrationSecret(), new NodeId(UUID.randomUUID()),127 serverOptions.getExternalUri(), factories, k8sOptions.getMaxSessions(), k8sOptions.getSessionTimeout(),128 k8sOptions.getHeartbeatPeriod()129 );130 }131 static List<SessionSlot> createFactories(KubernetesOptions k8sOptions, Tracer tracer,132 HttpClient.Factory clientFactory, EventBus eventBus,133 KubernetesDriver driver) {134 var configs = k8sOptions.getConfigs();135 if (configs.isEmpty()) {136 throw new ConfigException("Unable to find kubernetes configs");137 }138 return configs.stream().flatMap(c -> Collections.nCopies(k8sOptions.getMaxSessions(), c).stream())139 .map(config -> {140 var image = config.getImage();141 var stereoType = config.getStereoType();142 var factory = new KubernetesSessionFactory(tracer, clientFactory, driver,...

Full Screen

Full Screen

Source:GridModel.java Github

copy

Full Screen

...182 break;183 }184 Instant now = Instant.now();185 Instant lastTouched = nodePurgeTimes.getOrDefault(id, Instant.now());186 Instant lostTime = lastTouched.plus(node.getHeartbeatPeriod().multipliedBy(PURGE_TIMEOUT_MULTIPLIER / 2));187 Instant deadTime = lastTouched.plus(node.getHeartbeatPeriod().multipliedBy(PURGE_TIMEOUT_MULTIPLIER));188 if (node.getAvailability() == UP && lostTime.isBefore(now)) {189 LOG.info(String.format("Switching Node %s from UP to DOWN", node.getExternalUri()));190 replacements.put(node, rewrite(node, DOWN));191 }192 if (node.getAvailability() == DOWN && deadTime.isBefore(now)) {193 LOG.info(String.format("Removing Node %s, DOWN for too long", node.getExternalUri()));194 toRemove.add(node);195 }196 }197 replacements.forEach((before, after) -> {198 nodes.remove(before);199 nodes.add(after);200 });201 toRemove.forEach(node -> {202 nodes.remove(node);203 nodePurgeTimes.remove(node.getNodeId());204 nodeHealthCount.remove(node.getNodeId());205 events.fire(new NodeRemovedEvent(node));206 });207 } finally {208 writeLock.unlock();209 }210 }211 public Availability setAvailability(NodeId id, Availability availability) {212 Require.nonNull("Node ID", id);213 Require.nonNull("Availability", availability);214 Lock writeLock = lock.writeLock();215 writeLock.lock();216 try {217 NodeStatus node = getNode(id);218 if (node == null) {219 return DOWN;220 }221 if (availability.equals(node.getAvailability())) {222 if (node.getAvailability() == UP) {223 nodePurgeTimes.put(node.getNodeId(), Instant.now());224 }225 return availability;226 }227 LOG.info(String.format(228 "Switching node %s (uri: %s) from %s to %s",229 id,230 node.getExternalUri(),231 node.getAvailability(),232 availability));233 Availability previous = node.getAvailability();234 NodeStatus refreshed = rewrite(node, availability);235 nodes.remove(node);236 nodes.add(refreshed);237 nodePurgeTimes.put(node.getNodeId(), Instant.now());238 return previous;239 } finally {240 writeLock.unlock();241 }242 }243 public boolean reserve(SlotId slotId) {244 Lock writeLock = lock.writeLock();245 writeLock.lock();246 try {247 NodeStatus node = getNode(slotId.getOwningNodeId());248 if (node == null) {249 LOG.warning(String.format("Asked to reserve slot on node %s, but unable to find node", slotId.getOwningNodeId()));250 return false;251 }252 if (!UP.equals(node.getAvailability())) {253 LOG.warning(String.format(254 "Asked to reserve a slot on node %s, but node is %s",255 slotId.getOwningNodeId(),256 node.getAvailability()));257 return false;258 }259 Optional<Slot> maybeSlot = node.getSlots().stream()260 .filter(slot -> slotId.equals(slot.getId()))261 .findFirst();262 if (!maybeSlot.isPresent()) {263 LOG.warning(String.format(264 "Asked to reserve slot on node %s, but no slot with id %s found",265 node.getNodeId(),266 slotId));267 return false;268 }269 reserve(node, maybeSlot.get());270 return true;271 } finally {272 writeLock.unlock();273 }274 }275 public Set<NodeStatus> getSnapshot() {276 Lock readLock = this.lock.readLock();277 readLock.lock();278 try {279 return ImmutableSet.copyOf(nodes);280 } finally {281 readLock.unlock();282 }283 }284 private NodeStatus getNode(NodeId id) {285 Require.nonNull("Node ID", id);286 Lock readLock = lock.readLock();287 readLock.lock();288 try {289 return nodes.stream()290 .filter(n -> n.getNodeId().equals(id))291 .findFirst()292 .orElse(null);293 } finally {294 readLock.unlock();295 }296 }297 private NodeStatus rewrite(NodeStatus status, Availability availability) {298 return new NodeStatus(299 status.getNodeId(),300 status.getExternalUri(),301 status.getMaxSessionCount(),302 status.getSlots(),303 availability,304 status.getHeartbeatPeriod(),305 status.getVersion(),306 status.getOsInfo());307 }308 public void release(SessionId id) {309 if (id == null) {310 return;311 }312 Lock writeLock = lock.writeLock();313 writeLock.lock();314 try {315 for (NodeStatus node : nodes) {316 for (Slot slot : node.getSlots()) {317 if (slot.getSession()==null) {318 continue;319 }320 if (id.equals(slot.getSession().getId())) {321 Slot released = new Slot(322 slot.getId(),323 slot.getStereotype(),324 slot.getLastStarted(),325 null);326 amend(node.getAvailability(), node, released);327 return;328 }329 }330 }331 } finally {332 writeLock.unlock();333 }334 }335 public void reserve(NodeStatus status, Slot slot) {336 Instant now = Instant.now();337 Slot reserved = new Slot(338 slot.getId(),339 slot.getStereotype(),340 now,341 new Session(342 RESERVED,343 status.getExternalUri(),344 slot.getStereotype(),345 slot.getStereotype(),346 now));347 amend(UP, status, reserved);348 }349 public void setSession(SlotId slotId, Session session) {350 Require.nonNull("Slot ID", slotId);351 Lock writeLock = lock.writeLock();352 writeLock.lock();353 try {354 NodeStatus node = getNode(slotId.getOwningNodeId());355 if (node == null) {356 LOG.warning("Grid model and reality have diverged. Unable to find node " + slotId.getOwningNodeId());357 return;358 }359 Optional<Slot> maybeSlot = node.getSlots().stream()360 .filter(slot -> slotId.equals(slot.getId()))361 .findFirst();362 if (!maybeSlot.isPresent()) {363 LOG.warning("Grid model and reality have diverged. Unable to find slot " + slotId);364 return;365 }366 Slot slot = maybeSlot.get();367 Session maybeSession = slot.getSession();368 if (maybeSession == null) {369 LOG.warning("Grid model and reality have diverged. Slot is not reserved. " + slotId);370 return;371 }372 if (!RESERVED.equals(maybeSession.getId())) {373 LOG.warning(374 "Grid model and reality have diverged. Slot has session and is not reserved. " + slotId);375 return;376 }377 Slot updated = new Slot(378 slot.getId(),379 slot.getStereotype(),380 session == null ? slot.getLastStarted() : session.getStartTime(),381 session);382 amend(node.getAvailability(), node, updated);383 } finally {384 writeLock.unlock();385 }386 }387 public void updateHealthCheckCount(NodeId id, Availability availability) {388 Require.nonNull("Node ID", id);389 Require.nonNull("Availability", availability);390 Lock writeLock = lock.writeLock();391 writeLock.lock();392 try {393 int unhealthyCount = nodeHealthCount.getOrDefault(id, 0);394 // Keep track of consecutive number of times the Node health check fails395 if (availability.equals(DOWN)) {396 nodeHealthCount.put(id, unhealthyCount + 1);397 }398 // If the Node is healthy again before crossing the threshold, then reset the count.399 if (unhealthyCount <= UNHEALTHY_THRESHOLD && availability.equals(UP)) {400 nodeHealthCount.put(id, 0);401 }402 } finally {403 writeLock.unlock();404 }405 }406 private void amend(Availability availability, NodeStatus status, Slot slot) {407 Set<Slot> newSlots = new HashSet<>(status.getSlots());408 newSlots.removeIf(s -> s.getId().equals(slot.getId()));409 newSlots.add(slot);410 NodeStatus node = getNode(status.getNodeId());411 Lock writeLock = lock.writeLock();412 writeLock.lock();413 try {414 nodes.remove(node);415 nodes.add(new NodeStatus(416 status.getNodeId(),417 status.getExternalUri(),418 status.getMaxSessionCount(),419 newSlots,420 availability,421 status.getHeartbeatPeriod(),422 status.getVersion(),423 status.getOsInfo()));424 } finally {425 writeLock.unlock();426 }427 }428}...

Full Screen

Full Screen

Source:OneShotNode.java Github

copy

Full Screen

...132 return new OneShotNode(133 loggingOptions.getTracer(),134 eventOptions.getEventBus(),135 secretOptions.getRegistrationSecret(),136 nodeOptions.getHeartbeatPeriod(),137 new NodeId(UUID.randomUUID()),138 serverOptions.getExternalUri(),139 nodeOptions.getPublicGridUri().orElseThrow(() -> new ConfigException("Unable to determine public grid address")),140 stereotype,141 driverInfo);142 }143 @Override144 public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessionRequest sessionRequest) {145 if (driver != null) {146 throw new IllegalStateException("Only expected one session at a time");147 }148 Optional<WebDriver> driver = driverInfo.createDriver(sessionRequest.getDesiredCapabilities());149 if (!driver.isPresent()) {150 return Either.left(new WebDriverException("Unable to create a driver instance"));...

Full Screen

Full Screen

Source:GridStatusHandler.java Github

copy

Full Screen

...109 .put("id", node.getNodeId())110 .put("uri", node.getExternalUri())111 .put("maxSessions", node.getMaxSessionCount())112 .put("osInfo", node.getOsInfo())113 .put("heartbeatPeriod", node.getHeartbeatPeriod().toMillis())114 .put("availability", node.getAvailability())115 .put("version", node.getVersion())116 .put("slots", node.getSlots())117 .build())118 .collect(toList());119 ImmutableMap.Builder<String, Object> value = ImmutableMap.builder();120 value.put("ready", ready);121 value.put("message", ready ? "Selenium Grid ready." : "Selenium Grid not ready.");122 value.put("nodes", nodeResults);123 HttpResponse res = new HttpResponse()124 .setContent(asJson(ImmutableMap.of("value", value.build())));125 HTTP_RESPONSE.accept(span, res);126 HTTP_RESPONSE_EVENT.accept(attributeMap, res);127 attributeMap.put("grid.status", EventAttribute.setValue(ready));...

Full Screen

Full Screen

Source:NodeStatus.java Github

copy

Full Screen

...136 }137 public Availability getAvailability() {138 return availability;139 }140 public Duration getHeartbeatPeriod() {141 return heartbeatPeriod;142 }143 public String getVersion() {144 return version;145 }146 public Map<String, String> getOsInfo() {147 return osInfo;148 }149 public float getLoad() {150 float inUse = slots.parallelStream()151 .filter(slot -> slot.getSession() != null)152 .count();153 return (inUse / (float) maxSessionCount) * 100f;154 }...

Full Screen

Full Screen

Source:GridRedisClient.java Github

copy

Full Screen

...118 node.getExternalUri(),119 node.getMaxSessionCount(),120 node.getSlots(),121 node.getAvailability(),122 node.getHeartbeatPeriod(),123 node.getVersion(),124 node.getOsInfo());125 return Optional.of(resultNode);126 }127 return maybeNode;128 }129 public void removeAllNodes(Set<NodeId> nodeIds) {130 nodeIds.forEach(this::removeNode);131 }132 public Set<NodeStatus> getNodes(Set<NodeId> nodeIds) {133 return nodeIds.stream()134 .filter(nodeId -> getNode(nodeId).isPresent())135 .map(nodeId -> getNode(nodeId).get())136 .collect(Collectors.toSet());...

Full Screen

Full Screen

getHeartbeatPeriod

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.NodeStatus;2NodeStatus nodeStatus = new NodeStatus();3int heartbeatPeriod = nodeStatus.getHeartbeatPeriod();4System.out.println("Heartbeat Period: " + heartbeatPeriod);5Recommended Posts: How to use getHeartbeatPeriod() method of org.openqa.selenium.grid.data.NodeStatus class?6How to use getSlot() method of org.openqa.selenium.grid.data.NodeStatus class?7How to use getSlots() method of org.openqa.selenium.grid.data.NodeStatus class?8How to use getUri() method of org.openqa.selenium.grid.data.NodeStatus class?9How to use getUri() method of org.openqa.selenium.grid.data.Session class?10How to use getCapabilities() method of org.openqa.selenium.grid.data.Session class?11How to use getDialects() method of org.openqa.selenium.grid.data.Session class?12How to use getDownstreamDialects() method of org.openqa.selenium.grid.data.Session class?13How to use getDownstreamStatus() method of org.openqa.selenium.grid.data.Session class?14How to use getDownstreamUri() method of org.openqa.selenium.grid.data.Session class?15How to use getId() method of org.openqa.selenium.grid.data.Session class?16How to use getStartTime() method of org.openqa.selenium.grid.data.Session class?17How to use getStatus() method of org.openqa.selenium.grid.data.Session class?18How to use getUpstreamDialects() method of org.openqa.selenium.grid.data.Session class?19How to use getUpstreamStatus() method of org.openqa.selenium.grid.data.Session class?20How to use getUpstreamUri() method of org.openqa.selenium.grid.data.Session class?21How to use getUri() method of org.openqa.selenium.grid.data.Session class?22How to use getCapabilities() method of org.openqa.selenium.grid.data.Slot class?23How to use getStartTime() method of org.openqa.selenium.grid.data.Slot class?24How to use getStatus() method of org.openqa.selenium.grid.data.Slot class?25How to use getUri() method of org.openqa.selenium.grid.data.Slot class?26How to use getUri() method of org.openqa.selenium.grid.data.SessionRequest class?27How to use getCapabilities() method of org.openqa.selenium.grid.data.SessionRequest class?28How to use getDownstreamDialects() method of org.openqa.selenium.grid.data.SessionRequest class?29How to use getDownstreamUri() method of org.openqa.selenium.grid.data.SessionRequest class?

Full Screen

Full Screen

getHeartbeatPeriod

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.NodeStatus;2NodeStatus nodeStatus = new NodeStatus();3int heartbeatPeriod = nodeStatus.getHeartbeatPeriod();4import org.openqa.selenium.grid.data.NodeStatus;5NodeStatus nodeStatus = new NodeStatus();6int heartbeatPeriod = nodeStatus.getHeartbeatPeriod();7import org.openqa.selenium.grid.data.NodeStatus;8NodeStatus nodeStatus = new NodeStatus();9int heartbeatPeriod = nodeStatus.getHeartbeatPeriod();10import org.openqa.selenium.grid.data.NodeStatus;11NodeStatus nodeStatus = new NodeStatus();12int heartbeatPeriod = nodeStatus.getHeartbeatPeriod();13import org.openqa.selenium.grid.data.NodeStatus;14NodeStatus nodeStatus = new NodeStatus();15int heartbeatPeriod = nodeStatus.getHeartbeatPeriod();16import org.openqa.selenium.grid.data.NodeStatus;17NodeStatus nodeStatus = new NodeStatus();18int heartbeatPeriod = nodeStatus.getHeartbeatPeriod();19import org.openqa.selenium.grid.data.NodeStatus;20NodeStatus nodeStatus = new NodeStatus();21int heartbeatPeriod = nodeStatus.getHeartbeatPeriod();22import org.openqa.selenium.grid.data.NodeStatus;23NodeStatus nodeStatus = new NodeStatus();24int heartbeatPeriod = nodeStatus.getHeartbeatPeriod();25import org.openqa.selenium.grid.data.NodeStatus;26NodeStatus nodeStatus = new NodeStatus();27int heartbeatPeriod = nodeStatus.getHeartbeatPeriod();28import org.openqa.selenium.grid.data.NodeStatus;29NodeStatus nodeStatus = new NodeStatus();30int heartbeatPeriod = nodeStatus.getHeartbeatPeriod();31import org.openqa.selenium.grid.data.NodeStatus;32NodeStatus nodeStatus = new NodeStatus();

Full Screen

Full Screen

getHeartbeatPeriod

Using AI Code Generation

copy

Full Screen

1long heartbeatPeriod = nodeStatus.getHeartbeatPeriod();2System.out.println("heartbeatPeriod = " + heartbeatPeriod);3org.openqa.selenium.grid.data.NodeStatus.getHeartbeatPeriod()4Recommended Posts: Selenium | getHost() method in Java5Selenium | getPort() method in Java6Selenium | getUri() method in Java7Selenium | getProtocol() method in Java8Selenium | getHost() method in Java9Selenium | getPort() method in Java10Selenium | getUri() method in Java11Selenium | getProtocol() method in Java12Selenium | getHost() method in Java13Selenium | getPort() method in Java14Selenium | getUri() method in Java15Selenium | getProtocol() method in Java16Selenium | getHost() method in Java17Selenium | getPort() method in Java18Selenium | getUri() method in Java19Selenium | getProtocol() method in Java20Selenium | getHost() method in Java21Selenium | getPort() method in Java22Selenium | getUri() method in Java23Selenium | getProtocol() method in Java24Selenium | getHost() method in Java25Selenium | getPort() method in Java26Selenium | getUri() method in Java27Selenium | getProtocol() method in Java28Selenium | getHost() method in Java29Selenium | getPort() method in Java30Selenium | getUri() method in Java31Selenium | getProtocol() method in Java32Selenium | getHost() method in Java33Selenium | getPort() method in Java34Selenium | getUri() method in Java35Selenium | getProtocol() method in Java36Selenium | getHost() method in Java37Selenium | getPort() method in Java38Selenium | getUri() method in Java39Selenium | getProtocol() method in Java40Selenium | getHost() method in Java41Selenium | getPort() method in Java42Selenium | getUri() method in Java43Selenium | getProtocol() method in Java44Selenium | getHost() method in Java45Selenium | getPort() method in Java46Selenium | getUri() method in Java47Selenium | getProtocol() method in Java

Full Screen

Full Screen

getHeartbeatPeriod

Using AI Code Generation

copy

Full Screen

1public static void main(String[] args) {2 NodeStatus nodeStatus = NodeStatus.create(3 Duration.ofSeconds(10),4 Duration.ofSeconds(20),5 Duration.ofSeconds(30),6 Collections.emptyList());7 System.out.println(nodeStatus.getHeartbeatPeriod());8}9public static void main(String[] args) {10 NodeStatus nodeStatus = NodeStatus.create(11 Duration.ofSeconds(10),12 Duration.ofSeconds(20),13 Duration.ofSeconds(30),14 Collections.emptyList());15 System.out.println(nodeStatus.getHeartbeatPeriod().getSeconds());16}17public static void main(String[] args) {18 NodeStatus nodeStatus = NodeStatus.create(19 Duration.ofSeconds(10),20 Duration.ofSeconds(20),21 Duration.ofSeconds(30),22 Collections.emptyList());23 System.out.println(nodeStatus.getHeartbeatPeriod().toMillis());24}25public static void main(String[] args) {26 NodeStatus nodeStatus = NodeStatus.create(27 Duration.ofSeconds(10),28 Duration.ofSeconds(20),29 Duration.ofSeconds(30),30 Collections.emptyList());31 System.out.println(nodeStatus.getHeartbeatPeriod().getNano());32}

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