How to use waitForTerminationAfterDestroy method of com.paypal.selion.grid.AbstractBaseProcessLauncher class

Best SeLion code snippet using com.paypal.selion.grid.AbstractBaseProcessLauncher.waitForTerminationAfterDestroy

Source:AbstractBaseProcessLauncher.java Github

copy

Full Screen

...102 throw new WebDriverException(e);103 }104 }105 }106 private void waitForTerminationAfterDestroy(int duration, TimeUnit unit) {107 long end = System.currentTimeMillis() + unit.toMillis(duration);108 while (isRunning() && System.currentTimeMillis() < end) {109 try {110 Thread.sleep(50);111 } catch (InterruptedException e) {112 throw new WebDriverException(e);113 }114 }115 }116 public void destroyProcessForcefully() {117 try {118 Process awaitFor = this.process.destroyForcibly();119 awaitFor.waitFor(10, SECONDS);120 } catch (InterruptedException e) {121 Thread.interrupted();122 throw new RuntimeException(e);123 }124 }125 }126 Thread shutDownHook = new Thread() {127 @Override128 public void run() {129 shutdown();130 }131 };132 /**133 * @return the command line to invoke as a {@link CommandLine}134 */135 CommandLine getCommandLine() {136 return cmdLine;137 }138 /**139 * Set the command line to invoke140 *141 * @param commandLine142 * a {@link CommandLine} to invoke143 */144 void setCommandLine(CommandLine commandLine) {145 this.cmdLine = commandLine;146 }147 /**148 * Init with the supplied {@code args} and a default {@link ProcessLauncherConfiguration}. All {@code args} take149 * precedence over any other values.150 *151 * @param args152 * The program arguments to use. Can be a mix of SeLion and selenium arguments.153 */154 void init(String[] args) {155 init(args, null);156 }157 /**158 * Init with the supplied dash {@code args} and the supplied {@link ProcessLauncherOptions}. All {@code args} take159 * precedence over the {@code options} and/or other values.160 *161 * @param args162 * The program arguments to use. Can be a mix of SeLion and selenium arguments.163 * @param options164 * {@link ProcessLauncherOptions} to consider165 */166 void init(String[] args, ProcessLauncherOptions options) {167 ProcessLauncherConfiguration plc = new ProcessLauncherConfiguration();168 plc.merge(options);169 JCommander commander = new JCommander();170 commander.setAcceptUnknownOptions(true);171 commander.addObject(plc);172 try {173 commander.parse(args);174 // we need to consider the selionConfig file when the caller is providing175 // a non-default selionConfig file location176 if (plc.getSeLionConfig() != SELION_CONFIG_FILE) {177 // reload the config from the file178 plc = ProcessLauncherConfiguration.loadFromFile(plc.getSeLionConfig());179 // re-merge the options180 plc.merge(options);181 // re-parse the args182 commander = new JCommander();183 commander.setAcceptUnknownOptions(true);184 commander.addObject(plc);185 commander.parse(args);186 }187 } catch (ParameterException | IOException e) {188 LOGGER.log(Level.SEVERE, e.getMessage(), e);189 System.exit(1);190 }191 setLauncherOptions(plc);192 // save off all the command line that were provided.193 List<String> commands = new LinkedList<>(Arrays.asList(args));194 setCommands(commands);195 // setup the SeLion config196 ConfigParser.setConfigFile(plc.getSeLionConfig());197 InstallHelper.firstTimeSetup();198 }199 /**200 * This method spawns a jar, and waits for it to exit [either cleanly or forcibly]201 *202 * @param interval203 * How often should the application check if the command is still running or if it exit.204 * @throws IOException205 * @throws InterruptedException206 */207 final void continuouslyRestart(long interval) throws IOException, InterruptedException {208 LOGGER.entering(interval);209 while (true) {210 if (!isInitialized()) {211 FileDownloader.checkForDownloads(getType(), getLauncherOptions()212 .isFileDownloadCheckTimeStampOnInvocation(), getLauncherOptions()213 .isFileDownloadCleanupOnInvocation());214 }215 startProcess(false);216 while (!handler.hasResult()) {217 LOGGER.fine("Child process still running. Going back to sleep.");218 Thread.sleep(interval);219 }220 if (handler.hasResult()) {221 ExecuteException e = handler.getException();222 if (e != null) {223 LOGGER.log(Level.SEVERE, handler.getException().getMessage(), handler.getException());224 }225 }226 LOGGER.info("Child process quit. Restarting it.");227 setInitialized(false);228 }229 }230 /**231 * Start a process based on the commands provided.232 *233 * @param squelch234 * Whether to show command executed as a logger.info message235 * @throws IOException236 */237 void startProcess(boolean squelch) throws IOException {238 LOGGER.entering(squelch);239 if (!squelch) {240 LOGGER.fine("Executing command " + cmdLine.toString());241 }242 watchdog.reset();243 DefaultExecutor executor = new DefaultExecutor();244 executor.setWatchdog(watchdog);245 executor.setStreamHandler(new PumpStreamHandler());246 executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());247 handler = new DefaultExecuteResultHandler();248 executor.execute(cmdLine, handler);249 LOGGER.exiting();250 }251 public void run() {252 try {253 if (!isInitialized()) {254 addJVMShutDownHook();255 FileDownloader.checkForDownloads(getType(), getLauncherOptions()256 .isFileDownloadCheckTimeStampOnInvocation(), getLauncherOptions()257 .isFileDownloadCleanupOnInvocation());258 setInitialized(true);259 }260 if (getCommands().contains("-help") || getCommands().contains("--help") || getCommands().contains("-h")) {261 startProcess(true);262 handler.waitFor();263 if (handler.getExitValue() == 0) {264 printUsageInfo();265 }266 return;267 }268 if (getCommands().contains("-version")) {269 getLauncherOptions().setContinuouslyRestart(false);270 }271 if (getLauncherOptions().isContinuouslyRestart()) {272 long interval = getLauncherOptions().getRestartCycle();273 LOGGER.fine("Restart cycle will check every " + interval + " ms");274 continuouslyRestart(interval);275 }276 // non-continuous process.277 startProcess(false);278 handler.waitFor();279 } catch (InterruptedException | IOException e) {280 // log the exception and exit, if shutdown was not called281 if (!shutdownCalled) {282 LOGGER.log(Level.SEVERE, e.getMessage(), e);283 System.exit(1);284 }285 }286 }287 abstract void printUsageInfo();288 /**289 * Shuts down the instance represented by this launcher. Uses the {@link ProcessHandlerFactory} to find sub290 * processes.291 */292 public void shutdown() {293 shutdownCalled = true;294 if (isRunning()) {295 watchdog.waitForProcessStarted();296 watchdog.destroyProcess();297 watchdog.waitForTerminationAfterDestroy(2, SECONDS);298 if (isRunning()) {299 watchdog.destroyProcessForcefully();300 watchdog.waitForTerminationAfterDestroy(1, SECONDS);301 if (isRunning()) {302 LOGGER.severe(String.format("Unable to kill process with PID %s", watchdog.getProcessId()));303 }304 }305 }306 // if shutdown() was called by something other than the shutdown hook, we don't need the shutdown hook anymore307 try {308 if (shutDownHook != null) {309 Runtime.getRuntime().removeShutdownHook(shutDownHook);310 }311 } catch (IllegalStateException e) {312 // ignore.. happens when the shutdown hook is in use, that's okay313 }314 }...

Full Screen

Full Screen

waitForTerminationAfterDestroy

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.grid.AbstractBaseProcessLauncher;2import com.paypal.selion.grid.ProcessLauncherOptions;3public class CustomProcessLauncher extends AbstractBaseProcessLauncher {4 public CustomProcessLauncher(ProcessLauncherOptions options) {5 super(options);6 }7 public void launch() {8 }9 public void destroy() {10 }11 public void waitForTerminationAfterDestroy() {12 }13}

Full Screen

Full Screen

waitForTerminationAfterDestroy

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.grid.AbstractBaseProcessLauncher;2import com.paypal.selion.grid.ProcessLauncherOptions;3import com.paypal.selion.grid.ProcessLauncherOptions.ProcessLauncherOptionsBuilder;4public class WaitForTerminationAfterDestroy {5 public static void main(String[] args) {6 ProcessLauncherOptions options = new ProcessLauncherOptionsBuilder().build();7 AbstractBaseProcessLauncher launcher = new AbstractBaseProcessLauncher(options) {8 public void launch() {9 System.out.println("Launching process");10 }11 public void destroy() {12 System.out.println("Destroying process");13 }14 };15 launcher.launch();16 launcher.waitForTerminationAfterDestroy();17 }18}

Full Screen

Full Screen

waitForTerminationAfterDestroy

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.grid.AbstractBaseProcessLauncher;2import com.paypal.selion.grid.ProcessLauncherOptions;3public class WaitForTerminationAfterDestroy {4 public static void main(String[] args) {5 ProcessLauncherOptions options = new ProcessLauncherOptions();6 options.setProcessToLaunch("notepad.exe");7 AbstractBaseProcessLauncher processLauncher = new AbstractBaseProcessLauncher(options) {8 };9 processLauncher.launch();10 processLauncher.destroy();11 processLauncher.waitForTerminationAfterDestroy();12 }13}

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.

Run SeLion automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful