How to use listener method of org.openqa.selenium.grid.data.NodeHeartBeatEvent class

Best Selenium code snippet using org.openqa.selenium.grid.data.NodeHeartBeatEvent.listener

Source:DistributorTest.java Github

copy

Full Screen

...167 false);168 distributor.add(node);169 AtomicBoolean heartbeatStarted = new AtomicBoolean();170 CountDownLatch latch = new CountDownLatch(1);171 bus.addListener(NodeHeartBeatEvent.listener(nodeStatus -> {172 if (node.getId().equals(nodeStatus.getId())) {173 latch.countDown();174 heartbeatStarted.set(true);175 }176 }));177 waitToHaveCapacity(distributor);178 boolean eventFiredAndListenedTo = false;179 try {180 eventFiredAndListenedTo = latch.await(30, TimeUnit.SECONDS);181 } catch (InterruptedException e) {182 Assert.fail("Thread Interrupted");183 }184 assertThat(eventFiredAndListenedTo).isTrue();185 assertThat(heartbeatStarted.get()).isTrue();186 }187 @Test188 public void shouldBeAbleToAddANodeAndCreateASession() {189 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);190 NewSessionQueue queue = new LocalNewSessionQueue(191 tracer,192 bus,193 new DefaultSlotMatcher(),194 Duration.ofSeconds(2),195 Duration.ofSeconds(2),196 registrationSecret);197 LocalNode node = LocalNode.builder(tracer, bus, routableUri, routableUri, registrationSecret)198 .add(199 caps,200 new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))201 .build();202 Distributor distributor = new LocalDistributor(203 tracer,204 bus,205 new PassthroughHttpClient.Factory(node),206 sessions,207 queue,208 new DefaultSlotSelector(),209 registrationSecret,210 Duration.ofMinutes(5),211 false);212 distributor.add(node);213 waitToHaveCapacity(distributor);214 MutableCapabilities sessionCaps = new MutableCapabilities(caps);215 sessionCaps.setCapability("sausages", "gravy");216 Either<SessionNotCreatedException, CreateSessionResponse> result =217 distributor.newSession(createRequest(sessionCaps));218 assertThatEither(result).isRight();219 Session session = result.right().getSession();220 assertThat(session.getCapabilities()).isEqualTo(sessionCaps);221 assertThat(session.getUri()).isEqualTo(routableUri);222 }223 @Test224 public void creatingASessionAddsItToTheSessionMap() {225 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);226 NewSessionQueue queue = new LocalNewSessionQueue(227 tracer,228 bus,229 new DefaultSlotMatcher(),230 Duration.ofSeconds(2),231 Duration.ofSeconds(2),232 registrationSecret);233 LocalNode node = LocalNode.builder(tracer, bus, routableUri, routableUri, registrationSecret)234 .add(235 caps,236 new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))237 .build();238 LocalDistributor distributor = new LocalDistributor(239 tracer,240 bus,241 new PassthroughHttpClient.Factory(node),242 sessions,243 queue,244 new DefaultSlotSelector(),245 registrationSecret,246 Duration.ofMinutes(5),247 false);248 distributor.add(node);249 waitToHaveCapacity(distributor);250 MutableCapabilities sessionCaps = new MutableCapabilities(caps);251 sessionCaps.setCapability("sausages", "gravy");252 Either<SessionNotCreatedException, CreateSessionResponse> result =253 distributor.newSession(createRequest(sessionCaps));254 assertThatEither(result).isRight();255 Session returned = result.right().getSession();256 Session session = sessions.get(returned.getId());257 assertThat(session.getCapabilities()).isEqualTo(sessionCaps);258 assertThat(session.getUri()).isEqualTo(routableUri);259 }260 @Test261 public void shouldBeAbleToRemoveANode() throws MalformedURLException {262 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);263 NewSessionQueue queue = new LocalNewSessionQueue(264 tracer,265 bus,266 new DefaultSlotMatcher(),267 Duration.ofSeconds(2),268 Duration.ofSeconds(2),269 registrationSecret);270 LocalNode node = LocalNode.builder(tracer, bus, routableUri, routableUri, registrationSecret)271 .add(272 caps,273 new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))274 .build();275 Distributor local = new LocalDistributor(276 tracer,277 bus,278 new PassthroughHttpClient.Factory(node),279 sessions,280 queue,281 new DefaultSlotSelector(),282 registrationSecret,283 Duration.ofMinutes(5),284 false);285 Distributor distributor = new RemoteDistributor(286 tracer,287 new PassthroughHttpClient.Factory(local),288 new URL("http://does.not.exist"),289 registrationSecret);290 distributor.add(node);291 distributor.remove(node.getId());292 Either<SessionNotCreatedException, CreateSessionResponse> result =293 local.newSession(createRequest(caps));294 assertThatEither(result).isLeft();295 }296 @Test297 public void testDrainingNodeDoesNotAcceptNewSessions() {298 SessionMap sessions = new LocalSessionMap(tracer, bus);299 NewSessionQueue queue = new LocalNewSessionQueue(300 tracer,301 bus,302 new DefaultSlotMatcher(),303 Duration.ofSeconds(2),304 Duration.ofSeconds(2),305 registrationSecret);306 LocalNode node = LocalNode.builder(tracer, bus, routableUri, routableUri, registrationSecret)307 .add(308 caps,309 new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))310 .build();311 Distributor distributor = new LocalDistributor(312 tracer,313 bus,314 new PassthroughHttpClient.Factory(node),315 sessions,316 queue,317 new DefaultSlotSelector(),318 registrationSecret,319 Duration.ofMinutes(5),320 false);321 distributor.add(node);322 distributor.drain(node.getId());323 assertTrue(node.isDraining());324 Either<SessionNotCreatedException, CreateSessionResponse> result = distributor.newSession(createRequest(caps));325 assertThatEither(result).isLeft();326 }327 @Test328 public void testDrainedNodeShutsDownOnceEmpty() throws InterruptedException {329 SessionMap sessions = new LocalSessionMap(tracer, bus);330 NewSessionQueue queue = new LocalNewSessionQueue(331 tracer,332 bus,333 new DefaultSlotMatcher(),334 Duration.ofSeconds(2),335 Duration.ofSeconds(2),336 registrationSecret);337 LocalNode node = LocalNode.builder(tracer, bus, routableUri, routableUri, registrationSecret)338 .add(339 caps,340 new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))341 .build();342 CountDownLatch latch = new CountDownLatch(1);343 bus.addListener(NodeDrainComplete.listener(ignored -> latch.countDown()));344 Distributor distributor = new LocalDistributor(345 tracer,346 bus,347 new PassthroughHttpClient.Factory(node),348 sessions,349 queue,350 new DefaultSlotSelector(),351 registrationSecret,352 Duration.ofMinutes(5),353 false);354 distributor.add(node);355 waitToHaveCapacity(distributor);356 distributor.drain(node.getId());357 latch.await(5, TimeUnit.SECONDS);358 assertThat(latch.getCount()).isEqualTo(0);359 assertThat(distributor.getStatus().getNodes()).isEmpty();360 Either<SessionNotCreatedException, CreateSessionResponse> result =361 distributor.newSession(createRequest(caps));362 assertThatEither(result).isLeft();363 }364 @Test365 public void drainedNodeDoesNotShutDownIfNotEmpty() throws InterruptedException {366 SessionMap sessions = new LocalSessionMap(tracer, bus);367 NewSessionQueue queue = new LocalNewSessionQueue(368 tracer,369 bus,370 new DefaultSlotMatcher(),371 Duration.ofSeconds(2),372 Duration.ofSeconds(2),373 registrationSecret);374 LocalNode node = LocalNode.builder(tracer, bus, routableUri, routableUri, registrationSecret)375 .add(376 caps,377 new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))378 .build();379 CountDownLatch latch = new CountDownLatch(1);380 bus.addListener(NodeDrainComplete.listener(ignored -> latch.countDown()));381 Distributor distributor = new LocalDistributor(382 tracer,383 bus,384 new PassthroughHttpClient.Factory(node),385 sessions,386 queue,387 new DefaultSlotSelector(),388 registrationSecret,389 Duration.ofMinutes(5),390 false);391 distributor.add(node);392 waitToHaveCapacity(distributor);393 Either<SessionNotCreatedException, CreateSessionResponse> session =394 distributor.newSession(createRequest(caps));395 assertThatEither(session).isRight();396 distributor.drain(node.getId());397 latch.await(5, TimeUnit.SECONDS);398 assertThat(latch.getCount()).isEqualTo(1);399 assertThat(distributor.getStatus().getNodes().size()).isEqualTo(1);400 }401 @Test402 public void drainedNodeShutsDownAfterSessionsFinish() throws InterruptedException {403 SessionMap sessions = new LocalSessionMap(tracer, bus);404 NewSessionQueue queue = new LocalNewSessionQueue(405 tracer,406 bus,407 new DefaultSlotMatcher(),408 Duration.ofSeconds(2),409 Duration.ofSeconds(2),410 registrationSecret);411 LocalNode node = LocalNode.builder(tracer, bus, routableUri, routableUri, registrationSecret)412 .add(413 caps,414 new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))415 .add(416 caps,417 new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))418 .build();419 CountDownLatch latch = new CountDownLatch(1);420 bus.addListener(NodeDrainComplete.listener(ignored -> latch.countDown()));421 Distributor distributor = new LocalDistributor(422 tracer,423 bus,424 new PassthroughHttpClient.Factory(node),425 sessions,426 queue,427 new DefaultSlotSelector(),428 registrationSecret,429 Duration.ofMinutes(5),430 false);431 distributor.add(node);432 waitToHaveCapacity(distributor);433 Either<SessionNotCreatedException, CreateSessionResponse> firstResponse =434 distributor.newSession(createRequest(caps));...

Full Screen

Full Screen

Source:SauceNode.java Github

copy

Full Screen

...161 tmpFileCleanup.submit(tempFileSystems::cleanUp, Duration.ofSeconds(30), Duration.ofSeconds(30));162 Regularly regularHeartBeat = new Regularly("Heartbeat Node: " + externalUri);163 regularHeartBeat.submit(() -> bus.fire(new NodeHeartBeatEvent(getStatus())), heartbeatPeriod,164 heartbeatPeriod);165 bus.addListener(SessionClosedEvent.listener(id -> {166 // Listen to session terminated events so we know when to fire the NodeDrainComplete event167 if (this.isDraining()) {168 int done = pendingSessions.decrementAndGet();169 if (done <= 0) {170 LOG.info("Firing node drain complete message");171 bus.fire(new NodeDrainComplete(this.getId()));172 }173 }174 }));175 Runtime.getRuntime().addShutdownHook(new Thread(this::stopAllSessions));176 new JMXHelper().register(this);177 }178 public static SauceNode.Builder builder(179 Tracer tracer,...

Full Screen

Full Screen

Source:LocalNode.java Github

copy

Full Screen

...159 .build();160 this.regularly = new Regularly("Local Node: " + externalUri);161 regularly.submit(currentSessions::cleanUp, Duration.ofSeconds(30), Duration.ofSeconds(30));162 regularly.submit(tempFileSystems::cleanUp, Duration.ofSeconds(30), Duration.ofSeconds(30));163 bus.addListener(NodeAddedEvent.listener(nodeId -> {164 if (getId().equals(nodeId)) {165 // Lets avoid to create more than one "Regularly" when the Node registers again.166 if (!heartBeatStarted.getAndSet(true)) {167 regularly.submit(168 () -> bus.fire(new NodeHeartBeatEvent(getStatus())), heartbeatPeriod, heartbeatPeriod);169 }170 }171 }));172 bus.addListener(SessionClosedEvent.listener(id -> {173 try {174 this.stop(id);175 } catch (NoSuchSessionException ignore) {176 }177 if (this.isDraining()) {178 int done = pendingSessions.decrementAndGet();179 if (done <= 0) {180 LOG.info("Firing node drain complete message");181 bus.fire(new NodeDrainComplete(this.getId()));182 }183 }184 }));185 new JMXHelper().register(this);186 }...

Full Screen

Full Screen

Source:KubernetesNode.java Github

copy

Full Screen

...91 var sessionCleanup = new Regularly("Session Cleanup Node: " + uri);92 sessionCleanup.submit(currentSessions::cleanUp, Duration.ofSeconds(30), Duration.ofSeconds(30));93 var regularHeartBeat = new Regularly("Heartbeat Node: " + uri);94 regularHeartBeat.submit(() -> bus.fire(new NodeHeartBeatEvent(getStatus())), heartbeatPeriod, heartbeatPeriod);95 bus.addListener(SessionClosedEvent.listener(id -> {96 if (this.isDraining() && pendingSessions.decrementAndGet() <= 0) {97 LOG.info("Firing node drain complete message");98 bus.fire(new NodeDrainComplete(this.getId()));99 }100 }));101 additionalRoutes = combine(102 get("/downloads/{sessionId}/{fileName}")103 .to(params -> new GetFile(getActiveSession(sessionIdFrom(params)), fileNameFrom(params))),104 delete("/downloads/{sessionId}/{fileName}")105 .to(params -> new DeleteFile(getActiveSession(sessionIdFrom(params)), fileNameFrom(params))),106 get("/downloads/{sessionId}")107 .to(params -> new ListFiles(getActiveSession(sessionIdFrom(params)))),108 delete("/downloads/{sessionId}")109 .to(params -> new DeleteFiles(getActiveSession(sessionIdFrom(params)))));...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

...123 this.nodes = new ConcurrentHashMap<>();124 this.sessionRequests = Require.nonNull("New Session Request Queue", sessionRequests);125 this.registrationSecret = Require.nonNull("Registration secret", registrationSecret);126 this.healthcheckInterval = Require.nonNull("Health check interval", healthcheckInterval);127 bus.addListener(NodeStatusEvent.listener(this::register));128 bus.addListener(NodeStatusEvent.listener(model::refresh));129 bus.addListener(NodeHeartBeatEvent.listener(nodeStatus -> {130 if (nodes.containsKey(nodeStatus.getId())) {131 model.touch(nodeStatus.getId());132 } else {133 register(nodeStatus);134 }135 }));136 bus.addListener(NodeDrainComplete.listener(this::remove));137 bus.addListener(NewSessionRequestEvent.listener(requestIds::offer));138 Regularly regularly = new Regularly("Local Distributor");139 regularly.submit(model::purgeDeadNodes, Duration.ofSeconds(30), Duration.ofSeconds(30));140 Thread shutdownHook = new Thread(this::callExecutorShutdown);141 Runtime.getRuntime().addShutdownHook(shutdownHook);142 NewSessionRunnable runnable = new NewSessionRunnable();143 ThreadFactory threadFactory = r -> {144 Thread thread = new Thread(r);145 thread.setName("New Session Creation");146 thread.setDaemon(true);147 return thread;148 };149 executorService = Executors.newSingleThreadScheduledExecutor(threadFactory);150 executorService.scheduleAtFixedRate(runnable, 0, 1000, TimeUnit.MILLISECONDS);151 }...

Full Screen

Full Screen

Source:NodeHeartBeatEvent.java Github

copy

Full Screen

...24 private static final EventName NODE_HEARTBEAT = new EventName("node-heartbeat");25 public NodeHeartBeatEvent(NodeStatus status) {26 super(NODE_HEARTBEAT, Require.nonNull("Node status", status));27 }28 public static EventListener<NodeStatus> listener(Consumer<NodeStatus> handler) {29 Require.nonNull("Handler", handler);30 return new EventListener<NodeStatus>(NODE_HEARTBEAT, NodeStatus.class, handler);31 }32}...

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.NodeHeartBeatEvent;2import org.openqa.selenium.grid.data.NodeStatusEvent;3import org.openqa.selenium.grid.data.Session;4import org.openqa.selenium.grid.data.SessionEvent;5import org.openqa.selenium.grid.data.SessionRequest;6import org.openqa.selenium.grid.data.SessionRequestEvent;7import org.openqa.selenium.grid.events.Event;8import org.openqa.selenium.grid.events.EventBus;9import org.openqa.selenium.grid.events.EventListener;10import org.openqa.selenium.grid.events.EventName;11import org.openqa.selenium.grid.events.Listener;12import org.openqa.selenium.grid.events.NewSessionEvent;13import org.openqa.selenium.grid.events.NewSessionRequestEvent;14import org.openqa.selenium.grid.events.NodeAddedEvent;15import org.openqa.selenium.grid.events.NodeRemovedEvent;16import org.openqa.selenium.grid.events.NodeStatusEvent;17import org.openqa.selenium.grid.events.SessionClosedEvent;18import org.openqa.selenium.grid.events.SessionCreatedEvent;19import org.openqa.selenium.grid.events.SessionRequestedEvent;20import org.openqa.selenium.grid.events.SessionStartedEvent;21import org.openqa.selenium.grid.events.SessionTerminatedEvent;22import org.openqa.selenium.grid.events.StaleSessionEvent;23import org.openqa.selenium.grid.events.StaleSessionRequestEvent;24import org.openqa.selenium.grid.events.TerminateSessionEvent;25import org.openqa.selenium.grid.events.TerminateSessionRequestEvent;26import org.openqa.selenium.grid.events.UnregisterNodeEvent;27import org.openqa.selenium.grid.node.local.LocalNode;28import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;29import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap;30import org.openqa.selenium.internal.Require;31import org.openqa.selenium.remote.http.HttpClient;32import org.openqa.selenium.remote.tracing.Tracer;33import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer;34import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracerOptions;35import org.openqa.selenium.remote.tracing.opentelemetry.context.jfr.OpenTelemetryJfrContext;36import org.openqa.selenium.remote.tracing.opentelemetry.context.log4j2.OpenTelemetryLog4j2Context;37import org.openqa.selenium.remote.tracing.opentelemetry.context.slf4j.OpenTelemetrySlf4jContext;38import org.openqa.selenium.remote.tracing.opentelemetry.context.threadlocal.OpenTelemetryThreadLocalContext;39import org.openqa.selenium.remote.tracing.opentelemetry.jaeger.OpenTelemetryJaegerExporter;40import org.openqa.selenium.remote.tracing.opentelemetry.logging.OpenTelemetryLoggingExporter;41import org.openqa.selenium.remote.tracing.opentelemetry.zipkin.OpenTelemetryZipkinExporter;42import org

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 NodeHeartBeatEvent

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful