/** * @see GridRegistry#getExistingSession(ExternalSessionKey) */ public TestSession getExistingSession(ExternalSessionKey externalKey) { return activeTestSessions.getExistingSession(externalKey); }
/** * @see GridRegistry#setThrowOnCapabilityNotPresent(boolean) */ public void setThrowOnCapabilityNotPresent(boolean throwOnCapabilityNotPresent) { proxies.setThrowOnCapabilityNotPresent(throwOnCapabilityNotPresent); }
/** * @see GridRegistry#getUsedProxies() */ public List<RemoteProxy> getUsedProxies() { return proxies.getBusyProxies(); }
@VisibleForTesting protected void terminateIdleTest() { for (TestSlot testSlot : getTestSlots()) { if (testSlot.getSession() != null) { long executionTime = (System.currentTimeMillis() - testSlot.getLastSessionStart()) / 1000; ga.testEvent(DockerSeleniumRemoteProxy.class.getName(), testSlot.getSession().getRequestedCapabilities().toString(), executionTime); getRegistry().forceRelease(testSlot, SessionTerminationReason.ORPHAN); } } }
private boolean takeRequestHandler(RequestHandler handler) { final TestSession session = proxies.getNewSession(handler.getRequest().getDesiredCapabilities()); final boolean sessionCreated = session != null; if (sessionCreated) { String remoteName = session.getSlot().getProxy().getId(); long timeToAssignProxy = System.currentTimeMillis() - handler.getRequest().getCreationTime(); LOG.info("Test session with internal key {} assigned to remote ({}) after {} seconds ({} ms).", session.getInternalKey(), remoteName, timeToAssignProxy / 1000, timeToAssignProxy); seleniumTestSessionStartLatency.observe(timeToAssignProxy / Collector.MILLISECONDS_PER_SECOND); seleniumTestSessionsWaiting.dec(); activeTestSessions.add(session); handler.bindSession(session); } return sessionCreated; }
/** * @see GridRegistry#forceRelease(TestSlot, SessionTerminationReason) */ public void forceRelease(TestSlot testSlot, SessionTerminationReason reason) { if (testSlot.getSession() == null) { return; } String internalKey = testSlot.getInternalKey(); release(internalKey, reason); testSlot.doFinishRelease(); }
public void add(RemoteProxy proxy) { boolean shouldAdd = true; if (proxy instanceof DockerSeleniumRemoteProxy) { DockerSeleniumRemoteProxy dockerSeleniumRemoteProxy = (DockerSeleniumRemoteProxy) proxy; shouldAdd = this.register(dockerSeleniumRemoteProxy); } if (shouldAdd) { super.add(proxy); } else { // Won't be tracking the proxy, so it won't be removed and shutdown later - tear down. proxy.teardown(); } }
/** * @see GridRegistry#getSession(ExternalSessionKey) */ public TestSession getSession(ExternalSessionKey externalKey) { return activeTestSessions.findSessionByExternalKey(externalKey); }
/** * @see GridRegistry#getActiveSessions() */ public Set<TestSession> getActiveSessions() { return activeTestSessions.unmodifiableSet(); }
/** * @see GridRegistry#getNewSessionRequestCount() */ public int getNewSessionRequestCount() { // may race return newSessionQueue.getNewSessionRequestCount(); }
/** * @see GridRegistry#getDesiredCapabilities() */ public Iterable<DesiredCapabilities> getDesiredCapabilities() { return newSessionQueue.getDesiredCapabilities(); }
@Override public void teardown() { poller.interrupt(); super.teardown(); }
/** * @see GridRegistry#getProxyById(String) */ public RemoteProxy getProxyById(String id) { LOG.debug("Getting proxy {}", id); return proxies.getProxyById(id); }
/** * @see GridRegistry#clearNewSessionRequests() */ public void clearNewSessionRequests() { newSessionQueue.clearNewSessionRequests(); seleniumTestSessionsWaiting.set(0); }
/** * @see GridRegistry#removeNewSessionRequest(RequestHandler) */ public boolean removeNewSessionRequest(RequestHandler request) { boolean wasRemoved = newSessionQueue.removeNewSessionRequest(request); if (wasRemoved) { seleniumTestSessionsWaiting.dec(); } return wasRemoved; }
private String getUnprocessedRequests() { int numUnprocessedRequests = getRegistry().getNewSessionRequestCount(); String unprocessedRequests = ""; if (numUnprocessedRequests > 0) { unprocessedRequests = String.format("%d requests waiting for a slot to be free.", numUnprocessedRequests); } return unprocessedRequests; }
private void release(String internalKey, SessionTerminationReason reason) { if (internalKey == null) { return; } final TestSession session = activeTestSessions.findSessionByInternalKey(internalKey); if (session != null) { release(session, reason); return; } LOG.warn("Tried to release session with internal key {} but couldn't find it.", internalKey); }
@Override public void verifyAbilityToHandleDesiredCapabilities(Map<String, Object> desiredCapabilities) { // Using the matcher to see if docker-selenium can handle the desired capabilities. If matches is because the // capability should be fulfilled by a cloud provider or a external node. ZaleniumCapabilityMatcher matcher = new ZaleniumCapabilityMatcher(); if (matcher.matches(null, desiredCapabilities)) { super.verifyAbilityToHandleDesiredCapabilities(desiredCapabilities); } }