Best SeLion code snippet using com.paypal.selion.internal.platform.grid.AbstractBaseLocalServerComponent.waitForInitialization
Source:AbstractBaseLocalServerComponent.java
...51 setExecutor(Executors.newSingleThreadExecutor());52 Runnable worker = getLauncher();53 try {54 getExecutor().execute(worker);55 waitForInitialization(Long.parseLong(Config.getConfigProperty(ConfigProperty.DOWNLOAD_TIMEOUT)));56 waitForComponentToComeUp();57 LOGGER.info(String.format("%s spawned", this.getClass().getSimpleName()));58 } catch (IllegalStateException e) {59 throw new GridException(String.format("Failed to start a %s", this.getClass().getSimpleName()), e);60 }61 LOGGER.exiting();62 }63 public synchronized void shutdown() {64 LOGGER.entering();65 if (!getLauncher().isRunning()) {66 LOGGER.exiting();67 return;68 }69 try {70 getLauncher().shutdown();71 getExecutor().shutdownNow();72 while (!getExecutor().isTerminated() || getLauncher().isRunning()) {73 getExecutor().awaitTermination(30, TimeUnit.SECONDS);74 }75 LOGGER.info(String.format("%s has been stopped", this.getClass().getSimpleName()));76 } catch (InterruptedException e) {77 String errorMsg = "An error occurred while attempting to shut down the %s.";78 LOGGER.log(Level.SEVERE, String.format(errorMsg, this.getClass().getSimpleName()));79 }80 LOGGER.exiting();81 }82 /**83 * Check the port availability84 * 85 * @param port86 * the port to check87 * @param msg88 * the text to append to the end of the error message displayed when the port is not available.89 * @throws IllegalArgumentException90 * when the port is not available.91 */92 void checkPort(int port, String msg) {93 StringBuilder message = new StringBuilder().append(" ").append(msg);94 String portInUseError = String.format("Port %d is already in use. Please shutdown the service "95 + "listening on this port or configure a different port%s.", port, message);96 boolean free = false;97 try {98 free = PortProber.pollPort(port);99 } catch (RuntimeException e) {100 throw new IllegalArgumentException(portInUseError, e);101 } finally {102 if (!free) {103 throw new IllegalArgumentException(portInUseError);104 }105 }106 }107 /*108 * Waits for the launcher to initialize. This code exists purely to give the launcher more time to download109 * dependencies. Otherwise, it is not needed since RunnableLauncher#isRunning() _should_ check for isInitialized()110 * at method entry.111 */112 private void waitForInitialization(long timeout) {113 LOGGER.entering();114 long time = 0;115 while (!getLauncher().isInitialized() && (time < timeout)) {116 try {117 // SeLion Grid could still be downloading dependencies.. Wait for it.118 Thread.sleep(1000);119 time += 1000;120 } catch (InterruptedException e) {121 throw new IllegalStateException(e.getMessage(), e);122 }123 }124 if (time == timeout) {125 throw new IllegalStateException(String.format("Timed out waiting for %s to initialize.",126 getLocalServerComponent().getClass().getSimpleName()));...
waitForInitialization
Using AI Code Generation
1[INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ selion-standalone-server ---2[INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ selion-standalone-server ---3[INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ selion-standalone-server ---4[INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ selion-standalone-server ---5[INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ selion-standalone-server ---6[INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ selion-standalone-server ---
waitForInitialization
Using AI Code Generation
1 public void waitForInitialization( long timeoutInSeconds) throws InterruptedException, TimeoutException {2 waitForInitialization(timeoutInSeconds, TimeUnit .SECONDS);3 }4 public void waitForInitialization( long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {5 waitForInitialization( new Date( new Date().getTime() + unit.toMillis(timeout)));6 }7 public void waitForInitialization(Date timeout) throws InterruptedException, TimeoutException {8 waitForServerState(timeout, true );9 }10 public void waitForTermination( long timeoutInSeconds) throws InterruptedException, TimeoutException {11 waitForTermination(timeoutInSeconds, TimeUnit .SECONDS);12 }13 public void waitForTermination( long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {14 waitForTermination( new Date( new Date().getTime() + unit.toMillis(timeout)));15 }
waitForInitialization
Using AI Code Generation
1public class LocalServerComponent extends AbstractBaseLocalServerComponent {2 public LocalServerComponent() {3 super("localServerComponent");4 }5 public void startServer() {6 }7 public void stopServer() {8 }9 public boolean isServerRunning() {10 }11 public static void main(String[] args) {12 LocalServerComponent component = new LocalServerComponent();13 component.start();14 component.waitForInitialization();15 component.stop();16 }17}
waitForInitialization
Using AI Code Generation
1public class AppUnderTest extends AbstractBaseLocalServerComponent {2 private static AppUnderTest appUnderTest = new AppUnderTest();3 private static final String APP_TITLE = "Google";4 private static final String APP_LOAD_TIMEOUT = "30";5 private AppUnderTest() {6 super(APP_URL, APP_TITLE, APP_LOAD_TIMEOUT);7 }8 public static AppUnderTest getInstance() {9 return appUnderTest;10 }11 public void launch() {12 getWebDriver().get(getAppUrl());13 }14 public void close() {15 getWebDriver().close();16 }17}18public class AppUnderTestTest {19 public void launchApp() {20 AppUnderTest.getInstance().launch();21 AppUnderTest.getInstance().waitForInitialization();22 }23 public void testApp() {24 Assert.assertTrue(AppUnderTest.getInstance().isInitialized());25 }26 public void closeApp() {27 AppUnderTest.getInstance().close();28 }29}30public class AppUnderTestTest {31 public void launchApp() {32 AppUnderTest.getInstance().launch();33 AppUnderTest.getInstance().waitForInitialization(60);34 }35 public void testApp() {36 Assert.assertTrue(AppUnderTest.getInstance().isInitialized());37 }38 public void closeApp() {39 AppUnderTest.getInstance().close();40 }41}42public class AppUnderTestTest {43 public void launchApp() {44 AppUnderTest.getInstance().launch();45 AppUnderTest.getInstance().waitForInitialization(60, TimeUnit.SECONDS);46 }47 public void testApp() {48 Assert.assertTrue(AppUnderTest.getInstance().isInitialized());49 }50 public void closeApp() {51 AppUnderTest.getInstance().close();52 }53}54public class AppUnderTestTest {55 public void launchApp() {56 AppUnderTest.getInstance().launch();57 AppUnderTest.getInstance().waitForInitialization(60, TimeUnit.SECONDS, 5, TimeUnit.SECONDS);58 }
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!