@Override public void afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) { String currentName = Thread.currentThread().getName(); Thread.currentThread().setName(getProxyName()); if (request instanceof WebDriverRequest && "DELETE".equalsIgnoreCase(request.getMethod())) { WebDriverRequest seleniumRequest = (WebDriverRequest) request; if (seleniumRequest.getRequestType().equals(RequestType.STOP_SESSION)) { long executionTime = (System.currentTimeMillis() - session.getSlot().getLastSessionStart()) / 1000; getGa().testEvent(getProxyClassName(), session.getRequestedCapabilities().toString(), executionTime); addTestToDashboard(session.getExternalKey().getKey(), true); } } super.afterCommand(session, request, response); Thread.currentThread().setName(currentName); }
@Override public void afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) { String currentName = configureThreadName(); super.afterCommand(session, request, response); LOGGER.debug("lastCommand: {} - executing...", request.getMethod(), request.getPathInfo()); if (request instanceof WebDriverRequest && "POST".equalsIgnoreCase(request.getMethod())) { WebDriverRequest seleniumRequest = (WebDriverRequest) request; if (RequestType.START_SESSION.equals(seleniumRequest.getRequestType())) { ExternalSessionKey externalKey = Optional.ofNullable(session.getExternalKey()) .orElse(new ExternalSessionKey("[No external key present]")); LOGGER.debug(String.format("Test session started with internal key %s and external key %s assigned to remote %s.", session.getInternalKey(), externalKey, getId())); LOGGER.debug("Test session started with internal key {} and external key {} assigned to remote.", session.getInternalKey(), externalKey); videoRecording(DockerSeleniumContainerAction.START_RECORDING); } } this.lastCommandTime = System.currentTimeMillis(); setThreadName(currentName); }
private static void checkVideoIsDone(ExternalSessionKey key) throws Exception { VideoFuture videoFuture = stoppingSessions.getIfPresent(key.toString()); if(videoFuture != null) { videoFuture.get(downloadWaitTimeout, TimeUnit.MILLISECONDS); } }
public static StoredVideoDownloadContext getVideoForSession(ExternalSessionKey key) throws Exception { checkVideoIsDone(key); return videoStore.retrieveVideo(key.toString()); }
@VisibleForTesting public void terminateIdleSessions() { String currentName = Thread.currentThread().getName(); Thread.currentThread().setName(getProxyName()); for (TestSlot testSlot : getTestSlots()) { if (testSlot.getSession() != null && (testSlot.getSession().getInactivityTime() >= (getMaxTestIdleTime() * 1000L))) { long executionTime = (System.currentTimeMillis() - testSlot.getLastSessionStart()) / 1000; getGa().testEvent(getProxyClassName(), testSlot.getSession().getRequestedCapabilities().toString(), executionTime); // If it is null, it is probable that the test never reached the cloud service. if (testSlot.getSession().getExternalKey() != null) { addTestToDashboard(testSlot.getSession().getExternalKey().getKey(), false); } getRegistry().forceRelease(testSlot, SessionTerminationReason.ORPHAN); logger.warn("Releasing slot and terminating session due to inactivity."); } } Thread.currentThread().setName(currentName); }
/** * Ends this test session for the hub, releasing the resources in the hub / registry. It does not * release anything on the remote. The resources are released in a separate thread, so the call * returns immediately. It allows release with long duration not to block the test while the hub is * releasing the resource. * * @param session The session to terminate * @param reason the reason for termination */ public void terminate(final TestSession session, final SessionTerminationReason reason) { // Thread safety reviewed String remoteName = ""; if (session.getSlot().getProxy() instanceof DockerSeleniumRemoteProxy) { remoteName = ((DockerSeleniumRemoteProxy)session.getSlot().getProxy()).getRegistration().getContainerId(); } String internalKey = Optional.ofNullable(session.getInternalKey()).orElse("No internal key"); ExternalSessionKey externalKey = Optional.ofNullable(session.getExternalKey()).orElse(new ExternalSessionKey("No external key was assigned")); new Thread(() -> _release(session.getSlot(), reason), "Terminate Test Session int id: [" + internalKey + "] ext id: [" + externalKey + "] container: [" + remoteName + "]").start(); }
public static StoredVideoInfoContext getVideoInfoForSession(ExternalSessionKey key) throws Exception { checkVideoIsDone(key); return videoStore.getVideoInformation(key.toString()); }
testName = getCapability(requestedCapability, ZaleniumCapabilityType.TEST_NAME, ""); String seleniumSessionId = newSession.getExternalKey() != null ? newSession.getExternalKey().getKey() : newSession.getInternalKey(); if (testName.isEmpty()) {
@Override public LocalTempFileDownloadContext retrieveVideo(String sessionId) throws Exception { File file = availableVideos.getIfPresent(new ExternalSessionKey(sessionId)); if(file != null && file.exists() && file.isFile()) { return new LocalTempFileDownloadContext(file); } return new LocalTempFileDownloadContext(null); }
public static void declareSessionStopping(TestSession session) { stoppingSessions.put(session.getExternalKey().getKey(), new VideoFuture()); }
@Override public void storeVideo(InputStream videoStream, long contentLength, String mimeType, String sessionId, SessionInfoBean infoBean) throws Exception { File outputFile = File.createTempFile("screencast", ".webm"); FileOutputStream outputStream = new FileOutputStream(outputFile); try { new StreamPumper(videoStream, outputStream).run(); } finally { outputStream.close(); } availableVideos.put(new ExternalSessionKey(sessionId), outputFile); log.info("Successfully retrieved video for session: " + sessionId + " and temporarily stashed it at: " + outputFile); }
public void refreshTimeout(String sessionId) { for (TestSession activeSession : registry.getActiveSessions()) { if ((activeSession != null) && (sessionId != null) && (activeSession.getExternalKey() != null)) { if (sessionId.equals(activeSession.getExternalKey().getKey())) { refreshTimeout(activeSession); } } } }
videoInfoForSession = HubVideoRegistry.getVideoInfoForSession(new ExternalSessionKey(sessionId)); } catch (Exception e) { log.log(Level.WARNING, "Caught exception when fetching video information for " + sessionId, e);
public URL getRemoteHostForSession(String sessionId) { for (TestSession activeSession : registry.getActiveSessions()) { if (sessionId.equals(activeSession.getExternalKey().getKey())) { return activeSession.getSlot().getProxy().getRemoteHost(); } } throw new IllegalArgumentException("Invalid sessionId. No active session is present for id:" + sessionId); }
videoInfoForSession = HubVideoRegistry.getVideoInfoForSession(new ExternalSessionKey(sessionId)); } catch (Exception e) { log.log(Level.WARNING, "Caught exception when fetching video information for " + sessionId, e);
videoContext = HubVideoRegistry.getVideoForSession(new ExternalSessionKey(sessionId)); } catch (Exception e) { log.log(Level.WARNING, "Caught exception when fetching video for " + sessionId, e);