How to use drain method of org.openqa.selenium.grid.distributor.local.LocalDistributor class

Best Selenium code snippet using org.openqa.selenium.grid.distributor.local.LocalDistributor.drain

Source:AddingNodesTest.java Github

copy

Full Screen

...310 public HealthCheck getHealthCheck() {311 return () -> new HealthCheck.Result(UP, "tl;dr");312 }313 @Override314 public void drain() {315 }316 }317}...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

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

Full Screen

Full Screen

Source:LocalDistributorTest.java Github

copy

Full Screen

...176 Set<NodeStatus> nodesBefore = statusBefore.getNodes();177 assertThat(nodesBefore.size()).isEqualTo(1);178 NodeStatus nodeBefore = nodesBefore.iterator().next();179 assertThat(nodeBefore.getAvailability()).isNotEqualTo(DRAINING);180 distributor.drain(localNode.getId());181 assertThat(localNode.isDraining()).isTrue();182 //Recheck the status - there should still be no node, it is removed183 DistributorStatus statusAfter = distributor.getStatus();184 Set<NodeStatus> nodesAfter = statusAfter.getNodes();185 assertThat(nodesAfter.size()).isEqualTo(0);186 }187 @Test188 public void testDrainNodeFromNode() {189 assertThat(localNode.isDraining()).isFalse();190 Distributor191 distributor =192 new LocalDistributor(tracer, bus, clientFactory, new LocalSessionMap(tracer, bus), null);193 distributor.add(localNode);194 localNode.drain();195 assertThat(localNode.isDraining()).isTrue();196 }197 private class Handler extends Session implements HttpHandler {198 private Handler(Capabilities capabilities) {199 super(new SessionId(UUID.randomUUID()), uri, new ImmutableCapabilities(), capabilities, Instant.now());200 }201 @Override202 public HttpResponse execute(HttpRequest req) throws UncheckedIOException {203 return new HttpResponse();204 }205 }206}...

Full Screen

Full Screen

drain

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.config.Config;2import org.openqa.selenium.grid.config.MapConfig;3import org.openqa.selenium.grid.distributor.local.LocalDistributor;4import org.openqa.selenium.grid.server.BaseServerOptions;5import org.openqa.selenium.grid.server.Server;6import org.openqa.selenium.grid.server.ServerFlags;7import org.openqa.selenium.grid.web.Routable;8import org.openqa.selenium.grid.web.Routes;9import org.openqa.selenium.remote.http.HttpMethod;10import org.openqa.selenium.remote.http.HttpRequest;11import org.openqa.selenium.remote.http.HttpResponse;12import java.util.HashMap;13import java.util.Map;14public class DistributorDrain {15 public static void main(String[] args) {16 Map<String, String> config = new HashMap<>();17 config.put("server", "org.openqa.selenium.grid.server.SeleniumServer");18 config.put("distributor", "org.openqa.selenium.grid.distributor.local.LocalDistributor");19 config.put("max-sessions", "1");20 config.put("port", "4444");21 Config gridConfig = new MapConfig(config);22 ServerFlags flags = new ServerFlags();23 BaseServerOptions serverOptions = new BaseServerOptions(gridConfig);24 Server<?> server = new Server<>(flags, serverOptions, gridConfig);25 LocalDistributor distributor = new LocalDistributor(gridConfig);26 Routes routes = new Routes();27 routes.add(new Routable() {28 public boolean matches(HttpRequest req) {29 return req.getMethod() == HttpMethod.GET && req.getUri().getPath().equals("/drain");30 }31 public HttpResponse execute(HttpRequest req) {32 distributor.drain();33 return new HttpResponse().setContent("Draining");34 }35 });36 server.start(routes);37 }38}39import org.openqa.selenium.grid.config.Config;40import org.openqa.selenium.grid.config.MapConfig;41import org.openqa.selenium.grid.distributor.local.LocalDistributor;42import org.openqa.selenium.grid.server.BaseServerOptions;43import org.openqa.selenium.grid.server.Server;44import org.openqa.selenium.grid.server.ServerFlags;45import org.openqa.selenium.grid.web.Routable;46import org.openqa.selenium.grid.web.Routes;47import org.openqa.selenium.remote.http.HttpMethod;48import org.openqa.selenium.remote.http.HttpRequest;49import org.openqa.selenium.remote.http.HttpResponse;50import java.util.HashMap;51import java.util.Map;52public class DistributorStop {53 public static void main(String[] args) {

Full Screen

Full Screen

drain

Using AI Code Generation

copy

Full Screen

1package com.qa.selenium;2import org.junit.Assert;3import org.junit.Test;4import org.openqa.selenium.By;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.grid.distributor.local.LocalDistributor;9import org.openqa.selenium.grid.web.Values;10import org.openqa.selenium.remote.http.HttpRequest;11import org.openqa.selenium.remote.http.HttpResponse;12import java.io.IOException;13import java.util.ArrayList;14import java.util.List;15public class SeleniumGridDrainMethod {16 public void test() throws IOException {17 LocalDistributor distributor = new LocalDistributor(Values.of("max-sessions", 1));18 HttpRequest request = new HttpRequest(HttpRequest.POST, "/session");19 HttpResponse response = distributor.execute(request);20 String sessionId = response.getHeader("X-Session-ID");21 distributor.drain();22 response = distributor.execute(request);23 String newSessionId = response.getHeader("X-Session-ID");24 Assert.assertNotEquals(sessionId, newSessionId);25 }26}27[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ selenium-grid-drain-method ---28[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ selenium-grid-drain-method ---29[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ selenium-grid-drain-method ---

Full Screen

Full Screen

drain

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.config.Config;2import org.openqa.selenium.grid.config.MapConfig;3import org.openqa.selenium.grid.data.Session;4import org.openqa.selenium.grid.distributor.local.LocalDistributor;5import org.openqa.selenium.grid.log.LoggingOptions;6import org.openqa.selenium.grid.server.BaseServerOptions;7import org.openqa.selenium.grid.server.Server;8import org.openqa.selenium.grid.server.ServerFlags;9import org.openqa.selenium.grid.web.Values;10import org.openqa.selenium.remote.http.HttpClient;11import org.openqa.selenium.remote.http.HttpResponse;12import org.openqa.selenium.remote.tracing.Tracer;13import org.openqa.selenium.remote.tracing.jaeger.JaegerOptions;14import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryOptions;15import org.openqa.selenium.remote.tracing.zipkin.ZipkinOptions;16import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracer;17import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerFactory;18import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptions;19import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptions.LogReporter;20import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptions.ScribeReporter;21import java.io.IOException;22import java.net.URI;23import java.net.URISyntaxException;24import java.util.HashMap;25import java.util.Map;26import java.util.stream.Stream;27public class DistributorDrain {28 public static void main(String[] args) throws URISyntaxException, IOException {29 Map<String, String> config = new HashMap<>();30 config.put("server", "config/server.json");31 config.put("distributor", "config/distributor.json");32 config.put("tracing", "config/tracing.json");33 Config baseConfig = new MapConfig(config);34 Config serverConfig = baseConfig.getConfig("server");35 Config distributorConfig = baseConfig.getConfig("distributor");36 Config tracingConfig = baseConfig.getConfig("tracing");37 LoggingOptions loggingOptions = new LoggingOptions(tracingConfig);38 Tracer tracer = loggingOptions.getTracer();39 JaegerOptions jaegerOptions = new JaegerOptions(tracingConfig);40 OpenTelemetryOptions openTelemetryOptions = new OpenTelemetryOptions(tracingConfig);41 ZipkinOptions zipkinOptions = new ZipkinOptions(tracingConfig);42 ZipkinTracerOptions zipkinTracerOptions = new ZipkinTracerOptions(tracingConfig);

Full Screen

Full Screen

drain

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.distributor.local.LocalDistributor;2import org.openqa.selenium.grid.node.local.LocalNode;3import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;4import org.openqa.selenium.grid.web.Routable;5import org.openqa.selenium.grid.web.Routes;6import org.openqa.selenium.remote.http.HttpMethod;7import org.openqa.selenium.remote.http.HttpRequest;8import org.openqa.selenium.remote.http.HttpResponse;9import org.openqa.selenium.remote.tracing.Tracer;10import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer;11import java.net.URI;12import java.net.URISyntaxException;13import java.util.Objects;14public class DrainNode {15 public static void main(String[] args) throws URISyntaxException {16 Tracer tracer = new OpenTelemetryTracer();17 LocalSessionMap sessions = new LocalSessionMap(tracer);18 LocalNode node = LocalNode.builder(tracer, sessions)19 .build();20 LocalDistributor distributor = new LocalDistributor(tracer, sessions);21 distributor.add(node);22 HttpRequest request = new HttpRequest(HttpMethod.POST, "/drain");23 HttpResponse response = distributor.execute(request);24 System.out.println(response);25 }26}27HttpResponse{statusCode=200, headers={Content-Type=[text/plain; charset=utf-8], Content-Length=[0]}, content=EmptyContent{}}[/code]

Full Screen

Full Screen

drain

Using AI Code Generation

copy

Full Screen

1LocalDistributor distributor = LocalDistributor.createDefaultDistributor();2Node node = Node.createDefaultNode();3distributor.add(node);4LocalDistributor distributor = LocalDistributor.createDefaultDistributor();5Node node = Node.createDefaultNode();6distributor.add(node);7distributor.drain(node);8LocalDistributor distributor = LocalDistributor.createDefaultDistributor();9Session session = Session.createDefaultSession();10distributor.add(session);11LocalDistributor distributor = LocalDistributor.createDefaultDistributor();12Session session = Session.createDefaultSession();13distributor.add(session);14distributor.drain(session);15LocalDistributor distributor = LocalDistributor.createDefaultDistributor();16EventListener listener = new EventListener();17distributor.addListener(listener);18LocalDistributor distributor = LocalDistributor.createDefaultDistributor();19EventListener listener = new EventListener();20distributor.addListener(listener);21distributor.removeListener(listener);22LocalDistributor distributor = LocalDistributor.createDefaultDistributor();

Full Screen

Full Screen

drain

Using AI Code Generation

copy

Full Screen

1LocalDistributor distributor = new LocalDistributor(2 new DefaultDistributorConfig(),3 new DefaultDistributorFactory()4);5Session session = new Session(6 new SessionId(UUID.randomUUID()),7 new ImmutableCapabilities("browserName", "chrome")8);9distributor.add(session);10distributor.drain(session);11Assert.assertFalse(distributor.getAvailableSessions().contains(session));12Assert.assertTrue(distributor.getDrainedSessions().contains(session));13Assert.assertTrue(distributor.getAllSessions().contains(session));14Assert.assertFalse(distributor.getAllSessions().contains(session));15Assert.assertFalse(distributor.getAllSessions().contains(session));16Assert.assertFalse(distributor.getAllSessions().contains(session));17Assert.assertFalse(distributor.getAllSessions().contains(session));18Assert.assertFalse(distributor.getAllSessions().contains(session));19Assert.assertFalse(distributor.getAllSessions().contains(session));20Assert.assertFalse(distributor.getAllSessions().contains(session));21Assert.assertFalse(distributor.getAllSessions().contains(session));22Assert.assertFalse(distributor.getAllSessions().contains(session));23Assert.assertFalse(distributor.getAllSessions().contains(session));24Assert.assertFalse(distributor.getAllSessions().contains(session));25Assert.assertFalse(distributor.getAllSessions().contains(session));

Full Screen

Full Screen

drain

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.distributor.local.LocalDistributor;2import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;3import org.openqa.selenium.grid.web.Routable;4import org.openqa.selenium.remote.http.HttpClient;5import org.openqa.selenium.remote.http.HttpResponse;6import org.openqa.selenium.remote.tracing.Tracer;7import java.net.URI;8import java.util.List;9import java.util.Objects;10import java.util.stream.Collectors;11public class DrainSessions {12 public static void main(String[] args) {13 String gridHubUrl = args[0];14 String nodeUrl = args[1];15 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();16 Tracer tracer = Tracer.getDefault();17 LocalDistributor localDistributor = new LocalDistributor(18 new SessionMapOptions(),19 URI.create(gridHubUrl));20 List<Routable> routables = localDistributor.getRoute().get();21 List<HttpResponse> responses = routables.stream()22 .map(routable -> routable.execute(clientFactory, URI.create(nodeUrl)))23 .filter(Objects::nonNull)24 .collect(Collectors.toList());25 System.out.println(responses.size());26 }27}

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