How to use stop method of com.testsigma.agent.launcher.Application class

Best Testsigma code snippet using com.testsigma.agent.launcher.Application.stop

Source:Application.java Github

copy

Full Screen

...8import java.nio.channels.FileChannel;9import java.nio.channels.FileLock;10import java.util.Objects;11public class Application {12 private static final String STOP_COMMAND = "stop";13 private static final int GRACEFUL_SHUTDOWN_THRESH_HOLD = 60;14 private static final Logger log = LogManager.getLogger(Application.class);15 public static void main(String[] paramArrayOfString) {16 if (paramArrayOfString.length >= 1 && STOP_COMMAND.equalsIgnoreCase(paramArrayOfString[0])) {17 stop();18 } else {19 start();20 }21 Runtime.getRuntime().halt(0);22 }23 private static void start() {24 log.info("-------------------- Testsigma Agent - START -------------------");25 try {26 File lockFile = new File(Objects.requireNonNull(Config.getDataDir()) + File.separator + "lock");27 File pidFile = new File(Objects.requireNonNull(Config.getDataDir()) + File.separator + "process.pid");28 log.info("Lock File Location: " + lockFile.getAbsolutePath());29 log.info("PID File Location: " + pidFile.getAbsolutePath());30 RandomAccessFile randomAccessFile = new RandomAccessFile(lockFile, "rw");31 FileChannel fileChannel = randomAccessFile.getChannel();32 FileLock fileLock = fileChannel.tryLock();33 if (fileLock != null) {34 try {35 Thread.currentThread().setName("TestsigmaAgentWrapper");36 createPidFile(pidFile);37 Launcher.getInstance().launch().join();38 removePidFile(pidFile);39 } catch (Exception e) {40 log.error(e.getMessage(), e);41 }42 log.info("Releasing Lock On Testsigma Agent Lock File...");43 fileLock.release();44 fileChannel.close();45 randomAccessFile.close();46 boolean lockDeleted = lockFile.delete();47 log.info("Testsigma Agent Lock File " + lockFile.getAbsolutePath() + " Deleted " + lockDeleted);48 } else {49 log.info("Failed To Launch Testsigma Agent - Another Instance Of Testsigma Agent Is Already Running!");50 fileChannel.close();51 randomAccessFile.close();52 }53 } catch (Exception e) {54 log.error(e.getMessage(), e);55 }56 log.info("-------------------- Testsigma Agent - STOPPED -------------------");57 }58 private static void createPidFile(File pidFile) throws IOException {59 removePidFile(pidFile);60 RandomAccessFile pidFileWriter = new RandomAccessFile(pidFile, "rw");61 long processPid = ProcessHandle.current().pid();62 log.info("Testsigma Agent Main PID - " + processPid);63 pidFileWriter.writeBytes(processPid + "");64 pidFileWriter.close();65 }66 private static void removePidFile(File pidFile) {67 if (pidFile.exists()) {68 log.debug("Testsigma Agent Main PID File Exists - " + pidFile.getAbsolutePath());69 boolean pidFileDeleted = pidFile.delete();70 log.debug("Testsigma Agent Main PID File " + pidFile.getAbsolutePath() + " Deleted - " + pidFileDeleted);71 } else {72 log.debug("Testsigma Agent Main PID File Doesn't Exists - " + pidFile.getAbsolutePath());73 }74 }75 private static void stop() {76 try {77 log.info("Stopping Testsigma Agent Using Stop Command");78 File pidFile = new File(Objects.requireNonNull(Config.getDataDir()) + File.separator + "process.pid");79 log.info("PID File Location: " + pidFile.getAbsolutePath());80 RandomAccessFile pidFileReader = new RandomAccessFile(pidFile, "r");81 String pid = pidFileReader.readLine();82 pidFileReader.close();83 if (StringUtils.isNoneBlank(pid)) {84 ProcessHandle processHandle = ProcessHandle.of(Long.parseLong(pid)).get();85 if (processHandle.supportsNormalTermination()) {86 log.debug("Process Implementation Supports Normal Termination. Terminating the Process Normally");87 processHandle.destroy();88 } else {89 log.debug("Process Implementation Doesn't Support Normal Termination(Probably Windows / VM). Destroying Parent and Child Processes Forcefully");90 stopProcessForcefully(processHandle);91 }92 for (int i = 0; i < GRACEFUL_SHUTDOWN_THRESH_HOLD; i += 5) {93 Thread.sleep(5000);94 if (!processHandle.isAlive()) {95 break;96 } else {97 log.info("Waiting For Testsigma Agent To Stop");98 }99 }100 if (processHandle.isAlive()) {101 log.info("Testsigma Agent Was Not Stopped Gracefully. Shutting It Down Forcefully");102 stopProcessForcefully(processHandle);103 } else {104 log.info("Stopped Testsigma Agent Gracefully");105 }106 if (pidFile.exists()) {107 removePidFile(pidFile);108 }109 } else {110 log.error("Process PID not found in PID file - " + pidFile.getAbsolutePath());111 }112 } catch (IOException | InterruptedException e) {113 log.error(e.getMessage(), e);114 }115 }116 private static void stopProcessForcefully(ProcessHandle processHandle) {117 try {118 Thread.sleep(5000);119 processHandle.children().forEach(Application::stopProcessForcefully);120 processHandle.destroyForcibly();121 } catch (Exception e) {122 log.error(e.getMessage(), e);123 }124 }125}...

Full Screen

Full Screen

stop

Using AI Code Generation

copy

Full Screen

1import com.testsigma.agent.launcher.Application;2Application app;3void stopApp() {4 app.stop();5}6void startApp() {7 app = new Application();8 app.start();9}10void run() {11 startApp();12 stopApp();13}14void main() {15 run();16}

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 Testsigma 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