How to use RandomHostSelectionStrategy class of ru.qatools.gridrouter.config package

Best Gridrouter code snippet using ru.qatools.gridrouter.config.RandomHostSelectionStrategy

Source:SmartHostSelectionStrategy.java Github

copy

Full Screen

1package ru.qatools.selenograph.gridrouter;2import ru.qatools.gridrouter.config.Host;3import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;4import ru.qatools.gridrouter.config.Region;5import ru.qatools.gridrouter.config.WithCount;6import ru.qatools.selenograph.front.HubSummary;7import java.util.ArrayList;8import java.util.HashMap;9import java.util.List;10import java.util.Map;11import java.util.function.Function;12import static java.util.Collections.emptyMap;13import static java.util.stream.Collectors.summingInt;14import static java.util.stream.Collectors.toMap;15import static ru.qatools.clay.utils.DateUtil.isTimePassedSince;16/**17 * @author Innokenty Shuvalov innokenty@yandex-team.ru18 */19public class SmartHostSelectionStrategy extends RandomHostSelectionStrategy20 implements UpdatableSelectionStrategy {21 protected static final int FALLBACK_TIMEOUT = 5 * 1000;22 protected static final int HUB_MAX_AGE = 45 * 1000;23 private long timestamp;24 /**25 * hostname -> free percentage (0 - 100)26 */27 private Map<String, Integer> hubs = emptyMap();28 //TODO split by browser and version29 public void updateHubSummaries(List<HubSummary> hubSummaries, long timestamp) {30 this.timestamp = timestamp;31 this.hubs = hubSummaries.stream()32 .filter(this::isUpdatedRecently)33 .collect(toMap(HubSummary::getAddress, this::getFreePercentage))...

Full Screen

Full Screen

Source:RandomHostSelectionStrategyTest.java Github

copy

Full Screen

...12import static org.hamcrest.Matchers.lessThan;13/**14 * @author Innokenty Shuvalov innokenty@yandex-team.ru15 */16public class RandomHostSelectionStrategyTest {17 private static final double ALLOWED_DEVIATION = 0.01;18 @Test19 @SuppressWarnings("ArraysAsListWithZeroOrOneArgument")20 public void testRandomness() {21 int entriesCount = 5000000;22 int keysCount = 10;23 Host host1 = new Host("host_1", 4444, keysCount - 1);24 List<Host> hosts = new ArrayList<>(keysCount);25 hosts.add(host1);26 int i = keysCount;27 while (i --> 1) {28 hosts.add(newHost());29 }30 HashMap<Host, Integer> appearances = new HashMap<>(keysCount, entriesCount / keysCount);31 RandomHostSelectionStrategy strategy = new RandomHostSelectionStrategy();32 i = entriesCount;33 while (i-- > 0) {34 Host host = strategy.selectRandom(hosts);35 appearances.put(host, Optional.ofNullable(appearances.get(host)).orElse(0) + 1);36 }37 assertThat(appearances.remove(host1), isAround(entriesCount / 2));38 for (int count : appearances.values()) {39 assertThat(count, isAround(entriesCount / 2 / (keysCount - 1)));40 }41 }42 private static Host newHost() {43 return new Host(UUID.randomUUID().toString(), 4444, 1);44 }45 private static Matcher<Integer> isAround(int count) {...

Full Screen

Full Screen

Source:RandomHostSelectionStrategy.java Github

copy

Full Screen

...5import static java.util.Collections.shuffle;6/**7 * @author Innokenty Shuvalov innokenty@yandex-team.ru8 */9public class RandomHostSelectionStrategy implements HostSelectionStrategy {10 protected <T extends WithCount> T selectRandom(List<T> elements) {11 List<T> copies = new ArrayList<>();12 for (T element : elements) {13 copies.addAll(nCopies(element.getCount(), element));14 }15 shuffle(copies);16 return copies.get(0);17 }18 @Override19 public Region selectRegion(List<Region> allRegions, List<Region> unvisitedRegions) {20 return selectRandom(unvisitedRegions);21 }22 @Override23 public Host selectHost(List<Host> hosts) {...

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1package ru.qatools.gridrouter.config;2import org.junit.Test;3import org.openqa.grid.common.RegistrationRequest;4import org.openqa.grid.internal.Registry;5import org.openqa.grid.internal.RemoteProxy;6import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;7import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;8import org.openqa.grid.web.Hub;9import org.openqa.selenium.remote.DesiredCapabilities;10import java.net.MalformedURLException;11import java.net.URL;12import java.util.LinkedList;13import java.util.List;14import static org.junit.Assert.assertEquals;15import static org.junit.Assert.assertTrue;16public class RandomHostSelectionStrategyTest {17 public void testRandomHostSelectionStrategy() throws MalformedURLException {18 GridHubConfiguration hubConfig = new GridHubConfiguration();19 hubConfig.setPort(4444);20 Hub hub = new Hub(hubConfig);21 hub.start();22 List<RemoteProxy> proxies = new LinkedList<>();23 for (int i = 0; i < 5; i++) {24 GridNodeConfiguration nodeConfig = new GridNodeConfiguration();25 nodeConfig.port = 5555 + i;26 nodeConfig.host = "localhost";27 nodeConfig.register = true;28 nodeConfig.registerCycle = 500;29 RegistrationRequest request = new RegistrationRequest(nodeConfig);30 request.getConfiguration().capabilities.add(new DesiredCapabilities());31 proxies.add(new RemoteProxy(request, hub.getRegistry()));32 }33 Registry registry = hub.getRegistry();34 for (RemoteProxy proxy : proxies) {35 registry.add(proxy);36 }37 RandomHostSelectionStrategy strategy = new RandomHostSelectionStrategy();38 for (int i = 0; i < 100; i++) {39 RemoteProxy proxy = strategy.getNewProxy(registry.getAllProxies(), null);40 assertTrue(proxies.contains(proxy));41 }42 hub.stop();43 }44}45package ru.qatools.gridrouter.config;46import org.junit.Test;47import org.openqa.grid.common.RegistrationRequest;48import org.openqa.grid.internal.Registry;49import org.openqa.grid.internal.RemoteProxy;50import org.openqa.grid.internal.utils.configuration.Grid

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;2import ru.qatools.gridrouter.config.Host;3import ru.qatools.gridrouter.config.Hosts;4import java.util.List;5import java.util.ArrayList;6import java.util.Arrays;7import java.util.Random;8import java.util.concurrent.ThreadLocalRandom;9import java.util.concurrent.atomic.AtomicInteger;10import java.util.concurrent.atomic.AtomicLong;11import java.util.concurrent.atomic.AtomicReference;12import java.util.concurrent.locks.ReentrantLock;13import java.util.stream.Collectors;14import java.util.stream.IntStream;15import java.util.stream.Stream;16import java.util.concurrent.ThreadLocalRandom;17public class RandomHostSelectionStrategy{18 private final Random random = new Random();19 private final List<Host> hosts;20 private final AtomicInteger counter = new AtomicInteger();21 private final ReentrantLock lock = new ReentrantLock();22 public RandomHostSelectionStrategy(Hosts hosts) {23 this.hosts = hosts.getHosts();24 }25 public Host nextHost() {26 lock.lock();27 try {28 int next = counter.getAndIncrement();29 if (next >= hosts.size()) {30 counter.set(0);31 next = 0;32 }33 return hosts.get(next);34 } finally {35 lock.unlock();36 }37 }38}39import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;40import ru.qatools.gridrouter.config.Host;41import ru.qatools.gridrouter.config.Hosts;42import java.util.List;43import java.util.ArrayList;44import java.util.Arrays;45import java.util.Random;46import java.util.concurrent.ThreadLocalRandom;47import java.util.concurrent.atomic.AtomicInteger;48import java.util.concurrent.atomic.AtomicLong;49import java.util.concurrent.atomic.AtomicReference;50import java.util.concurrent.locks.ReentrantLock;51import java.util.stream.Collectors;52import java.util.stream.IntStream;53import java.util.stream.Stream;54import java.util.concurrent.ThreadLocalRandom;55public class RandomHostSelectionStrategy{56 private final Random random = new Random();57 private final List<Host> hosts;58 private final AtomicInteger counter = new AtomicInteger();59 private final ReentrantLock lock = new ReentrantLock();60 public RandomHostSelectionStrategy(Hosts hosts) {61 this.hosts = hosts.getHosts();62 }63 public Host nextHost() {64 lock.lock();65 try {

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1package ru.qatools.gridrouter.config;2import java.util.List;3import java.util.Random;4import org.openqa.grid.internal.Registry;5import org.openqa.grid.internal.RemoteProxy;6import org.openqa.grid.web.servlet.handler.RequestHandler;7public class RandomHostSelectionStrategy implements HostSelectionStrategy {8 private final Random random = new Random();9 public String getHost(RequestHandler request, Registry registry) {10 List<RemoteProxy> proxies = registry.getAllProxies();11 int proxyIndex = random.nextInt(proxies.size());12 RemoteProxy proxy = proxies.get(proxyIndex);13 return proxy.getRemoteHost().getHost();14 }15}16package ru.qatools.gridrouter.config;17import java.util.List;18import java.util.Random;19import org.openqa.grid.internal.Registry;20import org.openqa.grid.internal.RemoteProxy;21import org.openqa.grid.web.servlet.handler.RequestHandler;22public class RandomPortSelectionStrategy implements PortSelectionStrategy {23 private final Random random = new Random();24 public int getPort(RequestHandler request, Registry registry) {25 List<RemoteProxy> proxies = registry.getAllProxies();26 int proxyIndex = random.nextInt(proxies.size());27 RemoteProxy proxy = proxies.get(proxyIndex);28 return proxy.getRemoteHost().getPort();29 }30}31package ru.qatools.gridrouter.config;32import java.util.List;33import java.util.concurrent.atomic.AtomicInteger;34import org.openqa.grid.internal.Registry;35import org.openqa.grid.internal.RemoteProxy;36import org.openqa.grid.web.servlet.handler.RequestHandler;37public class RoundRobinHostSelectionStrategy implements HostSelectionStrategy {38 private final AtomicInteger index = new AtomicInteger();39 public String getHost(RequestHandler request, Registry registry) {40 List<RemoteProxy> proxies = registry.getAllProxies();41 int proxyIndex = index.getAndIncrement() % proxies.size();42 RemoteProxy proxy = proxies.get(proxyIndex);43 return proxy.getRemoteHost().getHost();44 }45}46package ru.qatools.gridrouter.config;47import java.util.List;48import java.util.concurrent.atomic.AtomicInteger;49import org.openqa.grid.internal

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1package com.test;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.ArrayList;5import java.util.List;6import java.util.concurrent.TimeUnit;7import org.junit.After;8import org.junit.Before;9import org.junit.Test;10import org.openqa.selenium.By;11import org.openqa.selenium.WebDriver;12import org.openqa.selenium.WebElement;13import org.openqa.selenium.remote.DesiredCapabilities;14import org.openqa.selenium.remote.RemoteWebDriver;15import org.openqa.selenium.support.ui.ExpectedCondition;16import org.openqa.selenium.support.ui.WebDriverWait;17import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;18import ru.qatools.gridrouter.config.RandomHostSelectionStrategy.Host;19public class 3 {20 private WebDriver driver;21 private String baseUrl;22 private boolean acceptNextAlert = true;23 private StringBuffer verificationErrors = new StringBuffer();24 public void setUp() throws Exception {25 DesiredCapabilities capability = DesiredCapabilities.chrome();26 capability.setCapability("host", "localhost");27 capability.setCapability("port", 4444);28 capability.setCapability("browserName", "chrome");29 capability.setCapability("browserVersion", "ANY");30 capability.setCapability("platform", "ANY");31 capability.setCapability("maxInstances", "1");32 capability.setCapability("seleniumProtocol", "WebDriver");33 capability.setCapability("platformName", "ANY");34 capability.setCapability("platformVersion", "ANY");35 capability.setCapability("platform", "ANY");36 capability.setCapability("javascriptEnabled", true);37 capability.setCapability("takesScreenshot", true);38 capability.setCapability("cssSelectorsEnabled", true);39 capability.setCapability("handlesAlerts", true);40 capability.setCapability("databaseEnabled", true);41 capability.setCapability("locationContextEnabled", true);42 capability.setCapability("applicationCacheEnabled", true);43 capability.setCapability("browserConnectionEnabled", true);44 capability.setCapability("webStorageEnabled", true);45 capability.setCapability("rotatable", true);46 capability.setCapability("acceptSslCerts", true);47 capability.setCapability("nativeEvents", true);48 capability.setCapability("webdriver.remote.sessionid", "1");49 capability.setCapability("webdriver.remote.quietExceptions", true);50 capability.setCapability("webdriver.remote.unexpectedAlertBehaviour", "ignore");51 capability.setCapability("webdriver.remote.httpConnection", "keep-alive");52 capability.setCapability("webdriver.remote.useHttpUrlConnection", true

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1package ru.qatools.gridrouter.config;2import java.util.ArrayList;3import java.util.List;4public class RandomHostSelectionStrategy implements HostSelectionStrategy {5 private final List<String> hosts = new ArrayList<String>();6 public RandomHostSelectionStrategy() {7 }8 public String getHost() {9 return hosts.get(new Random().nextInt(hosts.size()));10 }11 public void addHost(String host) {12 hosts.add(host);13 }14}15package ru.qatools.gridrouter.config;16import java.util.ArrayList;17import java.util.List;18public class RoundRobinHostSelectionStrategy implements HostSelectionStrategy {19 private final List<String> hosts = new ArrayList<String>();20 private int index = 0;21 public RoundRobinHostSelectionStrategy() {22 }23 public String getHost() {24 if (index >= hosts.size()) {25 index = 0;26 }27 return hosts.get(index++);28 }29 public void addHost(String host) {30 hosts.add(host);31 }32}33package ru.qatools.gridrouter.config;34import java.util.ArrayList;35import java.util.List;36public class StaticHostSelectionStrategy implements HostSelectionStrategy {37 private final List<String> hosts = new ArrayList<String>();38 public StaticHostSelectionStrategy() {39 }40 public String getHost() {41 return hosts.get(0);42 }43 public void addHost(String host) {44 hosts.add(host);45 }46}47package ru.qatools.gridrouter.config;48public class HostSelectionStrategyFactory {49 public static HostSelectionStrategy create(String strategy) {50 if (strategy.equals("random")) {51 return new RandomHostSelectionStrategy();52 }53 if (strategy.equals("round-robin")) {

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1package ru.qatools.gridrouter;2import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;3import java.util.ArrayList;4import java.util.List;5public class TestRandomHostSelectionStrategy {6 public static void main(String[] args) {7 List<String> hosts = new ArrayList<String>();8 hosts.add("localhost:4444");9 hosts.add("localhost:4445");10 hosts.add("localhost:4446");11 hosts.add("localhost:4447");12 hosts.add("localhost:4448");13 hosts.add("localhost:4449");14 hosts.add("localhost:4450");15 hosts.add("localhost:4451");16 hosts.add("localhost:4452");17 hosts.add("localhost:4453");18 hosts.add("localhost:4454");19 hosts.add("localhost:4455");20 hosts.add("localhost:4456");21 hosts.add("localhost:4457");22 hosts.add("localhost:4458");23 hosts.add("localhost:4459");24 hosts.add("localhost:4460");25 hosts.add("localhost:4461");26 hosts.add("localhost:4462");27 hosts.add("localhost:4463");28 hosts.add("localhost:4464");29 hosts.add("localhost:4465");30 hosts.add("localhost:4466");31 hosts.add("localhost:4467");32 hosts.add("localhost:4468");33 hosts.add("localhost:4469");34 hosts.add("localhost:4470");35 hosts.add("localhost:4471");36 hosts.add("localhost:4472");37 hosts.add("localhost:4473");38 hosts.add("localhost:4474");39 hosts.add("localhost:4475");40 hosts.add("localhost:4476");41 hosts.add("localhost:4477");42 hosts.add("localhost:4478");43 hosts.add("localhost:4479");44 hosts.add("localhost:4480");45 hosts.add("localhost:4481");46 hosts.add("localhost:4482");47 hosts.add("localhost:4483");48 hosts.add("localhost:4484");49 hosts.add("localhost:4485");50 hosts.add("localhost:4486");51 hosts.add("localhost:4487");52 hosts.add("localhost:4488");53 hosts.add("localhost:4489");54 hosts.add("localhost:4490");55 hosts.add("

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;2import java.util.ArrayList;3import java.util.List;4public class RandomHostSelectionStrategyDemo {5 public static void main(String[] args) {6 RandomHostSelectionStrategy randomHostSelectionStrategy = new RandomHostSelectionStrategy();7 List<String> hosts = new ArrayList<String>();8 randomHostSelectionStrategy.setHosts(hosts);9 System.out.println(randomHostSelectionStrategy.selectHost());10 }11}

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1package ru.qatools.gridrouter.config;2import java.util.ArrayList;3import java.util.List;4import java.util.Random;5import org.openqa.grid.internal.RemoteProxy;6public class RandomHostSelectionStrategy implements HostSelectionStrategy {7 private Random random = new Random();8 public RemoteProxy select(List<RemoteProxy> proxies) {9 List<RemoteProxy> availableNodes = new ArrayList<>();10 for (RemoteProxy proxy : proxies) {11 if (proxy.isBusy()) {12 continue;13 }14 availableNodes.add(proxy);15 }16 if (availableNodes.isEmpty()) {17 return null;18 }19 return availableNodes.get(random.nextInt(availableNodes.size()));20 }21}22package ru.qatools.gridrouter.config;23import java.util.ArrayList;24import java.util.List;25import java.util.Random;26import org.openqa.grid.internal.RemoteProxy;27public class RandomHostSelectionStrategy implements HostSelectionStrategy {28 private Random random = new Random();29 public RemoteProxy select(List<RemoteProxy> proxies) {30 List<RemoteProxy> availableNodes = new ArrayList<>();31 for (RemoteProxy proxy : proxies) {32 if (proxy.isBusy()) {33 continue;34 }35 availableNodes.add(proxy);36 }37 if (availableNodes.isEmpty()) {38 return null;39 }40 return availableNodes.get(random.nextInt(availableNodes.size()));41 }42}43package ru.qatools.gridrouter.config;44import java.util.ArrayList;45import java.util.List;46import java.util.Random;47import org.openqa.grid.internal.RemoteProxy;48public class RandomHostSelectionStrategy implements HostSelectionStrategy {49 private Random random = new Random();50 public RemoteProxy select(List<RemoteProxy> proxies) {51 List<RemoteProxy> availableNodes = new ArrayList<>();52 for (RemoteProxy proxy : proxies) {53 if (proxy.isBusy()) {54 continue;55 }56 availableNodes.add(proxy);57 }58 if (availableNodes.isEmpty())

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;2import java.util.*;3import java.io.*;4public class 3 {5public static void main(String[] args) {6List<String> hosts = new ArrayList<String>();7RandomHostSelectionStrategy randomHostSelectionStrategy = new RandomHostSelectionStrategy();8String randomHost = randomHostSelectionStrategy.getHost(hosts);9System.out.println("Random host is " + randomHost);10}11}12import org.openqa.grid.internal.Registry;13import org.openqa.grid.internal.RemoteProxy;14import org.openqa.grid.web.servlet.handler.RequestHandler;15public class RandomPortSelectionStrategy implements PortSelectionStrategy {16 private final Random random = new Random();17 public int getPort(RequestHandler request, Registry registry) {18 List<RemoteProxy> proxies = registry.getAllProxies();19 int proxyIndex = random.nextInt(proxies.size());20 RemoteProxy proxy = proxies.get(proxyIndex);21 return proxy.getRemoteHost().getPort();22 }23}24package ru.qatools.gridrouter.config;25import java.util.List;26import java.util.concurrent.atomic.AtomicInteger;27import org.openqa.grid.internal.Registry;28import org.openqa.grid.internal.RemoteProxy;29import org.openqa.grid.web.servlet.handler.RequestHandler;30public class RoundRobinHostSelectionStrategy implements HostSelectionStrategy {31 private final AtomicInteger index = new AtomicInteger();32 public String getHost(RequestHandler request, Registry registry) {33 List<RemoteProxy> proxies = registry.getAllProxies();34 int proxyIndex = index.getAndIncrement() % proxies.size();35 RemoteProxy proxy = proxies.get(proxyIndex);36 return proxy.getRemoteHost().getHost();37 }38}39package ru.qatools.gridrouter.config;40import java.util.List;41import java.util.concurrent.atomic.AtomicInteger;42import org.openqa.grid.internal

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1package com.test;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.ArrayList;5import java.util.List;6import java.util.concurrent.TimeUnit;7import org.junit.After;8import org.junit.Before;9import org.junit.Test;10import org.openqa.selenium.By;11import org.openqa.selenium.WebDriver;12import org.openqa.selenium.WebElement;13import org.openqa.selenium.remote.DesiredCapabilities;14import org.openqa.selenium.remote.RemoteWebDriver;15import org.openqa.selenium.support.ui.ExpectedCondition;16import org.openqa.selenium.support.ui.WebDriverWait;17import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;18import ru.qatools.gridrouter.config.RandomHostSelectionStrategy.Host;19public class 3 {20 private WebDriver driver;21 private String baseUrl;22 private boolean acceptNextAlert = true;23 private StringBuffer verificationErrors = new StringBuffer();24 public void setUp() throws Exception {25 DesiredCapabilities capability = DesiredCapabilities.chrome();26 capability.setCapability("host", "localhost");27 capability.setCapability("port", 4444);28 capability.setCapability("browserName", "chrome");29 capability.setCapability("browserVersion", "ANY");30 capability.setCapability("platform", "ANY");31 capability.setCapability("maxInstances", "1");32 capability.setCapability("seleniumProtocol", "WebDriver");33 capability.setCapability("platformName", "ANY");34 capability.setCapability("platformVersion", "ANY");35 capability.setCapability("platform", "ANY");36 capability.setCapability("javascriptEnabled", true);37 capability.setCapability("takesScreenshot", true);38 capability.setCapability("cssSelectorsEnabled", true);39 capability.setCapability("handlesAlerts", true);40 capability.setCapability("databaseEnabled", true);41 capability.setCapability("locationContextEnabled", true);42 capability.setCapability("applicationCacheEnabled", true);43 capability.setCapability("browserConnectionEnabled", true);44 capability.setCapability("webStorageEnabled", true);45 capability.setCapability("rotatable", true);46 capability.setCapability("acceptSslCerts", true);47 capability.setCapability("nativeEvents", true);48 capability.setCapability("webdriver.remote.sessionid", "1");49 capability.setCapability("webdriver.remote.quietExceptions", true);50 capability.setCapability("webdriver.remote.unexpectedAlertBehaviour", "ignore");51 capability.setCapability("webdriver.remote.httpConnection", "keep-alive");52 capability.setCapability("webdriver.remote.useHttpUrlConnection", true

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1package ru.qatools.gridrouter.config;2import java.util.ArrayList;3import java.util.List;4public class RandomHostSelectionStrategy implements HostSelectionStrategy {5 private final List<String> hosts = new ArrayList<String>();6 public RandomHostSelectionStrategy() {7 }8 public String getHost() {9 return hosts.get(new Random().nextInt(hosts.size()));10 }11 public void addHost(String host) {12 hosts.add(host);13 }14}15package ru.qatools.gridrouter.config;16import java.util.ArrayList;17import java.util.List;18public class RoundRobinHostSelectionStrategy implements HostSelectionStrategy {19 private final List<String> hosts = new ArrayList<String>();20 private int index = 0;21 public RoundRobinHostSelectionStrategy() {22 }23 public String getHost() {24 if (index >= hosts.size()) {25 index = 0;26 }27 return hosts.get(index++);28 }29 public void addHost(String host) {30 hosts.add(host);31 }32}33package ru.qatools.gridrouter.config;34import java.util.ArrayList;35import java.util.List;36public class StaticHostSelectionStrategy implements HostSelectionStrategy {37 private final List<String> hosts = new ArrayList<String>();38 public StaticHostSelectionStrategy() {39 }40 public String getHost() {41 return hosts.get(0);42 }43 public void addHost(String host) {44 hosts.add(host);45 }46}47package ru.qatools.gridrouter.config;48public class HostSelectionStrategyFactory {49 public static HostSelectionStrategy create(String strategy) {50 if (strategy.equals("random")) {51 return new RandomHostSelectionStrategy();52 }53 if (strategy.equals("round-robin")) {

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;2import java.util.ArrayList;3import java.util.List;4public class RandomHostSelectionStrategyDemo {5 public static void main(String[] args) {6 RandomHostSelectionStrategy randomHostSelectionStrategy = new RandomHostSelectionStrategy();7 List<String> hosts = new ArrayList<String>();8 randomHostSelectionStrategy.setHosts(hosts);9 System.out.println(randomHostSelectionStrategy.selectHost());10 }11}

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1package ru.qatools.gridrouter.config;2import java.util.ArrayList;3import java.util.List;4import java.util.Random;5import org.openqa.grid.internal.RemoteProxy;6public class RandomHostSelectionStrategy implements HostSelectionStrategy {7 private Random random = new Random();8 public RemoteProxy select(List<RemoteProxy> proxies) {9 List<RemoteProxy> availableNodes = new ArrayList<>();10 for (RemoteProxy proxy : proxies) {11 if (proxy.isBusy()) {12 continue;13 }14 availableNodes.add(proxy);15 }16 if (availableNodes.isEmpty()) {17 return null;18 }19 return availableNodes.get(random.nextInt(availableNodes.size()));20 }21}22package ru.qatools.gridrouter.config;23import java.util.ArrayList;24import java.util.List;25import java.util.Random;26import org.openqa.grid.internal.RemoteProxy;27public class RandomHostSelectionStrategy implements HostSelectionStrategy {28 private Random random = new Random();29 public RemoteProxy select(List<RemoteProxy> proxies) {30 List<RemoteProxy> availableNodes = new ArrayList<>();31 for (RemoteProxy proxy : proxies) {32 if (proxy.isBusy()) {33 continue;34 }35 availableNodes.add(proxy);36 }37 if (availableNodes.isEmpty()) {38 return null;39 }40 return availableNodes.get(random.nextInt(availableNodes.size()));41 }42}43package ru.qatools.gridrouter.config;44import java.util.ArrayList;45import java.util.List;46import java.util.Random;47import org.openqa.grid.internal.RemoteProxy;48public class RandomHostSelectionStrategy implements HostSelectionStrategy {49 private Random random = new Random();50 public RemoteProxy select(List<RemoteProxy> proxies) {51 List<RemoteProxy> availableNodes = new ArrayList<>();52 for (RemoteProxy proxy : proxies) {53 if (proxy.isBusy()) {54 continue;55 }56 availableNodes.add(proxy);57 }58 if (availableNodes.isEmpty())

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;2import java.util.*;3import java.io.*;4public class 3 {5public static void main(String[] args) {6List<String> hosts = new ArrayList<String>();7RandomHostSelectionStrategy randomHostSelectionStrategy = new RandomHostSelectionStrategy();8String randomHost = randomHostSelectionStrategy.getHost(hosts);9System.out.println("Random host is " + randomHost);10}11}

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;2import java.util.ArrayList;3import java.util.List;4public class RandomHostSelectionStrategyDemo {5 public static void main(String[] args) {6 RandomHostSelectionStrategy randomHostSelectionStrategy = new RandomHostSelectionStrategy();7 List<String> hosts = new ArrayList<String>();8 randomHostSelectionStrategy.setHosts(hosts);9 System.out.println(randomHostSelectionStrategy.selectHost());10 }11}

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;2import java.util.*;3import java.io.*;4public class 3 {5public static void main(String[] args) {6List<String> hosts = new ArrayList<String>();7RandomHostSelectionStrategy randomHostSelectionStrategy = new RandomHostSelectionStrategy();8String randomHost = randomHostSelectionStrategy.getHost(hosts);9System.out.println("Random host is " + randomHost);10}11}

Full Screen

Full Screen

RandomHostSelectionStrategy

Using AI Code Generation

copy

Full Screen

1package com.test;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.ArrayList;5import java.util.List;6import java.util.concurrent.TimeUnit;7import org.junit.After;8import org.junit.Before;9import org.junit.Test;10import org.openqa.selenium.By;11import org.openqa.selenium.WebDriver;12import org.openqa.selenium.WebElement;13import org.openqa.selenium.remote.DesiredCapabilities;14import org.openqa.selenium.remote.RemoteWebDriver;15import org.openqa.selenium.support.ui.ExpectedCondition;16import org.openqa.selenium.support.ui.WebDriverWait;17import ru.qatools.gridrouter.config.RandomHostSelectionStrategy;18import ru.qatools.gridrouter.config.RandomHostSelectionStrategy.Host;19public class 3 {20 private WebDriver driver;21 private String baseUrl;22 private boolean acceptNextAlert = true;23 private StringBuffer verificationErrors = new StringBuffer();24 public void setUp() throws Exception {25 DesiredCapabilities capability = DesiredCapabilities.chrome();26 capability.setCapability("host", "localhost");27 capability.setCapability("port", 4444);28 capability.setCapability("browserName", "chrome");29 capability.setCapability("browserVersion", "ANY");30 capability.setCapability("platform", "ANY");31 capability.setCapability("maxInstances", "1");32 capability.setCapability("seleniumProtocol", "WebDriver");33 capability.setCapability("platformName", "ANY");34 capability.setCapability("platformVersion", "ANY");35 capability.setCapability("platform", "ANY");36 capability.setCapability("javascriptEnabled", true);37 capability.setCapability("takesScreenshot", true);38 capability.setCapability("cssSelectorsEnabled", true);39 capability.setCapability("handlesAlerts", true);40 capability.setCapability("databaseEnabled", true);41 capability.setCapability("locationContextEnabled", true);42 capability.setCapability("applicationCacheEnabled", true);43 capability.setCapability("browserConnectionEnabled", true);44 capability.setCapability("webStorageEnabled", true);45 capability.setCapability("rotatable", true);46 capability.setCapability("acceptSslCerts", true);47 capability.setCapability("nativeEvents", true);48 capability.setCapability("webdriver.remote.sessionid", "1");49 capability.setCapability("webdriver.remote.quietExceptions", true);50 capability.setCapability("webdriver.remote.unexpectedAlertBehaviour", "ignore");51 capability.setCapability("webdriver.remote.httpConnection", "keep-alive");52 capability.setCapability("webdriver.remote.useHttpUrlConnection", true

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gridrouter automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in RandomHostSelectionStrategy

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