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

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

Source:DistributorTest.java Github

copy

Full Screen

...33import org.openqa.selenium.grid.data.CreateSessionResponse;34import org.openqa.selenium.grid.data.DefaultSlotMatcher;35import org.openqa.selenium.grid.data.DistributorStatus;36import org.openqa.selenium.grid.data.NodeDrainComplete;37import org.openqa.selenium.grid.data.NodeHeartBeatEvent;38import org.openqa.selenium.grid.data.NodeStatus;39import org.openqa.selenium.grid.data.RequestId;40import org.openqa.selenium.grid.data.Session;41import org.openqa.selenium.grid.data.SessionRequest;42import org.openqa.selenium.grid.data.Slot;43import org.openqa.selenium.grid.distributor.local.LocalDistributor;44import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;45import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;46import org.openqa.selenium.grid.node.HealthCheck;47import org.openqa.selenium.grid.node.Node;48import org.openqa.selenium.grid.node.local.LocalNode;49import org.openqa.selenium.grid.security.Secret;50import org.openqa.selenium.grid.sessionmap.SessionMap;51import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;52import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;53import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;54import org.openqa.selenium.grid.testing.EitherAssert;55import org.openqa.selenium.grid.testing.PassthroughHttpClient;56import org.openqa.selenium.grid.testing.TestSessionFactory;57import org.openqa.selenium.grid.web.CombinedHandler;58import org.openqa.selenium.internal.Either;59import org.openqa.selenium.net.PortProber;60import org.openqa.selenium.remote.Dialect;61import org.openqa.selenium.remote.SessionId;62import org.openqa.selenium.remote.http.HttpClient;63import org.openqa.selenium.remote.http.HttpHandler;64import org.openqa.selenium.remote.http.HttpRequest;65import org.openqa.selenium.remote.http.HttpResponse;66import org.openqa.selenium.remote.tracing.DefaultTestTracer;67import org.openqa.selenium.remote.tracing.Tracer;68import org.openqa.selenium.support.ui.FluentWait;69import org.openqa.selenium.support.ui.Wait;70import java.io.UncheckedIOException;71import java.net.MalformedURLException;72import java.net.URI;73import java.net.URISyntaxException;74import java.net.URL;75import java.time.Duration;76import java.time.Instant;77import java.util.HashMap;78import java.util.HashSet;79import java.util.Map;80import java.util.Set;81import java.util.UUID;82import java.util.concurrent.CountDownLatch;83import java.util.concurrent.TimeUnit;84import java.util.concurrent.atomic.AtomicBoolean;85import java.util.concurrent.atomic.AtomicReference;86import java.util.logging.Logger;87import java.util.stream.Collectors;88import static org.assertj.core.api.Assertions.assertThat;89import static org.assertj.core.api.Assertions.fail;90import static org.junit.Assert.assertFalse;91import static org.junit.Assert.assertTrue;92import static org.openqa.selenium.grid.data.Availability.DOWN;93import static org.openqa.selenium.grid.data.Availability.UP;94import static org.openqa.selenium.remote.Dialect.W3C;95public class DistributorTest {96 private static final Logger LOG = Logger.getLogger("Distributor Test");97 private final Secret registrationSecret = new Secret("hellim");98 private final Wait<Object> wait = new FluentWait<>(new Object()).withTimeout(Duration.ofSeconds(5));99 private Tracer tracer;100 private EventBus bus;101 private Distributor local;102 private Capabilities stereotype;103 private Capabilities caps;104 private URI nodeUri;105 private URI routableUri;106 private static <A, B> EitherAssert<A, B> assertThatEither(Either<A, B> either) {107 return new EitherAssert<>(either);108 }109 @Before110 public void setUp() throws URISyntaxException {111 nodeUri = new URI("http://example:5678");112 routableUri = createUri();113 tracer = DefaultTestTracer.createTracer();114 bus = new GuavaEventBus();115 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);116 NewSessionQueue queue = new LocalNewSessionQueue(117 tracer,118 bus,119 new DefaultSlotMatcher(),120 Duration.ofSeconds(2),121 Duration.ofSeconds(2),122 registrationSecret);123 local = new LocalDistributor(124 tracer,125 bus,126 HttpClient.Factory.createDefault(),127 sessions,128 queue,129 new DefaultSlotSelector(),130 registrationSecret,131 Duration.ofMinutes(5),132 false);133 stereotype = new ImmutableCapabilities("browserName", "cheese");134 caps = new ImmutableCapabilities("browserName", "cheese");135 }136 @Test137 public void creatingANewSessionWithoutANodeEndsInFailure() {138 Either<SessionNotCreatedException, CreateSessionResponse> result = local.newSession(createRequest(caps));139 assertThatEither(result).isLeft();140 }141 @Test142 public void shouldStartHeartBeatOnNodeRegistration() {143 EventBus bus = new GuavaEventBus();144 LocalSessionMap sessions = new LocalSessionMap(tracer, bus);145 NewSessionQueue queue = new LocalNewSessionQueue(146 tracer,147 bus,148 new DefaultSlotMatcher(),149 Duration.ofSeconds(2),150 Duration.ofSeconds(2),151 registrationSecret);152 LocalNode node = LocalNode.builder(tracer, bus, routableUri, routableUri, registrationSecret)153 .add(154 caps,155 new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now())))156 .heartbeatPeriod(Duration.ofSeconds(10))157 .build();158 Distributor distributor = new LocalDistributor(159 tracer,160 bus,161 new PassthroughHttpClient.Factory(node),162 sessions,163 queue,164 new DefaultSlotSelector(),165 registrationSecret,166 Duration.ofMinutes(5),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();...

Full Screen

Full Screen

Source:SauceNode.java Github

copy

Full Screen

...36import org.openqa.selenium.grid.data.CreateSessionRequest;37import org.openqa.selenium.grid.data.CreateSessionResponse;38import org.openqa.selenium.grid.data.NodeDrainComplete;39import org.openqa.selenium.grid.data.NodeDrainStarted;40import org.openqa.selenium.grid.data.NodeHeartBeatEvent;41import org.openqa.selenium.grid.data.NodeId;42import org.openqa.selenium.grid.data.NodeStatus;43import org.openqa.selenium.grid.data.Session;44import org.openqa.selenium.grid.data.SessionClosedEvent;45import org.openqa.selenium.grid.data.Slot;46import org.openqa.selenium.grid.data.SlotId;47import org.openqa.selenium.grid.jmx.JMXHelper;48import org.openqa.selenium.grid.jmx.ManagedAttribute;49import org.openqa.selenium.grid.jmx.ManagedService;50import org.openqa.selenium.grid.node.ActiveSession;51import org.openqa.selenium.grid.node.HealthCheck;52import org.openqa.selenium.grid.node.Node;53import org.openqa.selenium.grid.node.SessionFactory;54import org.openqa.selenium.grid.node.config.NodeOptions;55import org.openqa.selenium.grid.node.docker.DockerAssetsPath;56import org.openqa.selenium.grid.node.local.LocalNode;57import org.openqa.selenium.grid.node.local.SessionSlot;58import org.openqa.selenium.grid.security.Secret;59import org.openqa.selenium.internal.Debug;60import org.openqa.selenium.internal.Either;61import org.openqa.selenium.internal.Require;62import org.openqa.selenium.io.TemporaryFilesystem;63import org.openqa.selenium.io.Zip;64import org.openqa.selenium.json.Json;65import org.openqa.selenium.remote.SessionId;66import org.openqa.selenium.remote.http.HttpMethod;67import org.openqa.selenium.remote.http.HttpRequest;68import org.openqa.selenium.remote.http.HttpResponse;69import org.openqa.selenium.remote.tracing.AttributeKey;70import org.openqa.selenium.remote.tracing.EventAttribute;71import org.openqa.selenium.remote.tracing.EventAttributeValue;72import org.openqa.selenium.remote.tracing.Span;73import org.openqa.selenium.remote.tracing.Status;74import org.openqa.selenium.remote.tracing.Tracer;75import java.io.File;76import java.io.IOException;77import java.io.InputStreamReader;78import java.io.UncheckedIOException;79import java.net.URI;80import java.net.URISyntaxException;81import java.nio.file.Files;82import java.nio.file.Paths;83import java.nio.file.StandardCopyOption;84import java.time.Duration;85import java.time.Instant;86import java.util.Collections;87import java.util.HashMap;88import java.util.List;89import java.util.Map;90import java.util.Optional;91import java.util.Set;92import java.util.UUID;93import java.util.concurrent.ExecutionException;94import java.util.concurrent.atomic.AtomicInteger;95import java.util.logging.Level;96import java.util.logging.Logger;97import java.util.stream.Collectors;98@ManagedService(objectName = "com.saucelabs.grid:type=Node,name=SauceNode",99 description = "SauceNode running the webdriver sessions and uploading results to Sauce.")100public class SauceNode extends Node {101 private static final Logger LOG = Logger.getLogger(LocalNode.class.getName());102 private final EventBus bus;103 private final URI externalUri;104 private final URI gridUri;105 private final Duration heartbeatPeriod;106 private final HealthCheck healthCheck;107 private final int maxSessionCount;108 private final List<SessionSlot> factories;109 private final Cache<SessionId, SessionSlot> currentSessions;110 private final Cache<SessionId, TemporaryFilesystem> tempFileSystems;111 private final AtomicInteger pendingSessions = new AtomicInteger();112 private SauceNode(113 Tracer tracer,114 EventBus bus,115 URI uri,116 URI gridUri,117 HealthCheck healthCheck,118 int maxSessionCount,119 Ticker ticker,120 Duration sessionTimeout,121 Duration heartbeatPeriod,122 List<SessionSlot> factories,123 Secret registrationSecret) {124 super(tracer, new NodeId(UUID.randomUUID()), uri, registrationSecret);125 this.bus = Require.nonNull("Event bus", bus);126 this.externalUri = Require.nonNull("Remote node URI", uri);127 this.gridUri = Require.nonNull("Grid URI", gridUri);128 this.maxSessionCount = Math.min(Require.positive("Max session count", maxSessionCount), factories.size());129 this.heartbeatPeriod = heartbeatPeriod;130 this.factories = ImmutableList.copyOf(factories);131 Require.nonNull("Registration secret", registrationSecret);132 this.healthCheck = healthCheck == null ?133 () -> new HealthCheck.Result(134 isDraining() ? DRAINING : UP,135 String.format("%s is %s", uri, isDraining() ? "draining" : "up")) :136 healthCheck;137 this.currentSessions = CacheBuilder.newBuilder()138 .expireAfterAccess(sessionTimeout)139 .ticker(ticker)140 .removalListener((RemovalListener<SessionId, SessionSlot>) notification -> {141 // Attempt to stop the session142 LOG.log(Debug.getDebugLogLevel(), "Stopping session {0}", notification.getKey().toString());143 SessionSlot slot = notification.getValue();144 if (!slot.isAvailable()) {145 slot.stop();146 }147 })148 .build();149 this.tempFileSystems = CacheBuilder.newBuilder()150 .expireAfterAccess(sessionTimeout)151 .ticker(ticker)152 .removalListener((RemovalListener<SessionId, TemporaryFilesystem>) notification -> {153 TemporaryFilesystem tempFS = notification.getValue();154 tempFS.deleteTemporaryFiles();155 tempFS.deleteBaseDir();156 })157 .build();158 Regularly sessionCleanup = new Regularly("Session Cleanup Node: " + externalUri);159 sessionCleanup.submit(currentSessions::cleanUp, Duration.ofSeconds(30), Duration.ofSeconds(30));160 Regularly tmpFileCleanup = new Regularly("TempFile Cleanup Node: " + externalUri);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 }...

Full Screen

Full Screen

Source:LocalNode.java Github

copy

Full Screen

...35import org.openqa.selenium.grid.data.CreateSessionResponse;36import org.openqa.selenium.grid.data.NodeAddedEvent;37import org.openqa.selenium.grid.data.NodeDrainComplete;38import org.openqa.selenium.grid.data.NodeDrainStarted;39import org.openqa.selenium.grid.data.NodeHeartBeatEvent;40import org.openqa.selenium.grid.data.NodeId;41import org.openqa.selenium.grid.data.NodeStatus;42import org.openqa.selenium.grid.data.Session;43import org.openqa.selenium.grid.data.SessionClosedEvent;44import org.openqa.selenium.grid.data.Slot;45import org.openqa.selenium.grid.data.SlotId;46import org.openqa.selenium.grid.jmx.JMXHelper;47import org.openqa.selenium.grid.jmx.ManagedAttribute;48import org.openqa.selenium.grid.jmx.ManagedService;49import org.openqa.selenium.grid.node.ActiveSession;50import org.openqa.selenium.grid.node.HealthCheck;51import org.openqa.selenium.grid.node.Node;52import org.openqa.selenium.grid.node.SessionFactory;53import org.openqa.selenium.grid.node.config.NodeOptions;54import org.openqa.selenium.grid.security.Secret;55import org.openqa.selenium.internal.Either;56import org.openqa.selenium.internal.Require;57import org.openqa.selenium.io.TemporaryFilesystem;58import org.openqa.selenium.io.Zip;59import org.openqa.selenium.json.Json;60import org.openqa.selenium.remote.SessionId;61import org.openqa.selenium.remote.http.HttpRequest;62import org.openqa.selenium.remote.http.HttpResponse;63import org.openqa.selenium.remote.tracing.AttributeKey;64import org.openqa.selenium.remote.tracing.EventAttribute;65import org.openqa.selenium.remote.tracing.EventAttributeValue;66import org.openqa.selenium.remote.tracing.Span;67import org.openqa.selenium.remote.tracing.Status;68import org.openqa.selenium.remote.tracing.Tracer;69import java.io.File;70import java.io.IOException;71import java.io.UncheckedIOException;72import java.net.URI;73import java.net.URISyntaxException;74import java.time.Clock;75import java.time.Duration;76import java.time.Instant;77import java.util.HashMap;78import java.util.List;79import java.util.Map;80import java.util.Optional;81import java.util.Set;82import java.util.UUID;83import java.util.concurrent.ExecutionException;84import java.util.concurrent.atomic.AtomicBoolean;85import java.util.concurrent.atomic.AtomicInteger;86import java.util.logging.Logger;87import java.util.stream.Collectors;88import static com.google.common.collect.ImmutableSet.toImmutableSet;89import static org.openqa.selenium.grid.data.Availability.DRAINING;90import static org.openqa.selenium.grid.data.Availability.UP;91import static org.openqa.selenium.grid.node.CapabilityResponseEncoder.getEncoder;92import static org.openqa.selenium.remote.HttpSessionId.getSessionId;93import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES;94import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;95import static org.openqa.selenium.remote.http.Contents.asJson;96import static org.openqa.selenium.remote.http.Contents.string;97import static org.openqa.selenium.remote.http.HttpMethod.DELETE;98@ManagedService(objectName = "org.seleniumhq.grid:type=Node,name=LocalNode",99 description = "Node running the webdriver sessions.")100public class LocalNode extends Node {101 private static final Json JSON = new Json();102 private static final Logger LOG = Logger.getLogger(LocalNode.class.getName());103 private final EventBus bus;104 private final URI externalUri;105 private final URI gridUri;106 private final Duration heartbeatPeriod;107 private final HealthCheck healthCheck;108 private final int maxSessionCount;109 private final List<SessionSlot> factories;110 private final Cache<SessionId, SessionSlot> currentSessions;111 private final Cache<SessionId, TemporaryFilesystem> tempFileSystems;112 private final Regularly regularly;113 private final AtomicInteger pendingSessions = new AtomicInteger();114 private final AtomicBoolean heartBeatStarted = new AtomicBoolean(false);115 private LocalNode(116 Tracer tracer,117 EventBus bus,118 URI uri,119 URI gridUri,120 HealthCheck healthCheck,121 int maxSessionCount,122 Ticker ticker,123 Duration sessionTimeout,124 Duration heartbeatPeriod,125 List<SessionSlot> factories,126 Secret registrationSecret) {127 super(tracer, new NodeId(UUID.randomUUID()), uri, registrationSecret);128 this.bus = Require.nonNull("Event bus", bus);129 this.externalUri = Require.nonNull("Remote node URI", uri);130 this.gridUri = Require.nonNull("Grid URI", gridUri);131 this.maxSessionCount = Math.min(Require.positive("Max session count", maxSessionCount), factories.size());132 this.heartbeatPeriod = heartbeatPeriod;133 this.factories = ImmutableList.copyOf(factories);134 Require.nonNull("Registration secret", registrationSecret);135 this.healthCheck = healthCheck == null ?136 () -> new HealthCheck.Result(137 isDraining() ? DRAINING : UP,138 String.format("%s is %s", uri, isDraining() ? "draining" : "up")) :139 healthCheck;140 this.currentSessions = CacheBuilder.newBuilder()141 .expireAfterAccess(sessionTimeout)142 .ticker(ticker)143 .removalListener((RemovalListener<SessionId, SessionSlot>) notification -> {144 // If we were invoked explicitly, then return: we know what we're doing.145 if (!notification.wasEvicted()) {146 return;147 }148 killSession(notification.getValue());149 })150 .build();151 this.tempFileSystems = CacheBuilder.newBuilder()152 .expireAfterAccess(sessionTimeout)153 .ticker(ticker)154 .removalListener((RemovalListener<SessionId, TemporaryFilesystem>) notification -> {155 TemporaryFilesystem tempFS = notification.getValue();156 tempFS.deleteTemporaryFiles();157 tempFS.deleteBaseDir();158 })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 }...

Full Screen

Full Screen

Source:KubernetesNode.java Github

copy

Full Screen

...90 .build();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}")...

Full Screen

Full Screen

Source:LocalDistributor.java Github

copy

Full Screen

...34import org.openqa.selenium.grid.data.NewSessionResponse;35import org.openqa.selenium.grid.data.NewSessionResponseEvent;36import org.openqa.selenium.grid.data.NodeAddedEvent;37import org.openqa.selenium.grid.data.NodeDrainComplete;38import org.openqa.selenium.grid.data.NodeHeartBeatEvent;39import org.openqa.selenium.grid.data.NodeId;40import org.openqa.selenium.grid.data.NodeStatus;41import org.openqa.selenium.grid.data.NodeStatusEvent;42import org.openqa.selenium.grid.data.RequestId;43import org.openqa.selenium.grid.data.Slot;44import org.openqa.selenium.grid.data.SlotId;45import org.openqa.selenium.grid.distributor.Distributor;46import org.openqa.selenium.grid.distributor.config.DistributorOptions;47import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;48import org.openqa.selenium.grid.log.LoggingOptions;49import org.openqa.selenium.grid.node.HealthCheck;50import org.openqa.selenium.grid.node.Node;51import org.openqa.selenium.grid.node.remote.RemoteNode;52import org.openqa.selenium.grid.security.Secret;53import org.openqa.selenium.grid.security.SecretOptions;54import org.openqa.selenium.grid.server.EventBusOptions;55import org.openqa.selenium.grid.server.NetworkOptions;56import org.openqa.selenium.grid.sessionmap.SessionMap;57import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;58import org.openqa.selenium.grid.sessionqueue.NewSessionQueuer;59import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueuerOptions;60import org.openqa.selenium.internal.Either;61import org.openqa.selenium.internal.Require;62import org.openqa.selenium.remote.http.HttpClient;63import org.openqa.selenium.remote.http.HttpRequest;64import org.openqa.selenium.remote.tracing.AttributeKey;65import org.openqa.selenium.remote.tracing.EventAttribute;66import org.openqa.selenium.remote.tracing.EventAttributeValue;67import org.openqa.selenium.remote.tracing.Span;68import org.openqa.selenium.remote.tracing.Tracer;69import org.openqa.selenium.status.HasReadyState;70import java.time.Duration;71import java.util.ArrayList;72import java.util.HashMap;73import java.util.List;74import java.util.Map;75import java.util.Optional;76import java.util.Queue;77import java.util.Set;78import java.util.concurrent.ConcurrentHashMap;79import java.util.concurrent.ConcurrentLinkedQueue;80import java.util.concurrent.Executors;81import java.util.concurrent.ScheduledExecutorService;82import java.util.concurrent.ThreadFactory;83import java.util.concurrent.TimeUnit;84import java.util.concurrent.locks.Lock;85import java.util.concurrent.locks.ReadWriteLock;86import java.util.concurrent.locks.ReentrantReadWriteLock;87import java.util.logging.Level;88import java.util.logging.Logger;89import static com.google.common.collect.ImmutableSet.toImmutableSet;90import static org.openqa.selenium.grid.data.Availability.DOWN;91import static org.openqa.selenium.grid.data.Availability.DRAINING;92import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf;93public class LocalDistributor extends Distributor {94 private static final Logger LOG = Logger.getLogger(LocalDistributor.class.getName());95 private final Tracer tracer;96 private final EventBus bus;97 private final HttpClient.Factory clientFactory;98 private final SessionMap sessions;99 private final Secret registrationSecret;100 private final Regularly hostChecker = new Regularly("distributor host checker");101 private final Map<NodeId, Runnable> allChecks = new HashMap<>();102 private final Queue<RequestId> requestIds = new ConcurrentLinkedQueue<>();103 private final ScheduledExecutorService executorService;104 private final Duration healthcheckInterval;105 private final ReadWriteLock lock = new ReentrantReadWriteLock(/* fair */ true);106 private final GridModel model;107 private final Map<NodeId, Node> nodes;108 private final NewSessionQueuer sessionRequests;109 public LocalDistributor(110 Tracer tracer,111 EventBus bus,112 HttpClient.Factory clientFactory,113 SessionMap sessions,114 NewSessionQueuer sessionRequests,115 Secret registrationSecret,116 Duration healthcheckInterval) {117 super(tracer, clientFactory, new DefaultSlotSelector(), sessions, registrationSecret);118 this.tracer = Require.nonNull("Tracer", tracer);119 this.bus = Require.nonNull("Event bus", bus);120 this.clientFactory = Require.nonNull("HTTP client factory", clientFactory);121 this.sessions = Require.nonNull("Session map", sessions);122 this.model = new GridModel(bus);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 -> {...

Full Screen

Full Screen

Source:NodeHeartBeatEvent.java Github

copy

Full Screen

...19import org.openqa.selenium.events.EventListener;20import org.openqa.selenium.events.EventName;21import org.openqa.selenium.internal.Require;22import java.util.function.Consumer;23public class NodeHeartBeatEvent extends Event {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

NodeHeartBeatEvent

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.data.TestSession;8import org.openqa.selenium.grid.data.TestSlot;9import org.openqa.selenium.grid.data.TestSlotEvent;10import org.openqa.selenium.grid.data.TestSlotEvent.TestSlotStatus;11import org.openqa.selenium.grid.distributor.local.LocalDistributor;12import org.openqa.selenium.grid.distributor.local.LocalDistributorFactory;13import org.openqa.selenium.grid.distributor.local.StickyStrategy;14import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;15import org.openqa.selenium.grid.distributor.remote.RemoteDistributorFactory;16import org.openqa.selenium.grid.graphql.GraphqlHandler;17import org.openqa.selenium.grid.graphql.GraphqlServlet;18import org.openqa.selenium.grid.graphql.NewSessionSubscription;19import org.openqa.selenium.grid.graphql.SessionSubscription;20import org.openqa.selenium.grid.graphql.SessionsSubscription;21import org.openqa.selenium.grid.graphql.SlotSubscription;22import org.openqa.selenium.grid.graphql.SlotsSubscription;23import org.openqa.selenium.grid.graphql.StatusSubscription;24import org.openqa.selenium.grid.node.local.LocalNode;25import org.openqa.selenium.grid.node.local.LocalNodeFactory;26import org.openqa.selenium.grid.node.remote.RemoteNode;27import org.openqa.selenium.grid.node.remote.RemoteNodeFactory;28import org.openqa.selenium.grid.security.Secret;29import org.openqa.selenium.grid.server.EventBusOptions;30import org.openqa.selenium.grid.server.EventBusOptions.EventBusFlags;31import org.openqa.selenium.grid.server.EventBusOptions.EventBusFlags.EventBusFlag;32import org.openqa.selenium.grid.server.Server;33import org.openqa.selenium.grid.server.ServerFlags;34import org.openqa.selenium.grid.server.ServerFlags.ServerFlag;35import org.openqa.selenium.grid.server.StandaloneServer;36import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;37import org.openqa.selenium.grid.sessionmap.local.LocalSessionMapFactory;38import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap;39import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMapFactory;40import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions;41import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions.NewSessionQueueFlags;42import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions.NewSessionQueueFlags.NewSessionQueueFlag;43import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;44import org.openqa.selenium.grid.sessionqueue.local.LocalNewSession

Full Screen

Full Screen

NodeHeartBeatEvent

Using AI Code Generation

copy

Full Screen

1NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);2NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);3NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);4NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);5NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);6NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);7NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);8NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);9NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);10NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);11NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);12NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);13NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);14NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, Instant.now(), status);

