How to use create method of org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector class

Best Selenium code snippet using org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector.create

Source:LocalDistributorTest.java Github

copy

Full Screen

...76 private URI uri;77 private Node localNode;78 @Before79 public void setUp() throws URISyntaxException {80 tracer = DefaultTestTracer.createTracer();81 bus = new GuavaEventBus();82 clientFactory = HttpClient.Factory.createDefault();83 Capabilities caps = new ImmutableCapabilities("browserName", "cheese");84 uri = new URI("http://localhost:1234");85 localNode = LocalNode.builder(tracer, bus, uri, uri, registrationSecret)86 .add(caps, new TestSessionFactory((id, c) -> new Handler(c)))87 .maximumConcurrentSessions(2)88 .build();89 }90 @Test91 public void testAddNodeToDistributor() {92 NewSessionQueue queue = new LocalNewSessionQueue(93 tracer,94 bus,95 new DefaultSlotMatcher(),96 Duration.ofSeconds(2),97 Duration.ofSeconds(2),98 registrationSecret);99 Distributor distributor = new LocalDistributor(100 tracer,101 bus,102 clientFactory,103 new LocalSessionMap(tracer, bus),104 queue,105 new DefaultSlotSelector(),106 registrationSecret,107 Duration.ofMinutes(5),108 false);109 distributor.add(localNode);110 DistributorStatus status = distributor.getStatus();111 //Check the size112 final Set<NodeStatus> nodes = status.getNodes();113 assertThat(nodes.size()).isEqualTo(1);114 //Check a couple attributes115 NodeStatus distributorNode = nodes.iterator().next();116 assertThat(distributorNode.getId()).isEqualByComparingTo(localNode.getId());117 assertThat(distributorNode.getUri()).isEqualTo(uri);118 }119 @Test120 public void testShouldNotAddNodeWithWrongSecret() {121 Secret secret = new Secret("my_secret");122 NewSessionQueue queue = new LocalNewSessionQueue(123 tracer,124 bus,125 new DefaultSlotMatcher(),126 Duration.ofSeconds(2),127 Duration.ofSeconds(2),128 registrationSecret);129 Distributor secretDistributor = new LocalDistributor(130 tracer,131 bus,132 clientFactory,133 new LocalSessionMap(tracer, bus),134 queue,135 new DefaultSlotSelector(),136 secret,137 Duration.ofMinutes(5),138 false);139 bus.fire(new NodeStatusEvent(localNode.getStatus()));140 DistributorStatus status = secretDistributor.getStatus();141 //Check the size142 final Set<NodeStatus> nodes = status.getNodes();143 assertThat(nodes.size()).isEqualTo(0);144 }145 @Test146 public void testRemoveNodeFromDistributor() {147 NewSessionQueue queue = new LocalNewSessionQueue(148 tracer,149 bus,150 new DefaultSlotMatcher(),151 Duration.ofSeconds(2),152 Duration.ofSeconds(2),153 registrationSecret);154 Distributor distributor = new LocalDistributor(155 tracer,156 bus,157 clientFactory,158 new LocalSessionMap(tracer, bus),159 queue,160 new DefaultSlotSelector(),161 registrationSecret,162 Duration.ofMinutes(5),163 false);164 distributor.add(localNode);165 //Check the size166 DistributorStatus statusBefore = distributor.getStatus();167 final Set<NodeStatus> nodesBefore = statusBefore.getNodes();168 assertThat(nodesBefore.size()).isEqualTo(1);169 //Recheck the status--should be zero170 distributor.remove(localNode.getId());171 DistributorStatus statusAfter = distributor.getStatus();172 final Set<NodeStatus> nodesAfter = statusAfter.getNodes();173 assertThat(nodesAfter.size()).isEqualTo(0);174 }175 @Test176 public void testAddSameNodeTwice() {177 NewSessionQueue queue = new LocalNewSessionQueue(178 tracer,179 bus,180 new DefaultSlotMatcher(),181 Duration.ofSeconds(2),182 Duration.ofSeconds(2),183 registrationSecret);184 Distributor distributor = new LocalDistributor(185 tracer,186 bus,187 clientFactory,188 new LocalSessionMap(tracer, bus),189 queue,190 new DefaultSlotSelector(),191 registrationSecret,192 Duration.ofMinutes(5),193 false);194 distributor.add(localNode);195 distributor.add(localNode);196 DistributorStatus status = distributor.getStatus();197 //Should only be one node after dupe check198 final Set<NodeStatus> nodes = status.getNodes();199 assertThat(nodes.size()).isEqualTo(1);200 }201 @Test202 public void shouldBeAbleToAddMultipleSessionsConcurrently() throws Exception {203 NewSessionQueue queue = new LocalNewSessionQueue(204 tracer,205 bus,206 new DefaultSlotMatcher(),207 Duration.ofSeconds(2),208 Duration.ofSeconds(2),209 registrationSecret);210 LocalDistributor distributor = new LocalDistributor(211 tracer,212 bus,213 clientFactory,214 new LocalSessionMap(tracer, bus),215 queue,216 new DefaultSlotSelector(),217 registrationSecret,218 Duration.ofMinutes(5),219 false);220 // Add one node to ensure that everything is created in that.221 Capabilities caps = new ImmutableCapabilities("browserName", "cheese");222 class VerifyingHandler extends Session implements HttpHandler {223 private VerifyingHandler(SessionId id, Capabilities capabilities) {224 super(id, uri, new ImmutableCapabilities(), capabilities, Instant.now());225 }226 @Override227 public HttpResponse execute(HttpRequest req) {228 Optional<SessionId> id = HttpSessionId.getSessionId(req.getUri()).map(SessionId::new);229 assertThat(id).isEqualTo(Optional.of(getId()));230 return new HttpResponse();231 }232 }233 // Only use one node.234 Node node = LocalNode.builder(tracer, bus, uri, uri, registrationSecret)...

Full Screen

Full Screen

Source:NewSessionCreationTest.java Github

copy

Full Screen

...70 private Secret registrationSecret;71 private Server<?> server;72 @Before73 public void setup() {74 tracer = DefaultTestTracer.createTracer();75 events = new GuavaEventBus();76 clientFactory = HttpClient.Factory.createDefault();77 registrationSecret = new Secret("hereford hop");78 }79 @After80 public void stopServer() {81 server.stop();82 }83 @Test84 public void ensureJsCannotCreateANewSession() throws URISyntaxException {85 SessionMap sessions = new LocalSessionMap(tracer, events);86 NewSessionQueue queue = new LocalNewSessionQueue(87 tracer,88 events,89 new DefaultSlotMatcher(),90 Duration.ofSeconds(2),91 Duration.ofSeconds(2),92 registrationSecret);93 Distributor distributor = new LocalDistributor(94 tracer,95 events,96 clientFactory,97 sessions,98 queue,99 new DefaultSlotSelector(),100 registrationSecret,101 Duration.ofMinutes(5),102 false);103 Routable router = new Router(tracer, clientFactory, sessions, queue, distributor)104 .with(new EnsureSpecCompliantHeaders(ImmutableList.of(), ImmutableSet.of()));105 server = new NettyServer(106 new BaseServerOptions(new MapConfig(ImmutableMap.of())),107 router,108 new ProxyCdpIntoGrid(clientFactory, sessions))109 .start();110 URI uri = server.getUrl().toURI();111 Node node = LocalNode.builder(112 tracer,113 events,114 uri,115 uri,116 registrationSecret)117 .add(118 Browser.detect().getCapabilities(),119 new TestSessionFactory(120 (id, caps) ->121 new Session(id, uri, Browser.detect().getCapabilities(), caps, Instant.now())))122 .build();123 distributor.add(node);124 try (HttpClient client = HttpClient.Factory.createDefault().createClient(server.getUrl())) {125 // Attempt to create a session with an origin header but content type set126 HttpResponse res = client.execute(127 new HttpRequest(POST, "/session")128 .addHeader("Content-Type", JSON_UTF_8)129 .addHeader("Origin", "localhost")130 .setContent(Contents.asJson(ImmutableMap.of(131 "capabilities", ImmutableMap.of(132 "alwaysMatch", Browser.detect().getCapabilities())))));133 assertThat(res.getStatus()).isEqualTo(HTTP_INTERNAL_ERROR);134 // And now make sure the session is just fine135 res = client.execute(136 new HttpRequest(POST, "/session")137 .addHeader("Content-Type", JSON_UTF_8)138 .setContent(Contents.asJson(ImmutableMap.of(139 "capabilities", ImmutableMap.of(140 "alwaysMatch", Browser.detect().getCapabilities())))));141 assertThat(res.isSuccessful()).isTrue();142 }143 }144 @Test145 public void shouldNotRetryNewSessionRequestOnUnexpectedError() throws URISyntaxException {146 Capabilities capabilities = new ImmutableCapabilities("browserName", "cheese");147 URI nodeUri = new URI("http://localhost:4444");148 CombinedHandler handler = new CombinedHandler();149 SessionMap sessions = new LocalSessionMap(tracer, events);150 handler.addHandler(sessions);151 NewSessionQueue queue = new LocalNewSessionQueue(152 tracer,153 events,154 new DefaultSlotMatcher(),155 Duration.ofSeconds(2),156 Duration.ofSeconds(10),157 registrationSecret);158 handler.addHandler(queue);159 Distributor distributor = new LocalDistributor(160 tracer,161 events,162 clientFactory,163 sessions,164 queue,165 new DefaultSlotSelector(),166 registrationSecret,167 Duration.ofMinutes(5),168 false);169 handler.addHandler(distributor);170 AtomicInteger count = new AtomicInteger();171 // First session creation attempt throws an error.172 // Does not reach second attempt.173 TestSessionFactory sessionFactory = new TestSessionFactory((id, caps) -> {174 if (count.get() == 0) {175 count.incrementAndGet();176 throw new SessionNotCreatedException("Expected the exception");177 } else {178 return new Session(179 id,180 nodeUri,181 new ImmutableCapabilities(),182 caps,183 Instant.now());184 }185 });186 LocalNode localNode = LocalNode.builder(tracer, events, nodeUri, nodeUri, registrationSecret)187 .add(capabilities, sessionFactory).build();188 handler.addHandler(localNode);189 distributor.add(localNode);190 Router router = new Router(tracer, clientFactory, sessions, queue, distributor);191 handler.addHandler(router);192 server = new NettyServer(193 new BaseServerOptions(194 new MapConfig(ImmutableMap.of())),195 handler);196 server.start();197 HttpRequest request = new HttpRequest(POST, "/session");198 request.setContent(asJson(199 ImmutableMap.of(200 "capabilities", ImmutableMap.of(201 "alwaysMatch", capabilities))));202 HttpClient client = clientFactory.createClient(server.getUrl());203 HttpResponse httpResponse = client.execute(request);204 assertThat(httpResponse.getStatus()).isEqualTo(HTTP_INTERNAL_ERROR);205 }206 @Test(timeout = 5000L)207 public void shouldRejectRequestForUnsupportedCaps() throws URISyntaxException {208 Capabilities capabilities = new ImmutableCapabilities("browserName", "cheese");209 URI nodeUri = new URI("http://localhost:4444");210 CombinedHandler handler = new CombinedHandler();211 SessionMap sessions = new LocalSessionMap(tracer, events);212 handler.addHandler(sessions);213 NewSessionQueue queue = new LocalNewSessionQueue(214 tracer,215 events,216 new DefaultSlotMatcher(),217 Duration.ofSeconds(5),218 Duration.ofSeconds(60),219 registrationSecret);220 handler.addHandler(queue);221 Distributor distributor = new LocalDistributor(222 tracer,223 events,224 clientFactory,225 sessions,226 queue,227 new DefaultSlotSelector(),228 registrationSecret,229 Duration.ofMinutes(5),230 true);231 handler.addHandler(distributor);232 TestSessionFactory sessionFactory = new TestSessionFactory((id, caps) ->233 new Session(234 id,235 nodeUri,236 new ImmutableCapabilities(),237 caps,238 Instant.now())239 );240 LocalNode localNode = LocalNode.builder(tracer, events, nodeUri, nodeUri, registrationSecret)241 .add(capabilities, sessionFactory).build();242 handler.addHandler(localNode);243 distributor.add(localNode);244 Router router = new Router(tracer, clientFactory, sessions, queue, distributor);245 handler.addHandler(router);246 server = new NettyServer(247 new BaseServerOptions(248 new MapConfig(ImmutableMap.of())),249 handler);250 server.start();251 HttpRequest request = new HttpRequest(POST, "/session");252 request.setContent(asJson(253 ImmutableMap.of(254 "capabilities", ImmutableMap.of(255 "alwaysMatch", new ImmutableCapabilities("browserName", "burger")))));256 HttpClient client = clientFactory.createClient(server.getUrl());257 HttpResponse httpResponse = client.execute(request);258 assertThat(httpResponse.getStatus()).isEqualTo(HTTP_INTERNAL_ERROR);259 }260}...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

...95 bus.addListener(NodeStatusEvent.listener(this::register));96 bus.addListener(NodeStatusEvent.listener(model::refresh));97 bus.addListener(NodeDrainComplete.listener(this::remove));98 }99 public static Distributor create(Config config) {100 Tracer tracer = new LoggingOptions(config).getTracer();101 EventBus bus = new EventBusOptions(config).getEventBus();102 HttpClient.Factory clientFactory = new NetworkOptions(config).getHttpClientFactory(tracer);103 SessionMap sessions = new SessionMapOptions(config).getSessionMap();104 BaseServerOptions serverOptions = new BaseServerOptions(config);105 return new LocalDistributor(tracer, bus, clientFactory, sessions, serverOptions.getRegistrationSecret());106 }107 @Override108 public boolean isReady() {109 try {110 return ImmutableSet.of(bus, sessions).parallelStream()111 .map(HasReadyState::isReady)112 .reduce(true, Boolean::logicalAnd);113 } catch (RuntimeException e) {114 return false;115 }116 }117 private void register(NodeStatus status) {118 Require.nonNull("Node", status);119 Lock writeLock = lock.writeLock();120 writeLock.lock();121 try {122 if (nodes.containsKey(status.getId())) {123 return;124 }125 Set<Capabilities> capabilities = status.getSlots().stream()126 .map(Slot::getStereotype)127 .map(ImmutableCapabilities::copyOf)128 .collect(toImmutableSet());129 // A new node! Add this as a remote node, since we've not called add130 RemoteNode remoteNode = new RemoteNode(131 tracer,132 clientFactory,133 status.getId(),134 status.getUri(),135 registrationSecret,136 capabilities);137 add(remoteNode);138 } finally {139 writeLock.unlock();140 }141 }142 @Override143 public LocalDistributor add(Node node) {144 Require.nonNull("Node", node);145 LOG.info(String.format("Added node %s at %s.", node.getId(), node.getUri()));146 nodes.put(node.getId(), node);147 model.add(node.getStatus());148 // Extract the health check149 Runnable runnableHealthCheck = asRunnableHealthCheck(node);150 allChecks.put(node.getId(), runnableHealthCheck);151 hostChecker.submit(runnableHealthCheck, Duration.ofMinutes(5), Duration.ofSeconds(30));152 bus.fire(new NodeAddedEvent(node.getId()));153 return this;154 }155 private Runnable asRunnableHealthCheck(Node node) {156 HealthCheck healthCheck = node.getHealthCheck();157 NodeId id = node.getId();158 return () -> {159 HealthCheck.Result result;160 try {161 result = healthCheck.check();162 } catch (Exception e) {163 LOG.log(Level.WARNING, "Unable to process node " + id, e);164 result = new HealthCheck.Result(DOWN, "Unable to run healthcheck. Assuming down");165 }166 Lock writeLock = lock.writeLock();167 writeLock.lock();168 try {169 model.setAvailability(id, result.getAvailability());170 } finally {171 writeLock.unlock();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);200 }201 } finally {202 writeLock.unlock();203 bus.fire(new NodeRemovedEvent(nodeId));204 }205 }206 @Override207 public DistributorStatus getStatus() {208 Lock readLock = this.lock.readLock();209 readLock.lock();210 try {211 return new DistributorStatus(model.getSnapshot());212 } finally {213 readLock.unlock();214 }215 }216 @Beta217 public void refresh() {218 List<Runnable> allHealthChecks = new ArrayList<>();219 Lock readLock = this.lock.readLock();220 readLock.lock();221 try {222 allHealthChecks.addAll(allChecks.values());223 } finally {224 readLock.unlock();225 }226 allHealthChecks.parallelStream().forEach(Runnable::run);227 }228 @Override229 protected Set<NodeStatus> getAvailableNodes() {230 Lock readLock = this.lock.readLock();231 readLock.lock();232 try {233 return model.getSnapshot().stream()234 .filter(node -> !DOWN.equals(node.getAvailability()))235 .collect(toImmutableSet());236 } finally {237 readLock.unlock();238 }239 }240 @Override241 protected Supplier<CreateSessionResponse> reserve(SlotId slotId, CreateSessionRequest request) {242 Require.nonNull("Slot ID", slotId);243 Require.nonNull("New Session request", request);244 Lock writeLock = this.lock.writeLock();245 writeLock.lock();246 try {247 Node node = nodes.get(slotId.getOwningNodeId());248 if (node == null) {249 return () -> {250 throw new SessionNotCreatedException("Unable to find node");251 };252 }253 model.reserve(slotId);254 return () -> {255 Optional<CreateSessionResponse> response = node.newSession(request);256 if (!response.isPresent()) {257 model.setSession(slotId, null);258 throw new SessionNotCreatedException("Unable to create session for " + request);259 }260 model.setSession(slotId, response.get().getSession());261 return response.get();262 };263 } finally {264 writeLock.unlock();265 }266 }267}...

Full Screen

Full Screen

Source:DefaultSlotSelectorTest.java Github

copy

Full Screen

...59 private URI uri;60 private Random random = new Random();61 @Before62 public void setUp() throws URISyntaxException {63 tracer = DefaultTestTracer.createTracer();64 bus = new GuavaEventBus();65 uri = new URI("http://localhost:1234");66 }67 @Test68 public void testGetPrioritizedNodeBuckets() {69 //build a bunch of nodes, using real values70 Set<NodeStatus> nodes = new HashSet<>();71 //Create 1 node that has edge, chrome, and firefox72 nodes.add(createNode("edge", "firefox", "chrome"));73 //Create 5 nodes that only have Chrome and Firefox74 IntStream.range(0, 4).forEach(ignore -> nodes.add(createNode("chrome", "firefox")));75 DefaultSlotSelector selector = new DefaultSlotSelector();76 //When you prioritize for Edge, you should only have 1 possibility77 Stream<NodeStatus> edgeNodes = nodes.stream()78 .filter(host -> host.hasCapacity(new ImmutableCapabilities("browserName", "edge")));79 Stream<NodeStatus> edgeStream = selector.getPrioritizedNodeStream(edgeNodes, new ImmutableCapabilities("browserName", "edge"))80 .filter(host -> host.hasCapacity(new ImmutableCapabilities("browserName", "edge")));81 assertThat(edgeStream.count()).isEqualTo(1);82 //When you prioritize for Chrome or Firefox, the Edge node will be removed, leaving 483 Stream<NodeStatus> chromeNodes = nodes.stream()84 .filter(host -> host.hasCapacity(new ImmutableCapabilities("browserName", "chrome")));85 Stream<NodeStatus> chromeStream = selector.getPrioritizedNodeStream(chromeNodes, new ImmutableCapabilities("browserName", "chrome"))86 .filter(host -> host.hasCapacity(new ImmutableCapabilities("browserName", "chrome")));87 assertThat(chromeStream.count()).isEqualTo(4);88 Stream<NodeStatus> firefoxNodes = nodes.stream()89 .filter(host -> host.hasCapacity(new ImmutableCapabilities("browserName", "firefox")));90 Stream<NodeStatus> firefoxStream = selector.getPrioritizedNodeStream(firefoxNodes, new ImmutableCapabilities("browserName", "firefox"))91 .filter(host -> host.hasCapacity(new ImmutableCapabilities("browserName", "firefox")));92 assertThat(firefoxStream.count()).isEqualTo(4);93 }94 @Test95 public void testAllBucketsSameSize() {96 Map<String, Set<NodeStatus>> buckets = buildBuckets(5, 5, 5, 5, 5, 5, 5, 5, 5, 5);97 DefaultSlotSelector selector = new DefaultSlotSelector();98 assertThat(selector.allBucketsSameSize(buckets)).isTrue();99 }100 @Test101 public void testAllBucketsNotSameSize() {102 Map<String, Set<NodeStatus>> buckets = buildBuckets(3, 5, 8 );103 DefaultSlotSelector selector = new DefaultSlotSelector();104 assertThat(selector.allBucketsSameSize(buckets)).isFalse();105 }106 @Test107 public void testOneBucketStillConsideredSameSize() {108 Map<String, Set<NodeStatus>> buckets = buildBuckets(3 );109 DefaultSlotSelector selector = new DefaultSlotSelector();110 assertThat(selector.allBucketsSameSize(buckets)).isTrue();111 }112 @Test113 public void testAllBucketsNotSameSizeProveNotUsingAverage() {114 //Make sure the numbers don't just average out to the same size115 Map<String, Set<NodeStatus>> buckets = buildBuckets(4, 5, 6 );116 DefaultSlotSelector selector = new DefaultSlotSelector();117 assertThat(selector.allBucketsSameSize(buckets)).isFalse();118 }119 @Test120 public void theMostLightlyLoadedNodeIsSelectedFirst() {121 // Create enough hosts so that we avoid the scheduler returning hosts in:122 // * insertion order123 // * reverse insertion order124 // * sorted with most heavily used first125 Capabilities caps = new ImmutableCapabilities("cheese", "beyaz peynir");126 NodeStatus lightest = createNode(caps, 10, 0);127 NodeStatus medium = createNode(caps, 10, 4);128 NodeStatus heavy = createNode(caps, 10, 6);129 NodeStatus massive = createNode(caps, 10, 8);130 SlotSelector selector = new DefaultSlotSelector();131 Set<SlotId> ids = selector.selectSlot(caps, ImmutableSet.of(heavy, medium, lightest, massive));132 SlotId expected = ids.iterator().next();133 assertThat(lightest.getSlots().stream()).anyMatch(slot -> expected.equals(slot.getId()));134 }135 private NodeStatus createNode(Capabilities stereotype, int count, int currentLoad) {136 NodeId nodeId = new NodeId(UUID.randomUUID());137 URI uri = createUri();138 Set<Slot> slots = new HashSet<>();139 for (int i = 0; i < currentLoad; i++) {140 Instant now = Instant.now();141 slots.add(142 new Slot(143 new SlotId(nodeId, UUID.randomUUID()),144 stereotype,145 now,146 Optional.of(new Session(new SessionId(UUID.randomUUID()), uri, stereotype, stereotype, now))));147 }148 for (int i = 0; i < count - currentLoad; i++) {149 slots.add(150 new Slot(151 new SlotId(nodeId, UUID.randomUUID()),152 stereotype,153 Instant.EPOCH,154 Optional.empty()));155 }156 return new NodeStatus(157 nodeId,158 uri,159 count,160 ImmutableSet.copyOf(slots),161 UP);162 }163 //Create a single node with the given browserName164 private NodeStatus createNode(String...browsers) {165 URI uri = createUri();166 LocalNode.Builder nodeBuilder = LocalNode.builder(tracer, bus, uri, uri, new Secret("cornish yarg"));167 nodeBuilder.maximumConcurrentSessions(browsers.length);168 Arrays.stream(browsers).forEach(browser -> {169 Capabilities caps = new ImmutableCapabilities("browserName", browser);170 nodeBuilder.add(caps, new TestSessionFactory((id, c) -> new Handler(c)));171 });172 Node myNode = nodeBuilder.build();173 return myNode.getStatus();174 }175 //Build a few node Buckets of different sizes176 private Map<String, Set<NodeStatus>> buildBuckets(int...sizes) {177 Map<String, Set<NodeStatus>> buckets = new HashMap<>();178 //The fact that it's re-using the same node doesn't matter--we're calculating "sameness"179 // based purely on the number of nodes in the Set180 IntStream.of(sizes).forEach(count -> {181 Set<NodeStatus> nodes = new HashSet<>();182 for (int i=0; i<count; i++) {183 nodes.add(createNode(UUID.randomUUID().toString()));184 }185 buckets.put(UUID.randomUUID().toString(), nodes);186 });187 return buckets;188 }189 private URI createUri() {190 try {191 return new URI("http://localhost:" + random.nextInt());192 } catch (URISyntaxException e) {193 throw new RuntimeException(e);194 }195 }196 private class Handler extends Session implements HttpHandler {197 private Handler(Capabilities capabilities) {198 super(new SessionId(UUID.randomUUID()), uri, new ImmutableCapabilities(), capabilities, Instant.now());199 }200 @Override201 public HttpResponse execute(HttpRequest req) throws UncheckedIOException {202 return new HttpResponse();203 }...

Full Screen

Full Screen

Source:RouterTest.java Github

copy

Full Screen

...67 private Router router;68 private Secret registrationSecret;69 @Before70 public void setUp() {71 tracer = DefaultTestTracer.createTracer();72 bus = new GuavaEventBus();73 handler = new CombinedHandler();74 HttpClient.Factory clientFactory = new PassthroughHttpClient.Factory(handler);75 sessions = new LocalSessionMap(tracer, bus);76 handler.addHandler(sessions);77 registrationSecret = new Secret("stinking bishop");78 queue = new LocalNewSessionQueue(79 tracer,80 bus,81 new DefaultSlotMatcher(),82 Duration.ofSeconds(2),83 Duration.ofSeconds(2),84 registrationSecret);85 handler.addHandler(queue);...

Full Screen

Full Screen

Source:DefaultSlotSelector.java Github

copy

Full Screen

...39 .sorted(40 Comparator.comparingLong(this::getNumberOfSupportedBrowsers)41 // Now sort by node which has the lowest load (natural ordering)42 .thenComparingDouble(NodeStatus::getLoad)43 // Then last session created (oldest first), so natural ordering again44 .thenComparingLong(NodeStatus::getLastSessionCreated)45 // And use the node id as a tie-breaker.46 .thenComparing(NodeStatus::getId))47 .flatMap(node -> node.getSlots().stream()48 .filter(slot -> !slot.getSession().isPresent())49 .filter(slot -> slot.isSupporting(capabilities))50 .map(Slot::getId))51 .collect(toImmutableSet());52 }53 @VisibleForTesting54 long getNumberOfSupportedBrowsers(NodeStatus nodeStatus) {55 return nodeStatus.getSlots()56 .stream()57 .map(slot -> slot.getStereotype().getBrowserName().toLowerCase())58 .distinct()59 .count();60 }61 public static SlotSelector create(Config config) {62 return new DefaultSlotSelector();63 }64}...

Full Screen

Full Screen

Source:GridModelTest.java Github

copy

Full Screen

...29import org.openqa.selenium.remote.tracing.DefaultTestTracer;30import org.openqa.selenium.remote.tracing.Tracer;31import java.time.Duration;32public class GridModelTest {33 private final Tracer tracer = DefaultTestTracer.createTracer();34 private final EventBus events = new GuavaEventBus();35 private final HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();36 private final SessionMap sessions = new LocalSessionMap(tracer, events);37 private final Secret secret = new Secret("cheese");38 LocalNewSessionQueue queue = new LocalNewSessionQueue(39 tracer,40 events,41 new DefaultSlotMatcher(),42 Duration.ofSeconds(2),43 Duration.ofSeconds(2),44 secret);45 private final Distributor distributor = new LocalDistributor(46 tracer,47 events,48 clientFactory,49 sessions,...

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1public DefaultSlotSelector create() {2 return new DefaultSlotSelector();3}4public RandomSlotSelector create() {5 return new RandomSlotSelector();6}7public RoundRobinSlotSelector create() {8 return new RoundRobinSlotSelector();9}10public StickySlotSelector create() {11 return new StickySlotSelector();12}13public WeightBasedSlotSelector create() {14 return new WeightBasedSlotSelector();15}16public WeightedStickySlotSelector create() {17 return new WeightedStickySlotSelector();18}19public DefaultSlotSelector create() {20 return new DefaultSlotSelector();21}22public RandomSlotSelector create() {23 return new RandomSlotSelector();24}25public RoundRobinSlotSelector create() {26 return new RoundRobinSlotSelector();27}28public StickySlotSelector create() {29 return new StickySlotSelector();30}31public WeightBasedSlotSelector create() {32 return new WeightBasedSlotSelector();33}

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;2import org.openqa.selenium.grid.distributor.selector.SlotSelector;3import org.openqa.selenium.grid.distributor.selector.SlotSelectorFactory;4import org.openqa.selenium.grid.config.Config;5import org.openqa.selenium.grid.config.ConfigException;6import org.openqa.selenium.grid.config.MemoizedConfig;7import org.openqa.selenium.grid.config.TomlConfig;8import org.openqa.selenium.grid.distributor.Distributor;9import org.openqa.selenium.grid.distributor.local.LocalDistributor;10import org.openqa.selenium.grid.distributor.local.StickyStrategy;11import org.openqa.selenium.grid.node.local.LocalNode;12import org.openqa.selenium.grid.server.BaseServerOptions;13import org.openqa.selenium.grid.server.Server;14import org.openqa.selenium.grid.server.ServerFlags;15import org.openqa.selenium.grid.web.Routable;16import org.openqa.selenium.internal.Require;17import org.openqa.selenium.json.Json;18import org.openqa.selenium.remote.http.HttpHandler;19import org.openqa.selenium.remote.tracing.Tracer;20import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer;21import org.openqa.selenium.remote.tracing.opentelemetry.config.OpenTelemetryConfiguration;22import org.openqa.selenium.remote.tracing.opentelemetry.config.OpenTelemetryConfigurationBuilder;23import org.openqa.selenium.remote.tracing.opentelemetry.exporter.JaegerExporter;24import org.openqa.selenium.remote.tracing.opentelemetry.exporter.ZipkinExporter;25import org.openqa.selenium.remote.tracing.opentelemetry.exporter.ZipkinExporterBuilder;26import org.openqa.selenium.remote.tracing.opentelemetry.exporter.ZipkinExporterConfiguration;27import org.openqa.selenium.remote.tracing.opentelemetry.exporter.ZipkinExporterConfigurationBuilder;28import org.openqa.selenium.remote.tracing.opentelemetry.global.GlobalOpenTelemetry;29import org.openqa.selenium.remote.tracing.opentelemetry.global.GlobalOpenTelemetryConfiguration;30import org.openqa.selenium.remote.tracing.opentelemetry.global.GlobalOpenTelemetryConfigurationBuilder;31import java.io.IOException;32import java.net.URI;33import java.net.URISyntaxException;34import java.time.Duration;35import java.util.ArrayList;36import java.util.Collection;37import java.util.List;38import java.util.Map;39import java.util.Objects;40import java.util.Optional;41import java.util.Set;42import java.util.concurrent.ConcurrentHashMap;43import java.util.function.Supplier;44import java.util.logging.Level;45import java.util.logging.Logger;46import java.util.stream.Collectors;47import static java.util.logging.Level.INFO;48import static java.util.logging.Level.WARNING;49import static org.openqa.selenium.grid.config.StandardGridRoles.DISTRIBUTOR_ROLE;50import static org.openqa

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium.grid.distributor.selector;2import org.openqa.selenium.grid.data.Session;3import org.openqa.selenium.grid.distributor.Distributor;4import org.openqa.selenium.grid.distributor.RemoteDistributor;5import org.openqa.selenium.grid.node.Node;6import org.openqa.selenium.grid.node.local.LocalNode;7import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;8import org.openqa.selenium.grid.web.Values;9import org.openqa.selenium.internal.Require;10import org.openqa.selenium.remote.http.HttpClient;11import org.openqa.selenium.remote.tracing.DefaultTestTracer;12import org.openqa.selenium.remote.tracing.Tracer;13import java.net.URI;14import java.util.Objects;15import java.util.function.Function;16public class DefaultSlotSelector implements SlotSelector {17 private final Tracer tracer;18 private final Distributor distributor;19 private final SessionMap sessions;20 public DefaultSlotSelector(21 SessionMap sessions) {22 this.tracer = Require.nonNull("Tracer", tracer);23 this.distributor = Require.nonNull("Distributor", distributor);24 this.sessions = Require.nonNull("Session map", sessions);25 }26 public static Function<Values, SlotSelector> create() {27 return values -> {28 Tracer tracer = DefaultTestTracer.createTracer();29 SessionMap sessions = new LocalSessionMap(tracer);30 Distributor distributor = new RemoteDistributor(tracer, HttpClient.Factory.createDefault(), sessions);31 return new DefaultSlotSelector(tracer, distributor, sessions);32 };33 }34 public Slot selectSlot(Session session) {35 return distributor.getSlot(session);36 }37 public void add(Node node) {38 distributor.add(node);39 }40 public void remove(Node node) {41 distributor.remove(node);42 }43 public static void main(String[] args) {44 Tracer tracer = DefaultTestTracer.createTracer();45 SessionMap sessions = new LocalSessionMap(tracer);46 Distributor distributor = new RemoteDistributor(tracer, HttpClient.Factory.createDefault(), sessions);47 SlotSelector selector = new DefaultSlotSelector(tracer, distributor, sessions);48 .add(sessions)49 .add(distributor)50 .build();51 selector.add(node);52 }53}

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;2import org.openqa.selenium.grid.distributor.selector.SlotSelector;3import org.openqa.selenium.grid.node.Node;4import org.openqa.selenium.grid.node.NodeId;5import org.openqa.selenium.grid.node.local.LocalNode;6import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;7import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap;8import org.openqa.selenium.grid.web.Routable;9import org.openqa.selenium.remote.http.HttpClient;10import org.openqa.selenium.remote.tracing.Tracer;11import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracer;12import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptions;13import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsBuilder;14import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsBuilder.ZipkinTracerOptionsBuilderImpl;15import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl;16import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl.ZipkinTracerOptionsImplBuilder;17import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl.ZipkinTracerOptionsImplBuilderImpl;18import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl.ZipkinTracerOptionsImplImpl;19import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl.ZipkinTracerOptionsImplImplBuilder;20import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl.ZipkinTracerOptionsImplImplBuilderImpl;21import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl.ZipkinTracerOptionsImplImplImpl;22import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl.ZipkinTracerOptionsImplImplImplBuilder;23import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl.ZipkinTracerOptionsImplImplImplBuilderImpl;24import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl.ZipkinTracerOptionsImplImplImplImpl;25import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl.ZipkinTracerOptionsImplImplImplImplBuilder;26import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl.ZipkinTracerOptionsImplImplImplImplBuilderImpl;27import org.openqa.selenium.remote.tracing.zipkin.ZipkinTracerOptionsImpl.ZipkinTracerOptionsImplImplImplImplImpl;28import org.openqa.selenium.remote

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1 DefaultSlotSelector defaultSlotSelector = new DefaultSlotSelector();2 DefaultSlotSelector defaultSlotSelector = new DefaultSlotSelector();3 defaultSlotSelector.getDefaultSlotSelector();4 defaultSlotSelector.getDefaultSlotSelector();5 defaultSlotSelector.getDefaultSlotSelector();6 defaultSlotSelector.getDefaultSlotSelector();7 defaultSlotSelector.getDefaultSlotSelector();8 defaultSlotSelector.getDefaultSlotSelector();9 defaultSlotSelector.getDefaultSlotSelector();10 defaultSlotSelector.getDefaultSlotSelector();11 defaultSlotSelector.getDefaultSlotSelector();12 defaultSlotSelector.getDefaultSlotSelector();13 defaultSlotSelector.getDefaultSlotSelector();14 defaultSlotSelector.getDefaultSlotSelector();15 defaultSlotSelector.getDefaultSlotSelector();16 defaultSlotSelector.getDefaultSlotSelector();17 defaultSlotSelector.getDefaultSlotSelector();18 defaultSlotSelector.getDefaultSlotSelector();19 defaultSlotSelector.getDefaultSlotSelector();20 defaultSlotSelector.getDefaultSlotSelector();21 defaultSlotSelector.getDefaultSlotSelector();22 defaultSlotSelector.getDefaultSlotSelector();23 defaultSlotSelector.getDefaultSlotSelector();24 defaultSlotSelector.getDefaultSlotSelector();25 defaultSlotSelector.getDefaultSlotSelector();26 defaultSlotSelector.getDefaultSlotSelector();27 defaultSlotSelector.getDefaultSlotSelector();28 defaultSlotSelector.getDefaultSlotSelector();29 defaultSlotSelector.getDefaultSlotSelector();30 defaultSlotSelector.getDefaultSlotSelector();

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 DefaultSlotSelector

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful