How to use remove method of org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue class

Best Selenium code snippet using org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue.remove

Source:NewSessionQueuerTest.java Github

copy

Full Screen

...102 @Test103 public void shouldBeAbleToAddToQueueAndGetValidResponse() {104 AtomicBoolean isPresent = new AtomicBoolean(false);105 bus.addListener(NewSessionRequestEvent.listener(reqId -> {106 Optional<HttpRequest> sessionRequest = this.local.remove();107 isPresent.set(sessionRequest.isPresent());108 Capabilities capabilities = new ImmutableCapabilities("browserName", "chrome");109 try {110 SessionId sessionId = new SessionId("123");111 Session session =112 new Session(113 sessionId,114 new URI("http://example.com"),115 caps,116 capabilities,117 Instant.now());118 CreateSessionResponse sessionResponse = new CreateSessionResponse(119 session,120 JSON.toJson(121 ImmutableMap.of(122 "value", ImmutableMap.of(123 "sessionId", sessionId,124 "capabilities", capabilities)))125 .getBytes(UTF_8));126 NewSessionResponse newSessionResponse =127 new NewSessionResponse(reqId, sessionResponse.getSession(),128 sessionResponse.getDownstreamEncodedResponse());129 bus.fire(new NewSessionResponseEvent(newSessionResponse));130 } catch (URISyntaxException e) {131 bus.fire(132 new NewSessionRejectedEvent(133 new NewSessionErrorResponse(new RequestId(UUID.randomUUID()), "Error")));134 }135 }));136 HttpResponse httpResponse = local.addToQueue(request);137 assertThat(isPresent.get()).isTrue();138 assertEquals(httpResponse.getStatus(), HTTP_OK);139 }140 @Test141 public void shouldBeAbleToAddToQueueAndGetErrorResponse() {142 AtomicBoolean isPresent = new AtomicBoolean(false);143 bus.addListener(NewSessionRequestEvent.listener(reqId -> {144 Optional<HttpRequest> sessionRequest = this.local.remove();145 isPresent.set(sessionRequest.isPresent());146 bus.fire(147 new NewSessionRejectedEvent(148 new NewSessionErrorResponse(reqId, "Error")));149 }));150 HttpResponse httpResponse = local.addToQueue(request);151 assertThat(isPresent.get()).isTrue();152 assertEquals(httpResponse.getStatus(), HTTP_INTERNAL_ERROR);153 }154 @Test155 public void shouldBeAbleToAddToQueueRemotelyAndGetErrorResponse() {156 AtomicBoolean isPresent = new AtomicBoolean(false);157 bus.addListener(NewSessionRequestEvent.listener(reqId -> {158 Optional<HttpRequest> sessionRequest = this.remote.remove();159 isPresent.set(sessionRequest.isPresent());160 bus.fire(161 new NewSessionRejectedEvent(162 new NewSessionErrorResponse(reqId, "Could not poll the queue")));163 }));164 HttpResponse httpResponse = remote.addToQueue(request);165 assertThat(isPresent.get()).isTrue();166 assertEquals(httpResponse.getStatus(), HTTP_INTERNAL_ERROR);167 }168 @Test169 public void shouldBeAbleToRemoveFromQueue() {170 Optional<HttpRequest> httpRequest = local.remove();171 assertFalse(httpRequest.isPresent());172 }173 @Test174 public void shouldBeClearQueue() {175 RequestId requestId = new RequestId(UUID.randomUUID());176 sessionQueue.offerLast(request, requestId);177 int count = local.clearQueue();178 assertEquals(count, 1);179 assertFalse(local.remove().isPresent());180 }181 @Test182 public void shouldBeClearQueueRemotely() {183 RequestId requestId = new RequestId(UUID.randomUUID());184 sessionQueue.offerLast(request, requestId);185 int count = remote.clearQueue();186 assertEquals(count, 1);187 assertFalse(remote.remove().isPresent());188 }189 @Test190 public void shouldBeClearQueueAndFireRejectedEvent() {191 AtomicBoolean result = new AtomicBoolean(false);192 RequestId requestId = new RequestId(UUID.randomUUID());193 bus.addListener(NewSessionRejectedEvent.listener(response ->194 result.set(response.getRequestId()195 .equals(requestId))));196 sessionQueue.offerLast(request, requestId);197 int count = remote.clearQueue();198 assertThat(result.get()).isTrue();199 assertEquals(count, 1);200 assertFalse(remote.remove().isPresent());201 }202 @Test203 public void shouldBeAbleToRemoveFromQueueRemotely() {204 Optional<HttpRequest> httpRequest = remote.remove();205 assertFalse(httpRequest.isPresent());206 }207 @Test208 public void shouldBeAbleToAddAgainToQueue() {209 boolean added = local.retryAddToQueue(request, new RequestId(UUID.randomUUID()));210 assertTrue(added);211 }212 @Test213 public void shouldBeAbleToAddAgainToQueueRemotely() {214 HttpRequest request = createRequest(payload, POST, "/se/grid/newsessionqueuer/session");215 boolean added = remote.retryAddToQueue(request, new RequestId(UUID.randomUUID()));216 assertTrue(added);217 }218 @Test219 public void shouldBeAbleToRetryRequest() {220 AtomicBoolean isPresent = new AtomicBoolean(false);221 AtomicBoolean retrySuccess = new AtomicBoolean(false);222 bus.addListener(NewSessionRequestEvent.listener(reqId -> {223 // Keep a count of event fired224 count++;225 Optional<HttpRequest> sessionRequest = this.remote.remove();226 isPresent.set(sessionRequest.isPresent());227 if (count == 1) {228 retrySuccess.set(remote.retryAddToQueue(sessionRequest.get(), reqId));229 }230 // Only if it was retried after an interval, the count is 2231 if (count == 2) {232 ImmutableCapabilities capabilities = new ImmutableCapabilities("browserName", "chrome");233 try {234 SessionId sessionId = new SessionId("123");235 Session session =236 new Session(237 sessionId,238 new URI("http://example.com"),239 caps,240 capabilities,241 Instant.now());242 CreateSessionResponse sessionResponse = new CreateSessionResponse(243 session,244 JSON.toJson(245 ImmutableMap.of(246 "value", ImmutableMap.of(247 "sessionId", sessionId,248 "capabilities", capabilities)))249 .getBytes(UTF_8));250 NewSessionResponse newSessionResponse =251 new NewSessionResponse(reqId, sessionResponse.getSession(),252 sessionResponse.getDownstreamEncodedResponse());253 bus.fire(new NewSessionResponseEvent(newSessionResponse));254 } catch (URISyntaxException e) {255 bus.fire(256 new NewSessionRejectedEvent(257 new NewSessionErrorResponse(new RequestId(UUID.randomUUID()), "Error")));258 }259 }260 }));261 HttpResponse httpResponse = remote.addToQueue(request);262 assertThat(isPresent.get()).isTrue();263 assertThat(retrySuccess.get()).isTrue();264 assertEquals(httpResponse.getStatus(), HTTP_OK);265 }266 @Test267 public void shouldBeAbleToHandleMultipleSessionRequestsAtTheSameTime() {268 bus.addListener(NewSessionRequestEvent.listener(reqId -> {269 Optional<HttpRequest> sessionRequest = this.local.remove();270 ImmutableCapabilities capabilities = new ImmutableCapabilities("browserName", "chrome");271 try {272 SessionId sessionId = new SessionId(UUID.randomUUID());273 Session session =274 new Session(275 sessionId,276 new URI("http://example.com"),277 caps,278 capabilities,279 Instant.now());280 CreateSessionResponse sessionResponse = new CreateSessionResponse(281 session,282 JSON.toJson(283 ImmutableMap.of(284 "value", ImmutableMap.of(285 "sessionId", sessionId,286 "capabilities", capabilities)))287 .getBytes(UTF_8));288 NewSessionResponse newSessionResponse =289 new NewSessionResponse(reqId, sessionResponse.getSession(),290 sessionResponse.getDownstreamEncodedResponse());291 bus.fire(new NewSessionResponseEvent(newSessionResponse));292 } catch (URISyntaxException e) {293 bus.fire(294 new NewSessionRejectedEvent(295 new NewSessionErrorResponse(new RequestId(UUID.randomUUID()), "Error")));296 }297 }));298 ExecutorService executor = Executors.newFixedThreadPool(2);299 Callable<HttpResponse> callable = () -> remote.addToQueue(request);300 Future<HttpResponse> firstRequest = executor.submit(callable);301 Future<HttpResponse> secondRequest = executor.submit(callable);302 try {303 HttpResponse firstResponse = firstRequest.get(30, TimeUnit.SECONDS);304 HttpResponse secondResponse = secondRequest.get(30, TimeUnit.SECONDS);305 String firstResponseContents = Contents.string(firstResponse);306 String secondResponseContents = Contents.string(secondResponse);307 assertEquals(firstResponse.getStatus(), HTTP_OK);308 assertEquals(secondResponse.getStatus(), HTTP_OK);309 assertNotEquals(firstResponseContents, secondResponseContents);310 } catch (InterruptedException | ExecutionException | TimeoutException e) {311 fail("Could not create session");312 }313 executor.shutdown();314 }315 @Test316 public void shouldBeAbleToTimeoutARequestOnRetry() {317 Tracer tracer = DefaultTestTracer.createTracer();318 LocalNewSessionQueue sessionQueue = new LocalNewSessionQueue(319 tracer,320 bus,321 Duration.ofSeconds(4),322 Duration.ofSeconds(2));323 local = new LocalNewSessionQueuer(tracer, bus, sessionQueue);324 HttpClient client = new PassthroughHttpClient(local);325 remote = new RemoteNewSessionQueuer(tracer, client);326 HttpRequest request = createRequest(payload, POST, "/session");327 request.addHeader(SESSIONREQUEST_TIMESTAMP_HEADER,328 Long.toString(1539091064));329 AtomicInteger count = new AtomicInteger();330 bus.addListener(NewSessionRequestEvent.listener(reqId -> {331 // Add to front of queue, when retry is triggered it will check if request timed out332 count.incrementAndGet();333 remote.retryAddToQueue(request, reqId);334 }));335 HttpResponse httpResponse = remote.addToQueue(request);336 assertEquals(count.get(),1);337 assertEquals(httpResponse.getStatus(), HTTP_INTERNAL_ERROR);338 }339 @Test340 public void shouldBeAbleToTimeoutARequestOnPoll() {341 Tracer tracer = DefaultTestTracer.createTracer();342 LocalNewSessionQueue sessionQueue = new LocalNewSessionQueue(343 tracer,344 bus,345 Duration.ofSeconds(4),346 Duration.ofSeconds(0));347 local = new LocalNewSessionQueuer(tracer, bus, sessionQueue);348 HttpClient client = new PassthroughHttpClient(local);349 remote = new RemoteNewSessionQueuer(tracer, client);350 AtomicBoolean isPresent = new AtomicBoolean();351 bus.addListener(NewSessionRequestEvent.listener(reqId -> {352 Optional<HttpRequest> request = remote.remove();353 isPresent.set(request.isPresent());354 bus.fire(355 new NewSessionRejectedEvent(356 new NewSessionErrorResponse(reqId, "Error")));357 }));358 HttpResponse httpResponse = remote.addToQueue(request);359 assertEquals(httpResponse.getStatus(), HTTP_INTERNAL_ERROR);360 assertThat(isPresent.get()).isFalse();361 }362 @Test363 public void shouldBeAbleToClearQueueAndRejectMultipleRequests() {364 ExecutorService executor = Executors.newFixedThreadPool(2);365 Callable<HttpResponse> callable = () -> remote.addToQueue(request);366 Future<HttpResponse> firstRequest = executor.submit(callable);...

Full Screen

Full Screen

Source:LocalDistributorTest.java Github

copy

Full Screen

...166 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 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(178 tracer,179 bus,180 Duration.ofSeconds(2),181 Duration.ofSeconds(2));182 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(183 tracer,184 bus,185 localNewSessionQueue,186 registrationSecret);187 Distributor distributor = new LocalDistributor(188 tracer,189 bus,190 clientFactory,191 new LocalSessionMap(tracer, bus),192 queuer,193 registrationSecret,194 Duration.ofMinutes(5));195 distributor.add(localNode);196 distributor.add(localNode);197 DistributorStatus status = distributor.getStatus();198 //Should only be one node after dupe check199 final Set<NodeStatus> nodes = status.getNodes();200 assertThat(nodes.size()).isEqualTo(1);201 }202 @Test203 public void shouldBeAbleToAddMultipleSessionsConcurrently() throws Exception {204 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(205 tracer,206 bus,207 Duration.ofSeconds(2),208 Duration.ofSeconds(2));209 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(210 tracer,211 bus,212 localNewSessionQueue,213 registrationSecret);214 LocalDistributor distributor = new LocalDistributor(215 tracer,216 bus,217 clientFactory,218 new LocalSessionMap(tracer, bus),219 queuer,220 registrationSecret,221 Duration.ofMinutes(5));222 // Add one node to ensure that everything is created in that.223 Capabilities caps = new ImmutableCapabilities("browserName", "cheese");224 class VerifyingHandler extends Session implements HttpHandler {225 private VerifyingHandler(SessionId id, Capabilities capabilities) {226 super(id, uri, new ImmutableCapabilities(), capabilities, Instant.now());227 }228 @Override229 public HttpResponse execute(HttpRequest req) {230 Optional<SessionId> id = HttpSessionId.getSessionId(req.getUri()).map(SessionId::new);231 assertThat(id).isEqualTo(Optional.of(getId()));232 return new HttpResponse();233 }234 }235 // Only use one node.236 Node node = LocalNode.builder(tracer, bus, uri, uri, registrationSecret)237 .add(caps, new TestSessionFactory(VerifyingHandler::new))238 .add(caps, new TestSessionFactory(VerifyingHandler::new))239 .add(caps, new TestSessionFactory(VerifyingHandler::new))240 .maximumConcurrentSessions(3)241 .build();242 distributor.add(node);243 HttpRequest req = new HttpRequest(HttpMethod.POST, "/session")244 .setContent(Contents.asJson(ImmutableMap.of(245 "capabilities", ImmutableMap.of(246 "alwaysMatch", ImmutableMap.of(247 "browserName", "cheese")))));248 List<Callable<SessionId>> callables = new ArrayList<>();249 for (int i = 0; i < 3; i++) {250 callables.add(() -> {251 Either<SessionNotCreatedException, CreateSessionResponse> result =252 distributor.newSession(req);253 if (result.isRight()) {254 CreateSessionResponse res = result.right();255 assertThat(res.getSession().getCapabilities().getBrowserName()).isEqualTo("cheese");256 return res.getSession().getId();257 } else {258 fail("Session creation failed", result.left());259 }260 return null;261 });262 }263 List<Future<SessionId>> futures = Executors.newFixedThreadPool(3).invokeAll(callables);264 for (Future<SessionId> future : futures) {265 SessionId id = future.get(2, TimeUnit.SECONDS);266 // Now send a random command.267 HttpResponse res = node.execute(new HttpRequest(GET, String.format("/session/%s/url", id)));268 assertThat(res.isSuccessful()).isTrue();269 }270 }271 @Test272 public void testDrainNodeFromDistributor() {273 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(274 tracer,275 bus,276 Duration.ofSeconds(2),277 Duration.ofSeconds(2));278 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(279 tracer,280 bus,281 localNewSessionQueue,282 registrationSecret);283 Distributor distributor = new LocalDistributor(284 tracer,285 bus,286 clientFactory,287 new LocalSessionMap(tracer, bus),288 queuer,289 registrationSecret,290 Duration.ofMinutes(5));291 distributor.add(localNode);292 assertThat(localNode.isDraining()).isFalse();293 //Check the size - there should be one node294 DistributorStatus statusBefore = distributor.getStatus();295 Set<NodeStatus> nodesBefore = statusBefore.getNodes();296 assertThat(nodesBefore.size()).isEqualTo(1);297 NodeStatus nodeBefore = nodesBefore.iterator().next();298 assertThat(nodeBefore.getAvailability()).isNotEqualTo(DRAINING);299 distributor.drain(localNode.getId());300 assertThat(localNode.isDraining()).isTrue();301 //Recheck the status - there should still be no node, it is removed302 DistributorStatus statusAfter = distributor.getStatus();303 Set<NodeStatus> nodesAfter = statusAfter.getNodes();304 assertThat(nodesAfter.size()).isEqualTo(0);305 }306 @Test307 public void testDrainNodeFromNode() {308 assertThat(localNode.isDraining()).isFalse();309 LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(310 tracer,311 bus,312 Duration.ofSeconds(2),313 Duration.ofSeconds(2));314 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(315 tracer,...

Full Screen

Full Screen

Source:LocalNewSessionQueue.java Github

copy

Full Screen

...121 LOG.log(Level.INFO, "Request {0} timed out", requestId);122 Lock writeLock = lock.writeLock();123 writeLock.lock();124 try {125 sessionRequests.remove();126 } finally {127 writeLock.unlock();128 bus.fire(new NewSessionRejectedEvent(129 new NewSessionErrorResponse(requestId, "New session request timed out")));130 }131 } else {132 LOG.log(Level.INFO,133 "Adding request back to the queue. All slots are busy. Request: {0}",134 requestId);135 bus.fire(new NewSessionRequestEvent(requestId));136 }137 }138 @Override139 public Optional<HttpRequest> poll() {...

Full Screen

Full Screen

Source:LocalNewSessionQueueTest.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.sessionqueue.local;18import org.junit.Before;19import org.junit.Test;20import org.openqa.selenium.Capabilities;21import org.openqa.selenium.ImmutableCapabilities;22import org.openqa.selenium.events.EventBus;23import org.openqa.selenium.events.local.GuavaEventBus;24import org.openqa.selenium.grid.data.NewSessionRequestEvent;25import org.openqa.selenium.grid.data.RequestId;26import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;27import org.openqa.selenium.remote.NewSessionPayload;28import org.openqa.selenium.remote.http.HttpMethod;29import org.openqa.selenium.remote.http.HttpRequest;30import org.openqa.selenium.remote.tracing.DefaultTestTracer;31import org.openqa.selenium.remote.tracing.Tracer;32import java.io.IOException;33import java.io.UncheckedIOException;34import java.time.Duration;35import java.util.Optional;36import java.util.UUID;37import java.util.concurrent.CountDownLatch;38import java.util.concurrent.TimeUnit;39import java.util.concurrent.atomic.AtomicBoolean;40import static org.assertj.core.api.Assertions.assertThat;41import static org.junit.Assert.assertEquals;42import static org.junit.Assert.assertTrue;43import static org.openqa.selenium.remote.http.Contents.utf8String;44import static org.openqa.selenium.remote.http.HttpMethod.POST;45public class LocalNewSessionQueueTest {46 private EventBus bus;47 private Capabilities caps;48 private NewSessionQueue sessionQueue;49 private HttpRequest expectedSessionRequest;50 private RequestId requestId;51 @Before52 public void setUp() {53 Tracer tracer = DefaultTestTracer.createTracer();54 caps = new ImmutableCapabilities("browserName", "chrome");55 bus = new GuavaEventBus();56 requestId = new RequestId(UUID.randomUUID());57 sessionQueue = new LocalNewSessionQueue(tracer, bus, Duration.ofSeconds(1));58 NewSessionPayload payload = NewSessionPayload.create(caps);59 expectedSessionRequest = createRequest(payload, POST, "/session");60 }61 @Test62 public void shouldBeAbleToAddToEndOfQueue() throws InterruptedException {63 AtomicBoolean result = new AtomicBoolean(false);64 CountDownLatch latch = new CountDownLatch(1);65 bus.addListener(NewSessionRequestEvent.listener(reqId -> {66 result.set(reqId.equals(requestId));67 latch.countDown();68 }));69 boolean added = sessionQueue.offerLast(expectedSessionRequest, requestId);70 assertTrue(added);71 72 latch.await(5, TimeUnit.SECONDS);73 assertThat(latch.getCount()).isEqualTo(0);74 assertTrue(result.get());75 }76 @Test77 public void shouldBeAbleToRemoveFromFrontOfQueue() {78 boolean added = sessionQueue.offerLast(expectedSessionRequest, requestId);79 assertTrue(added);80 Optional<HttpRequest> receivedRequest = sessionQueue.poll();81 assertTrue(receivedRequest.isPresent());82 assertEquals(expectedSessionRequest, receivedRequest.get());83 }84 @Test85 public void shouldAddTimestampHeader() {86 boolean added = sessionQueue.offerLast(expectedSessionRequest, requestId);87 assertTrue(added);88 Optional<HttpRequest> receivedRequest = sessionQueue.poll();89 assertTrue(receivedRequest.isPresent());90 HttpRequest request = receivedRequest.get();91 assertEquals(expectedSessionRequest, request);92 assertTrue(request.getHeader(NewSessionQueue.SESSIONREQUEST_TIMESTAMP_HEADER) != null);93 }94 @Test95 public void shouldAddRequestIdHeader() {96 boolean added = sessionQueue.offerLast(expectedSessionRequest, requestId);97 assertTrue(added);98 Optional<HttpRequest> receivedRequest = sessionQueue.poll();99 assertTrue(receivedRequest.isPresent());100 HttpRequest request = receivedRequest.get();101 assertEquals(expectedSessionRequest, request);102 String polledRequestId = request.getHeader(NewSessionQueue.SESSIONREQUEST_ID_HEADER);103 assertTrue(polledRequestId != null);104 assertEquals(requestId, new RequestId(UUID.fromString(polledRequestId)));105 }106 @Test107 public void shouldBeAbleToAddToFrontOfQueue() {108 ImmutableCapabilities chromeCaps = new ImmutableCapabilities("browserName", "chrome");109 NewSessionPayload chromePayload = NewSessionPayload.create(chromeCaps);110 HttpRequest chromeRequest = createRequest(chromePayload, POST, "/session");111 RequestId chromeRequestId = new RequestId(UUID.randomUUID());112 ImmutableCapabilities firefoxCaps = new ImmutableCapabilities("browserName", "firefox");113 NewSessionPayload firefoxpayload = NewSessionPayload.create(firefoxCaps);114 HttpRequest firefoxRequest = createRequest(firefoxpayload, POST, "/session");115 RequestId firefoxRequestId = new RequestId(UUID.randomUUID());116 boolean addedChromeRequest = sessionQueue.offerFirst(chromeRequest, chromeRequestId);117 assertTrue(addedChromeRequest);118 boolean addFirefoxRequest = sessionQueue.offerFirst(firefoxRequest, firefoxRequestId);119 assertTrue(addFirefoxRequest);120 Optional<HttpRequest> polledFirefoxRequest = sessionQueue.poll();121 assertTrue(polledFirefoxRequest.isPresent());122 assertEquals(firefoxRequest, polledFirefoxRequest.get());123 Optional<HttpRequest> polledChromeRequest = sessionQueue.poll();124 assertTrue(polledChromeRequest.isPresent());125 assertEquals(chromeRequest, polledChromeRequest.get());126 }127 @Test128 public void shouldBeClearAPopulatedQueue() {129 sessionQueue.offerLast(expectedSessionRequest, requestId);130 sessionQueue.offerLast(expectedSessionRequest, requestId);131 int count = sessionQueue.clear();132 assertEquals(count, 2);133 }134 @Test135 public void shouldBeClearAEmptyQueue() {136 int count = sessionQueue.clear();137 assertEquals(count, 0);138 }139 private HttpRequest createRequest(NewSessionPayload payload, HttpMethod httpMethod, String uri) {140 StringBuilder builder = new StringBuilder();141 try {142 payload.writeTo(builder);143 } catch (IOException e) {144 throw new UncheckedIOException(e);145 }146 HttpRequest request = new HttpRequest(httpMethod, uri);147 request.setContent(utf8String(builder.toString()));148 return request;149 }150}...

Full Screen

Full Screen

Source:LocalNewSessionQueuer.java Github

copy

Full Screen

...59 public boolean retryAddToQueue(HttpRequest request, RequestId reqId) {60 return sessionRequests.offerFirst(request, reqId);61 }62 @Override63 public Optional<HttpRequest> remove() {64 return sessionRequests.poll();65 }66 @Override67 public int clearQueue() {68 return sessionRequests.clear();69 }70 @Override71 public boolean isReady() {72 return bus.isReady();73 }74}...

Full Screen

Full Screen

remove

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium.grid.sessionqueue.local;2import org.openqa.selenium.grid.data.SessionRequest;3import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;4import org.openqa.selenium.grid.sessionqueue.NewSessionQueuer;5import org.openqa.selenium.grid.sessionqueue.SessionNotCreatedException;6import org.openqa.selenium.internal.Require;7import org.openqa.selenium.remote.tracing.Tracer;8import java.util.ArrayList;9import java.util.List;10import java.util.concurrent.BlockingQueue;11import java.util.concurrent.LinkedBlockingQueue;12public class LocalNewSessionQueue implements NewSessionQueue {13 private final BlockingQueue<SessionRequest> queue;14 private final NewSessionQueuer queuer;15 public LocalNewSessionQueue(Tracer tracer, NewSessionQueuer queuer) {16 this.queue = new LinkedBlockingQueue<>();17 this.queuer = Require.nonNull("New session queuer", queuer);18 }19 public void add(SessionRequest request) {20 Require.nonNull("Session request", request);21 queue.add(request);22 }23 public List<SessionRequest> remove(String id) {24 Require.nonNull("Session request id", id);25 List<SessionRequest> removedRequests = new ArrayList<>();26 for (SessionRequest request : queue) {27 if (id.equals(request.getId())) {28 removedRequests.add(request);29 }30 }31 queue.removeAll(removedRequests);32 return removedRequests;33 }34 public SessionRequest remove() throws SessionNotCreatedException {35 try {36 SessionRequest request = queue.take();37 queuer.onRequestComplete(request);38 return request;39 } catch (InterruptedException e) {40 throw new SessionNotCreatedException(e);41 }42 }43 public int size() {44 return queue.size();45 }46}47[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ selenium ---48[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ selenium ---

Full Screen

Full Screen

remove

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;2import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;3import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;4import org.openqa.selenium.remote.tracing.DefaultTestTracer;5import org.openqa.selenium.remote.tracer.DefaultTestTracer;6import org.openqa.selenium.remote.tracing.Tracer;7import org.openqa.selenium.remote.tracer.Tracer;8public class RemoveSessionQueue {9 public static void main(String[] args) {10 Tracer tracer = DefaultTestTracer.createTracer();11 NewSessionQueue queue = new LocalNewSessionQueue(tracer);12 queue.add("session1");13 queue.add("session2");14 queue.add("session3");15 queue.remove("session2");16 System.out.println(queue);17 }18}

Full Screen

Full Screen

remove

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;2import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueuer;3import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueuerOptions;4import org.openqa.selenium.remote.NewSessionPayload;5import org.openqa.selenium.remote.http.HttpClient;6import org.openqa.selenium.remote.http.HttpClientFactory;7import org.openqa.selenium.remote.tracing.Tracer;8import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryOptions;9import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer;10import java.net.URI;11import java.time.Duration;12import java.util.concurrent.TimeUnit;13public class LocalNewSessionQueueExample {14 public static void main(String[] args) {15 Tracer tracer = OpenTelemetryTracer.createTracer(OpenTelemetryOptions.builder().build());16 HttpClientFactory clientFactory = HttpClient.Factory.createDefault();17 LocalNewSessionQueuerOptions options = LocalNewSessionQueuerOptions.builder()18 .setSessionRequestTimeout(Duration.ofSeconds(30))19 .setSessionRequestPollingInterval(Duration.ofSeconds(1))20 .setSessionRequestPollingAttempts(5)21 .build();22 LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(23 options);24 LocalNewSessionQueue queue = queuer.getQueue();25 NewSessionPayload payload = NewSessionPayload.create(26 "{\\\"desiredCapabilities\\\":{\\\"browserName\\\":\\\"chrome\\\"}}");27 }28}29import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;30import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueuer;31import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueuerOptions;32import org.openqa.selenium.remote.NewSessionPayload;33import org.openqa.selenium.remote.http.HttpClient;34import org.openqa.selenium.remote.http.HttpClientFactory;35import org.openqa.selenium.remote.tracing.Tracer;36import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryOptions;37import org.openqa.selenium.remote.tracing.opente

Full Screen

Full Screen

remove

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;2import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;3import org.openqa.selenium.grid.sessionqueue.NewSessionQueuer;4import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions;5import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueuerOptions;6import org.openqa.selenium.remote.NewSessionPayload;7import org.openqa.selenium.remote.http.HttpClient;8import org.openqa.selenium.remote.tracing.Tracer;9import org.openqa.selenium.remote.tracing.distributed.DistributedTracer;10import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryOptions;11import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer;12import java.net.URI;13import java.net.URISyntaxException;14import java.util.UUID;15public class RemoveSessionFromQueue {16 public static void main(String[] args) throws URISyntaxException {17 Tracer tracer = createTracer();18 NewSessionQueue queue = createNewSessionQueue(tracer);19 NewSessionQueuer queuer = createNewSessionQueuer(tracer);20 queuer.addToQueue(payload);21 UUID sessionId = payload.getSessionId();22 queue.remove(sessionId);23 }24 private static Tracer createTracer() {25 OpenTelemetryTracer tracer = OpenTelemetryTracer.create(26 OpenTelemetryOptions.builder()27 .withServiceName("example")28 .withExporter("jaeger")29 .build());30 return new DistributedTracer(tracer);31 }32 private static NewSessionQueue createNewSessionQueue(Tracer tracer) {33 return new LocalNewSessionQueue(34 NewSessionQueueOptions.builder().build(),35 }36 private static NewSessionQueuer createNewSessionQueuer(Tracer

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