Full Screen

Full Screen

NodeHeartBeatEvent

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.NodeHeartbeatEvent;2import org.openqa.selenium.grid.node.NodeStatusEvent;3import org.openqa.selenium.grid.node.NodeStatus;4import org.openqa.selenium.grid.node.NodeId;5import org.openqa.selenium.support.events.EventBus;6import org.openqa.selenium.support.events.EventFiringWebDriver;7import org.openqa.selenium.support.events.WebDriverEventListener;8import org.openqa.selenium.WebDriver;9import org.openqa.selenium.WebElement;10import org.openqa.selenium.By;11import org.openqa.selenium.support.ui.ExpectedConditions;12import org.openqa.selenium.support.ui.WebDriverWait;13import org.openqa.selenium.remote.LocalFileDetector;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.openqa.selenium.remote.RemoteWebDriver;16import java.net.URL;17import java.lang.System;18import java.io.File;19import java.io.IOException;20import java.util.concurrent.TimeUnit;21import java.lang.Thread;22import java.lang.Exception;23import java.util.List;24import java.util.ArrayList;25import java.util.HashMap;26import

Full Screen

Full Screen

NodeHeartBeatEvent

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.grid.data.NodeHeartbeatEvent;2import org.openqa.selenium.grid.node.NodeStatusEvent;3import org.openqa.selenium.grid.node.NodeStatus;4import org.openqa.selenium.grid.node.NodeId;5import org.openqa.selenium.support.events.EventBus;6import org.openqa.selenium.support.events.EventFiringWebDriver;7import org.openqa.selenium.support.events.WebDriverEventListener;8import org.openqa.selenium.WebDriver;9import org.openqa.selenium.WebElement;10import org.openqa.selenium.By;11import org.openqa.selenium.support.ui.ExpectedConditions;12import org.openqa.selenium.support.ui.WebDriverWait;13import org.openqa.selenium.remote.LocalFileDetector;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.openqa.selenium.remote.RemoteWebDriver;16import java.net.URL;17import java.lang.System;18import java.io.File;19import java.io.IOException;20import java.util.concurrent.TimeUnit;21import java.lang.Thread;22import java.lang.Exception;23import java.util.List;24import java.util.ArrayList;25import java.util.HashMap;26import

