How to use launch method of com.testsigma.agent.launcher.Launcher class

Best Testsigma code snippet using com.testsigma.agent.launcher.Launcher.launch

Source:Launcher.java Github

copy

Full Screen

1package com.testsigma.agent.launcher;2import dorkbox.systemTray.Entry;3import dorkbox.systemTray.MenuItem;4import dorkbox.systemTray.SystemTray;5import org.apache.commons.lang3.StringUtils;6import org.apache.commons.lang3.SystemUtils;7import org.apache.http.HttpResponse;8import org.apache.http.client.methods.HttpGet;9import org.apache.http.client.utils.HttpClientUtils;10import org.apache.http.impl.client.CloseableHttpClient;11import org.apache.http.impl.client.HttpClients;12import org.apache.http.util.EntityUtils;13import org.slf4j.Logger;14import org.slf4j.LoggerFactory;15import java.awt.*;16import java.awt.event.ActionEvent;17import java.io.File;18import java.io.IOException;19import java.io.InputStream;20import java.lang.management.ManagementFactory;21import java.lang.management.RuntimeMXBean;22import java.net.ServerSocket;23import java.net.Socket;24import java.net.URISyntaxException;25import java.net.URL;26import java.nio.file.Path;27import java.nio.file.Paths;28import java.util.ArrayList;29import java.util.List;30import java.util.concurrent.*;31import static javax.swing.JOptionPane.showMessageDialog;32public class Launcher {33 private static final Logger log = LoggerFactory.getLogger(Launcher.class);34 private static final String classPathSeparator = (SystemUtils.IS_OS_WINDOWS ? ";" : ":");35 private static Launcher _instance;36 private final ExecutorService executorService = Executors.newCachedThreadPool();37 private boolean background = false;38 private boolean running = true;39 private boolean restart = false;40 private SystemTray systemTray = null;41 private ExecutorService socketExecutorService;42 private CompletableFuture<?> completableFuture;43 private Future<?> future;44 private ServerSocket wrapperServer;45 private Socket ipcSocket;46 private Process agentProcess;47 private AgentStatus agentStatus;48 private Thread shutdownHookThread;49 private CloseableHttpClient client;50 public static Launcher getInstance() {51 if (_instance == null) {52 _instance = new Launcher();53 }54 return _instance;55 }56 public final CompletableFuture<?> launch() {57 log.info("Launching Agent...");58 this.shutdownHookThread = new Thread(this::shutdownLauncher);59 Runtime.getRuntime().addShutdownHook(shutdownHookThread);60 configureSystemTrayIcon();61 start();62 return (this.completableFuture = new CompletableFuture());63 }64 private void start() {65 waitForAgentToStop();66 Launcher launcher = this;67 this.executorService.submit(() -> {68 List<String> command;69 launcher.agentProcess = null;70 log.info("Starting Agent...");71 setStatus(AgentStatus.STARTING);72 try {73 launcher.startWrapperServer();74 this.future = launcher.socketExecutorService.submit(() -> {75 Thread.currentThread().setName("agent-launcher-server");76 this.startIpcSocket();77 this.cleanupAgentProcess();78 shutdownLauncher();79 if (!this.background) {80 this.systemTray.shutdown();81 }82 //Commenting out restart option dues continuous restart when web server config fetch fails83 //this.restart();84 });85 command = launcher.agentStartCommand(launcher.wrapperServer.getLocalPort());86 launcher.agentProcess = launcher.startAgentProcess(command);87 log.debug("Waiting for Agent to start...");88 int agentStartupChecks = 60;89 while (agentStartupChecks > 0) {90 try {91 log.debug("Waiting for Agent to start");92 TimeUnit.SECONDS.sleep(1L);93 } catch (Exception e) {94 log.error(e.getMessage(), e);95 }96 if (!launcher.agentProcess.isAlive()) {97 log.error("Agent exited unexpectedly with exit code - " + launcher.agentProcess.exitValue());98 break;99 }100 if (launcher.ipcSocket != null) break;101 agentStartupChecks--;102 }103 if (launcher.ipcSocket != null) {104 log.info("Agent started successfully with process - " + agentProcess.pid());105 setStatus(AgentStatus.STARTED);106 } else {107 log.error("Failed to start agent....");108 }109 } catch (Exception e) {110 launcher.completableFuture.completeExceptionally(e);111 } finally {112 handleFailedStart();113 }114 });115 }116 private void restart() {117 if (this.running) {118 if (this.restart) {119 log.info("Agent restart requested");120 this.restart = false;121 }122 if (this.agentProcess != null && this.agentProcess.exitValue() != 0) {123 log.info("Agent exit was not clean. Exit code - " + this.agentProcess.exitValue());124 this.shutdown();125 return;126 }127 log.info("Starting Agent again....");128 this.start();129 }130 }131 private void shutdownLauncher() {132 Thread.currentThread().setName("shutdown-hook");133 this.running = false;134 shutdown();135 waitForAgentToStop();136 this.completableFuture.complete(null);137 log.info("Shutting down Launcher");138 }139 private void shutdown() {140 if (this.agentStatus.equals(AgentStatus.STOPPING) || this.agentStatus.equals(AgentStatus.STOPPED))141 return;142 log.info("Agent shutdown initiated");143 Process process = this.agentProcess;144 setStatus(AgentStatus.STOPPING);145 shutdownAgent();146 setStatus(AgentStatus.STOPPED);147 Executors.newSingleThreadScheduledExecutor().schedule(() -> {148 try {149 if (process.isAlive()) {150 log.info("Stopping agent process forcibly since agent process didn't exit normally");151 process.destroyForcibly();152 }153 } catch (Exception exception) {154 log.error(exception.getMessage(), exception);155 }156 }, 10L, TimeUnit.SECONDS);157 }158 private void shutdownAgent() {159 stopIpcSocket();160 stopWrapperServer();161 stopFuture();162 stopIpcSocketExecutorService();163 }164 private void waitForAgentToStop() {165 while (this.agentProcess != null && this.agentProcess.isAlive()) {166 log.info("Agent is still running, waiting");167 try {168 TimeUnit.SECONDS.sleep(1L);169 } catch (InterruptedException ignored) {170 }171 }172 }173 private void setStatus(AgentStatus agentStatus) {174 this.agentStatus = agentStatus;175 log.info("Changed Agent status to - " + agentStatus);176 if (this.background)177 return;178 this.systemTray.setStatus(String.format("Testsigma Agent - %s", agentStatus));179 }180 private List<String> agentStartCommand(int wrapperPort) throws URISyntaxException {181 RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();182 List<String> list = runtimeMXBean.getInputArguments();183 List<String> commandLineParameters = new ArrayList<>();184 for (String listStr : list) {185 if (!listStr.startsWith("-agentlib")) {186 commandLineParameters.add(listStr);187 }188 }189 List<String> command = new ArrayList<>();190 command.add(getJavaPath());191 command.addAll(commandLineParameters);192 command.add("-cp");193 command.add(getAgentClassPath());194 command.add("-Dagent.wrapper.port=" + wrapperPort);195 command.add("-Dagent.wrapper.background=" + this.background);196 command.add("com.testsigma.agent.TestsigmaAgent");197 return command;198 }199 private void sendFlare() {200 String alertMessage = "Unknown Error";201 try {202 client = HttpClients.createDefault();203 HttpGet getRequest = new HttpGet("http://localhost:8383/agent/api/v1/flare");204 HttpResponse response = client.execute(getRequest);205 if (response.getEntity() != null) {206 alertMessage = EntityUtils.toString(response.getEntity());207 }208 log.info("Response from flare request - " + response.getStatusLine() + " - " + alertMessage);209 } catch (Exception e) {210 alertMessage = e.getMessage();211 log.error(e.getMessage(), e);212 } finally {213 showMessageDialog(null, alertMessage);214 HttpClientUtils.closeQuietly(client);215 }216 }217 private void configureSystemTrayIcon() {218 if (GraphicsEnvironment.isHeadless()) {219 log.info("No Graphics environment available - headless mode.");220 this.background = true;221 }222 if (!this.background) {223 log.info("Loading System Tray icon");224 this.systemTray = SystemTray.get();225 InputStream inputStream = Launcher.class.getClassLoader().getResourceAsStream("icons/tray_icon.png");226 systemTray.setImage(inputStream);227 setStatus(AgentStatus.STOPPED);228 systemTray.getMenu().add((Entry) new dorkbox.systemTray.MenuItem("Send Flare Request", (ActionEvent actionEvent) -> {229 log.info("Agent send flare request menu action triggered");230 MenuItem menuItem = ((MenuItem) actionEvent.getSource());231 menuItem.setEnabled(false);232 sendFlare();233 menuItem.setEnabled(true);234 }));235// systemTray.getMenu().add((Entry) new dorkbox.systemTray.MenuItem("Restart", (ActionEvent actionEvent) -> {236// log.info("Agent restart menu action triggered");237// this.restart = true;238// shutdown();239// }));240 systemTray.getMenu().add((Entry) new MenuItem("Quit", (ActionEvent actionEvent) -> {241 log.info("Agent quit menu action triggered");242 Runtime.getRuntime().removeShutdownHook(this.shutdownHookThread);243 shutdownLauncher();244 if (!this.background) {245 this.systemTray.shutdown();246 }247 }));248 this.setupFrame();249 }250 }251 public void handleFailedStart() {252 if (this.ipcSocket == null) {253 if ((this.agentProcess != null) && agentProcess.isAlive()) {254 this.agentProcess.destroyForcibly();255 }256 this.shutdownAgent();257 }258 }259 private String getJavaPath() {260 String rootDir = System.getProperty("TS_ROOT_DIR");261 if (StringUtils.isNotBlank(rootDir)) {262 System.setProperty("java.home", rootDir + File.separator + "jre");263 }264 return System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";265 }266 private String getAgentClassPath() throws URISyntaxException {267 String classPath = System.getProperty("TS_AGENT_JAR") + File.separator + "lib" + File.separator + "*";268 String additionalClassPath = Config.getDataDir() + File.separator + "additional_libs" + File.separator + "*";269 String agentJarPath = getAgentJarPath();270 return agentJarPath + classPathSeparator + classPath + classPathSeparator + additionalClassPath;271 }272 private String getAgentJarPath() throws URISyntaxException {273 String agentJarDir = System.getProperty("TS_AGENT_JAR");274 if (StringUtils.isNotBlank(agentJarDir)) {275 return agentJarDir + File.separator + "agent.jar";276 }277 URL uRL = Launcher.class.getProtectionDomain().getCodeSource().getLocation();278 Path path = (new File(uRL.toURI())).toPath().getParent();279 return Paths.get(path.toAbsolutePath().toString(), "agent.jar").toAbsolutePath().toString();280 }281 private void startIpcSocket() {282 log.info("Accepting connection to the launcher socket....");283 try {284 this.ipcSocket = this.wrapperServer.accept();285 log.info("Agent connected to IPC socket...");286 } catch (Exception e) {287 log.error(e.getMessage(), e);288 }289 if (this.ipcSocket != null) {290 try {291 int data = this.ipcSocket.getInputStream().read();292 while (data != -1) {293 data = this.ipcSocket.getInputStream().read();294 }295 } catch (Exception e) {296 log.info("Agent disconnected from IPC socket");...

Full Screen

Full Screen

Source:Application.java Github

copy

Full Screen

1package com.testsigma.agent.launcher;2import org.apache.commons.lang3.StringUtils;3import org.apache.logging.log4j.LogManager;4import org.apache.logging.log4j.Logger;5import java.io.File;6import java.io.IOException;7import java.io.RandomAccessFile;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();...

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import com.testsigma.agent.launcher.Launcher;2public class 2 {3 public static void main(String[] args) {4 Launcher.launch(args);5 }6}7import com.testsigma.agent.launcher.Launcher;8public class 3 {9 public static void main(String[] args) {10 Launcher.launch(args);11 }12}13import com.testsigma.agent.launcher.Launcher;14public class 4 {15 public static void main(String[] args) {16 Launcher.launch(args);17 }18}19import com.testsigma.agent.launcher.Launcher;20public class 5 {21 public static void main(String[] args) {22 Launcher.launch(args);23 }24}25import com.testsigma.agent.launcher.Launcher;26public class 6 {27 public static void main(String[] args) {28 Launcher.launch(args);29 }30}31import com.testsigma.agent.launcher.Launcher;32public class 7 {33 public static void main(String[] args) {34 Launcher.launch(args);35 }36}37import com.testsigma.agent.launcher.Launcher;38public class 8 {39 public static void main(String[] args) {40 Launcher.launch(args);41 }42}43import com.testsigma.agent.launcher.Launcher;44public class 9 {45 public static void main(String[] args) {46 Launcher.launch(args);47 }48}49import com.testsigma.agent.launcher.Launcher;50public class 10 {51 public static void main(String[] args) {

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import com.testsigma.agent.launcher.Launcher;2import java.io.File;3import java.lang.reflect.InvocationTargetException;4import java.lang.reflect.Method;5import java.net.MalformedURLException;6import java.net.URL;7import java.net.URLClassLoader;8import java.util.ArrayList;9import java.util.List;10public class RunTest {11public static void main(String[] args) {12try {13File file = new File("D:/TestSigma/agent-1.0.0.jar");14URL url = file.toURI().toURL();15URL[] urls = new URL[]{url};16ClassLoader cl = new URLClassLoader(urls);17Class cls = cl.loadClass("com.testsigma.agent.launcher.Launcher");18Object obj = cls.newInstance();19Method method = cls.getDeclaredMethod("launch", String[].class);20String[] arr = new String[] { "-f", "D:/TestSigma/agent-1.0.0.jar", "-t", "D:/TestSigma/agent-1.0.0.jar", "-p", "D:/TestSigma/agent-1.0.0.jar", "-r", "D:/TestSigma/agent-1.0.0.jar" };21method.invoke(obj, (Object) arr);22} catch (MalformedURLException | ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {23}24}25}

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import com.testsigma.agent.launcher.Launcher;2public class 2 {3public static void main(String[] args) {4Launcher.main(new String[] { "2" });5}6}7import com.testsigma.agent.launcher.Launcher;8public class 3 {9public static void main(String[] args) {10Launcher.main(new String[] { "3" });11}12}13import com.testsigma.agent.launcher.Launcher;14public class 4 {15public static void main(String[] args) {16Launcher.main(new String[] { "4" });17}18}19import com.testsigma.agent.launcher.Launcher;20public class 5 {21public static void main(String[] args) {22Launcher.main(new String[] { "5" });23}24}25import com.testsigma.agent.launcher.Launcher;26public class 6 {27public static void main(String[] args) {28Launcher.main(new String[] { "6" });29}30}31import com.testsigma.agent.launcher.Launcher;32public class 7 {33public static void main(String[] args) {34Launcher.main(new String[] { "7" });35}36}37import com.testsigma.agent.launcher.Launcher;38public class 8 {39public static void main(String[] args) {40Launcher.main(new String[] { "8" });41}42}43import com.testsigma.agent.launcher.Launcher;44public class 9 {45public static void main(String[] args) {46Launcher.main(new String[] { "9" });47}48}49import com

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1package com.testsigma.agent.launcher;2import java.lang.reflect.InvocationTargetException;3import java.lang.reflect.Method;4public class Launcher {5 public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {6 Class<?> cls = Class.forName("com.testsigma.agent.launcher.Launcher");7 Method method = cls.getDeclaredMethod("launch", String.class, String.class, String.class, String.class, String.class, String.class, String.class);8 }9 public static void launch(String url, String apiKey, String packageName, String className, String methodName, String testName, String testDescription) {10 }11}12java -cp <path-to-jar-file>;<path-to-test.jar>;<path-to-junit-jar>;<path-to-assertj-jar>;<path-to-json-jar>;<path-to-httpclient-jar>;<path-to-httpcore-jar>;<path-to-commons-logging-jar> com.testsigma.agent.launcher.Launcher13java -cp <path-to-jar-file>;<path-to-test.jar>;<path

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import com.testsigma.agent.launcher.Launcher;2public class 2 {3public static void main(String[] args) {4Launcher.launch("C:\\Program Files (x86)\\TestSigma\\Agent\\config\\config.properties");5}6}7import com.testsigma.agent.launcher.Launcher;

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import com.testsigma.agent.launcher.Launcher;2public class 2 {3public static void main(String[] args) {4}5}6import com.testsigma.agent.launcher.Launcher;7public class 3 {8public static void main(String[] args) {9}10}11import com.testsigma.agent.launcher.Launcher;12public class 4 {13public static void main(String[] args) {14}15}16import com.testsigma.agent.launcher.Launcher;17public class 5 {18public static void main(String[] args) {19}20}21import com.testsigma.agent.launcher.Launcher;22public class 6 {23public static void main(String[] args) {24}25}26import com.testsigma.agent.launcher.Launcher;27public class 7 {28public static void main(String[] args) {29}30}31import com.testsigma.agent.launcher.Launcher;32public class 8 {33public static void main(String[] args) {

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import com.testsigma.agent.launcher.Launcher;2{3 public static void main(String[] args) throws Exception4 {5 String[] testArgs = {"-test", "com.testsigma.testcases.SampleTest"};6 Launcher.launch(testArgs, "com.testsigma.agent.launcher.Launcher");7 }8}9import com.testsigma.agent.launcher.Launcher;10{11 public static void main(String[] args) throws Exception12 {13 String[] testArgs = {"-test", "com.testsigma.testcases.SampleTest"};14 Launcher.launch(testArgs, "com.testsigma.testcases.SampleTest");15 }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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful