@Override public TestSession getNewSession(Map<String, Object> requestedCapability) { String currentName = Thread.currentThread().getName(); Thread.currentThread().setName(getProxyName()); /* Validate first if the capability is matched */ if (!hasCapability(requestedCapability)) { return null; } logger.info("Test will be forwarded to {} - {}", getProxyName(), requestedCapability); Thread.currentThread().setName(currentName); return super.getNewSession(requestedCapability); }
@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); }
super.beforeCommand(session, request, response); Thread.currentThread().setName(currentName);
@Override public void beforeSession(TestSession session) { super.beforeSession(session); synchronized (this) { totalTests++; } }
@Override public void afterSession(TestSession session) { String currentName = configureThreadName(); try { // This means that the shutdown command was triggered before receiving this afterSession command if (!TestInformation.TestStatus.TIMEOUT.equals(testInformation.getTestStatus())) { long executionTime = (System.currentTimeMillis() - session.getSlot().getLastSessionStart()) / 1000; ga.testEvent(DockerSeleniumRemoteProxy.class.getName(), session.getRequestedCapabilities().toString(), executionTime); if (isTestSessionLimitReached()) { LOGGER.info("Session {} completed. Node should shutdown soon...", session.getInternalKey()); cleanupNode(true); } else { LOGGER.info("Session {} completed. Cleaning up node for reuse, used {} of max {} sessions", session.getInternalKey(), getAmountOfExecutedTests(), maxTestSessions); cleanupNode(false); } } } catch (Exception e) { LOGGER.warn(e.toString(), e); } finally { super.afterSession(session); } setThreadName(currentName); }
@Override public long getLastSessionStart() { return super.getLastSessionStart(); }
@Override public void onEvent(List<RemoteException> events, RemoteException lastInserted) { List<RemoteException> remoteNotReachableEvents = events.stream() .filter(event -> event instanceof RemoteNotReachableException) .collect(Collectors.toList()); super.onEvent(remoteNotReachableEvents, lastInserted); if (lastInserted instanceof RemoteUnregisterException) { LOGGER.debug(lastInserted.getMessage()); GridRegistry registry = this.getRegistry(); registry.removeIfPresent(this); } }
@Override public void startPolling() { super.startPolling(); cloudProxyNodePoller = new CloudProxyNodePoller(this); cloudProxyNodePoller.start(); }
if (((DefaultRemoteProxy) proxy).isDown()) { localBuilder.append("(cannot be reached at the moment)");
@Override public void beforeSession(TestSession session) { super.beforeSession(session); synchronized (this) { totalTests++; } }
@Override public void afterSession(TestSession session) { super.afterSession(session); if(isCurrentlyRecording) { log.warning("Session session terminated ungracefully for " + session.getExternalKey() + " on node " + getId() + " - stopping recording"); stopRecording(session); } }
private TestSession createNewSession(Map<String, Object> requestedCapability) { String currentName = configureThreadName(); TestSession newSession = super.getNewSession(requestedCapability); if (newSession == null) {
@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 beforeCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) { String currentName = configureThreadName(); super.beforeCommand(session, request, response); LOGGER.debug("lastCommand: {} - executing...", request.getMethod(), request.getPathInfo()); if (request instanceof WebDriverRequest && "POST".equalsIgnoreCase(request.getMethod())) {
@Override public void beforeSession(TestSession arg0) { super.beforeSession(arg0); HttpPost r = new HttpPost(serviceUrl + "?command=start"); try { HttpResponse response = client.execute(r); if(response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { log.warning("Could not start video reporting: " + EntityUtils.toString(response.getEntity())); return; } isCurrentlyRecording = true; log.info("Started recording for new session on node: " + getId()); } catch (Exception e) { log.warning("Could not start video reporting due to exception: " + e.getMessage()); e.printStackTrace(); return; } finally { r.releaseConnection(); } }
@Override public TestSession getNewSession(Map<String, Object> requestedCapability) { synchronized (this) { if (isRestarting() || !isAvailable()) { return null; } return super.getNewSession(requestedCapability); } }
@Override public void afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) { super.afterCommand(session, request, response); // its a shame we have to extract this again SeleniumBasedRequest seleniumRequest = SeleniumBasedRequest.createFromRequest(request, getRegistry()); if(RequestType.STOP_SESSION.equals(seleniumRequest.getRequestType())) { if(isCurrentlyRecording) { log.info("Selenium session closed for " + session.getExternalKey() + " on node " + getId() + " - stopping recording."); stopRecording(session); } else { log.severe("Recording not started for " + session.getExternalKey() + " on node " + getId() + " and session being deleted - this could be a bug in the code."); } } }
@Override public void beforeCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) { super.beforeCommand(session, request, response); SeleniumBasedRequest seleniumRequest = SeleniumBasedRequest.createFromRequest(request, getRegistry()); // https://github.com/aimmac23/selenium-video-node/issues/10 - we need to mark the session as stopping, before we // pass back the client any information to prevent race conditions when downloading the video if(RequestType.STOP_SESSION.equals(seleniumRequest.getRequestType())) { if(isCurrentlyRecording) { HubVideoRegistry.declareSessionStopping(session); } else { log.severe("Recording not started for " + session.getExternalKey() + " on node " + getId() + " - cannot register session as stopping."); } } }
TestSession session = super.getNewSession(requestedCapability); if (session != null) {
TestSession session = super.getNewSession(requestedCapability); if (session != null) {