Full Screen

Full Screen

NodeHeartBeatEvent

Using AI Code Generation

copy

Full Screen

1NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, sessionIds, lastSession);2NodeHeartBeatEventCodec codec = new NodeHeartBeatEventCodec();3EventCodec<NodeHeartBeatEvent> heartBeatEventCodec = EventCodec.create(codec);4Span span = tracer.getCurrentContext().createSpan("node-heartbeat", heartBeatEventCodec.encode(event));5String spanId = span.getId();6String traceId = span.getTraceId();7span.close();8span.close(Status.FAILED);9Tracer tracer = Tracer.getDefault();10Event event = new Event("event-name", new HashMap<String, Object>());11EventCodec<Event> eventEventCodec = EventCodec.create(event);12Span span = tracer.getCurrentContext().createSpan("span-name", eventEventCodec.encode(event));13String spanId = span.getId();14String traceId = span.getTraceId();15span.close();

Full Screen

Full Screen

NodeHeartBeatEvent

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.data.TestSession;8import org.openqa.selenium.grid.data.TestSlot;9import org.openqa.selenium.grid.data.TestSlotEvent;10import org.openqa.selenium.grid.data.TestSlotEvent.TestSlotStatus;11import org.openqa.selenium.grid.distributor.local.LocalDistributor;12import org.openqa.selenium.grid.distributor.local.LocalDistributorFactory;13import org.openqa.selenium.grid.distributor.local.StickyStrategy;14import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;15import org.openqa.selenium.grid.distributor.remote.RemoteDistributorFactory;16import org.openqa.selenium.grid.graphql.GraphqlHandler;17import org.openqa.selenium.grid.graphql.GraphqlServlet;18import org.openqa.selenium.grid.graphql.NewSessionSubscription;19import org.openqa.selenium.grid.graphql.SessionSubscription;20import org.openqa.selenium.grid.graphql.SessionsSubscription;21import org.openqa.selenium.grid.graphql.SlotSubscription;22import org.openqa.selenium.grid.graphql.SlotsSubscription;23import org.openqa.selenium.grid.graphql.StatusSubscription;24import org.openqa.selenium.grid.node.local.LocalNode;25import org.openqa.selenium.grid.node.local.LocalNodeFactory;26import org.openqa.selenium.grid.node.remote.RemoteNode;27import org.openqa.selenium.grid.node.remote.RemoteNodeFactory;28import org.openqa.selenium.grid.security.Secret;29import org.openqa.selenium.grid.server.EventBusOptions;30import org.openqa.selenium.grid.server.EventBusOptions.EventBusFlags;31import org.openqa.selenium.grid.server.EventBusOptions.EventBusFlags.EventBusFlag;32import org.openqa.selenium.grid.server.Server;33import org.openqa.selenium.grid.server.ServerFlags;34import org.openqa.selenium.grid.server.ServerFlags.ServerFlag;35import org.openqa.selenium.grid.server.StandaloneServer;36import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;37import org.openqa.selenium.grid.sessionmap.local.LocalSessionMapFactory;38import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap;39import org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMapFactory;40import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions;41import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions.NewSessionQueueFlags;42import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions.NewSessionQueueFlags.NewSessionQueueFlag;43import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue;44import org.openqa.selenium.grid.sessionqueue.local.LocalNewSession

Full Screen

Full Screen

NodeHeartBeatEvent

Using AI Code Generation

copy

Full Screen

1NodeHeartBeatEvent event = new NodeHeartBeatEvent(nodeId, sessionIds, lastSession);2NodeHeartBeatEventCodec codec = new NodeHeartBeatEventCodec();3EventCodec<NodeHeartBeatEvent> heartBeatEventCodec = EventCodec.create(codec);4Span span = tracer.getCurrentContext().createSpan("node-heartbeat", heartBeatEventCodec.encode(event));5String spanId = span.getId();6String traceId = span.getTraceId();7span.close();8span.close(Status.FAILED);9Tracer tracer = Tracer.getDefault();10Event event = new Event("event-name", new HashMap<String, Object>());11EventCodec<Event> eventEventCodec = EventCodec.create(event);12Span span = tracer.getCurrentContext().createSpan("span-name", eventEventCodec.encode(event));13String spanId = span.getId();14String traceId = span.getTraceId();15span.close();

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 methods in NodeHeartBeatEvent

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful