How to use disableMaxSessions method of com.paypal.selion.proxy.SeLionRemoteProxy class

Best SeLion code snippet using com.paypal.selion.proxy.SeLionRemoteProxy.disableMaxSessions

Source:SeLionRemoteProxy.java Github

copy

Full Screen

...375 stopNodeRecycleThread();376 // verify the servlet is supported on the node377 if (!canForceShutdown) {378 // allow this proxy to keep going379 disableMaxSessions();380 scheduledShutdown = false;381 LOGGER.exiting();382 return;383 }384 // clean up the test slots385 for (TestSlot slot : getTestSlots()) {386 if (slot.getSession() != null) {387 totalSessionsCompleted++;388 proxyLogger.info("Timing out session #" + totalSessionsCompleted + " (" + slot.getSession().toString()389 + ")");390 getRegistry().forceRelease(slot, SessionTerminationReason.TIMEOUT);391 }392 }393 // call the node servlet394 List<NameValuePair> nvps = new ArrayList<>();395 nvps.add(new BasicNameValuePair(NodeForceRestartServlet.TOKEN_PARAMETER,396 NodeForceRestartServlet.CONFIGURED_TOKEN_VALUE));397 HttpResponse response = sendToNodeServlet(NodeForceRestartServlet.class, nvps);398 if (response == null) {399 proxyLogger.warning("Node " + getId() + " failed to shutdown and returned a null response.");400 // stop the polling thread, mark this proxy as down, force this proxy to re-register401 teardown("it failed to shutdown and must re-register");402 LOGGER.exiting();403 return;404 }405 final int responseStatusCode = response.getStatusLine().getStatusCode();406 if (responseStatusCode != HttpStatus.SC_OK) {407 proxyLogger.warning("Node " + getId() + " did not shutdown and returned HTTP " + responseStatusCode);408 // stop the polling thread, mark this proxy as down, force this proxy to re-register409 teardown("it failed to shutdown and must re-register");410 LOGGER.exiting();411 return;412 }413 // stop the polling thread, mark this proxy as down414 teardown("it is shutdown");415 proxyLogger.info("Node " + getId() + " shutdown successfully.");416 LOGGER.exiting();417 }418 private void teardown(String reason) {419 addNewEvent(new RemoteUnregisterException(String.format("Unregistering node %s because %s.",420 getId(), reason)));421 teardown();422 }423 /**424 * Thread will recycle the node when all active sessions are completed425 */426 class NodeRecycleThread extends Thread {427 private static final int DEFAULT_TIMEOUT = 0; // Waits forever428 private volatile boolean running;429 private final String nodeId;430 NodeRecycleThread(String nodeId) {431 super();432 running = false;433 this.nodeId = nodeId;434 }435 @Override436 public void run() {437 LOGGER.entering();438 running = true;439 int timeout = getThreadWaitTimeout();440 int expired = 0;441 proxyLogger.fine("Started NodeRecycleThread with " + ((timeout == 0) ? "no" : "a " + timeout + " second")442 + " timeout for node " + nodeId);443 while (keepLooping(expired, timeout)) {444 try {445 sleep(1000);446 expired += 1;447 } catch (InterruptedException e) {448 if (running) {449 // SEVERE, only if shutdown() was not called450 LOGGER.log(Level.SEVERE, e.getMessage(), e);451 }452 running = false;453 proxyLogger.warning("NodeRecycleThread was interrupted.");454 LOGGER.exiting();455 return;456 }457 }458 if (wasExpired(expired, timeout)) {459 proxyLogger.info("Timeout occurred while waiting for sessions to complete. Shutting down the node.");460 } else {461 proxyLogger.info("All sessions are complete. Shutting down the node.");462 }463 forceNodeShutdown();464 LOGGER.exiting();465 }466 int getThreadWaitTimeout() {467 final String key = "nodeRecycleThreadWaitTimeout";468 return config.custom.containsKey(key) ? Integer.parseInt(config.custom.get(key)) : DEFAULT_TIMEOUT;469 }470 private boolean keepLooping(int expired, int timeout) {471 return (getTotalUsed() > 0) && running && ((expired < timeout) || (timeout == 0));472 }473 private boolean wasExpired(int expired, int timeout) {474 return (expired >= timeout) && (timeout != 0);475 }476 public void shutdown() {477 LOGGER.entering();478 running = false;479 proxyLogger.fine("Shutting down NodeRecycleThread for node " + nodeId);480 interrupt();481 LOGGER.exiting();482 }483 }484 /**485 * @return the {@link NodeRecycleThread} associated with this proxy486 */487 private NodeRecycleThread getNodeRecycleThread() {488 return nodeRecycleThread;489 }490 /**491 * disables the max session count for this node.492 */493 private void disableMaxSessions() {494 proxyLogger.warning("Disabling max unique sessions for Node " + getId());495 config.custom.put("uniqueSessionCount", "-1");496 }497 /**498 * @return an integer value which represents the number of unique sessions this proxy allows for before499 * automatically spinning up a {@link NodeRecycleThread}500 */501 private int getMaxSessionsAllowed() {502 final String key = "uniqueSessionCount";503 return config.custom.containsKey(key) ? Integer.parseInt(config.custom.get(key)) : DEFAULT_MAX_SESSIONS_ALLOWED;504 }505 /**506 * @return total uptime since proxy came online in minutes507 */...

Full Screen

Full Screen

disableMaxSessions

Using AI Code Generation

copy

Full Screen

1package com.paypal.selion.proxy;2import java.util.Map;3import java.util.logging.Logger;4import org.openqa.grid.common.RegistrationRequest;5import org.openqa.grid.internal.Registry;6import org.openqa.grid.internal.TestSession;7import org.openqa.grid.internal.TestSlot;8import org.openqa.grid.internal.listeners.Prioritizer;9import org.openqa.grid.internal.listeners.RegistrationListener;10import org.openqa.grid.internal.listeners.SelfHealingProxy;11import org.openqa.grid.selenium.proxy.DefaultRemoteProxy;12public class SeLionRemoteProxy extends DefaultRemoteProxy implements SelfHealingProxy, Prioritizer, RegistrationListener {13 private static final Logger log = Logger.getLogger(SeLionRemoteProxy.class.getName());14 private static final int MAX_SESSIONS = 1;15 public SeLionRemoteProxy(RegistrationRequest request, Registry registry) {16 super(request, registry);17 }18 public TestSession getNewSession(Map<String, Object> requestedCapability) {19 TestSession session = super.getNewSession(requestedCapability);20 if (session == null) {21 return null;22 }23 disableMaxSessions();24 return session;25 }26 private void disableMaxSessions() {27 for (TestSlot testSlot : getTestSlots()) {28 testSlot.setMaxConcurrent(MAX_SESSIONS);29 }30 }31 public void beforeRegistration() {32 disableMaxSessions();33 }34 public int getPriority() {35 return 1;36 }37 public boolean beforeSession(TestSession session) {38 return true;39 }40 public void afterSession(TestSession session) {41 }42}

Full Screen

Full Screen

disableMaxSessions

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.proxy.SeLionRemoteProxy;2import java.util.concurrent.TimeUnit;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.firefox.FirefoxDriver;5import org.openqa.selenium.remote.DesiredCapabilities;6import org.openqa.selenium.remote.RemoteWebDriver;7import org.testng.annotations.Test;8public class TestClass {9 public void testMethod() throws Exception {10 DesiredCapabilities capabilities = DesiredCapabilities.firefox();11 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);12 driver.quit();13 }14}

Full Screen

Full Screen

disableMaxSessions

Using AI Code Generation

copy

Full Screen

1package com.paypal.selion.proxy;2import org.openqa.grid.common.RegistrationRequest;3import org.openqa.grid.internal.Registry;4import org.openqa.grid.internal.RemoteProxy;5import org.openqa.grid.internal.TestSlot;6import org.openqa.grid.selenium.proxy.DefaultRemoteProxy;7import java.util.List;8public class SeLionRemoteProxy extends DefaultRemoteProxy {9 public SeLionRemoteProxy(RegistrationRequest request, Registry registry) {10 super(request, registry);11 }12 public void disableMaxSessions() {13 List<TestSlot> testSlots = getTestSlots();14 for (TestSlot testSlot : testSlots) {15 testSlot.setMaxConcurrent(0);16 }17 }18 public void removeNode() {19 getRegistry().removeIfPresent(this);20 }21}

Full Screen

Full Screen

disableMaxSessions

Using AI Code Generation

copy

Full Screen

1package com.paypal.selion.testcomponents;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.support.ui.ExpectedConditions;4import org.openqa.selenium.support.ui.WebDriverWait;5import org.testng.annotations.Test;6import com.paypal.selion.annotations.WebTest;7import com.paypal.selion.platform.grid.Grid;8import com.paypal.selion.platform.grid.SeLionGrid;9import com.paypal.selion.platform.grid.browsercapabilities.DefaultCapabilitiesBuilder;10import com.paypal.selion.platform.grid.browsercapabilities.SeLionCapabilityHelper;11import com.paypal.selion.platform.grid.browsercapabilities.WebDriverFactory;12import com.paypal.selion.platform.utilities.WebDriverWaitUtils;13import com.paypal.selion.testcomponents.BasicPageImpl;14import com.paypal.selion.testcomponents.FlipkartHomePage;15import com.paypal.selion.testcomponents.FlipkartLoginPage;16import com.paypal.selion.testcomponents.FlipkartProductPage;17import com.paypal.selion.testcomponents.FlipkartSearchResultsPage;18public class FlipkartTest {19 public void testFlipkartLogin() {20 WebDriver driver = Grid.driver("chrome");21 WebDriverWaitUtils.waitUntilElementIsVisible(new FlipkartHomePage().getLoginLink());22 new FlipkartHomePage().getLoginLink().click();23 WebDriverWaitUtils.waitUntilElementIsVisible(new FlipkartLoginPage().getLoginButton());24 new FlipkartLoginPage().getLoginButton().click();25 WebDriverWaitUtils.waitUntilElementIsVisible(new FlipkartLoginPage().getLoginError());26 driver.quit();27 }28 public void testFlipkartSearch() {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful