How to use startExternalProcessPrinter method of org.evomaster.client.java.controller.ExternalSutController class

Best EvoMaster code snippet using org.evomaster.client.java.controller.ExternalSutController.startExternalProcessPrinter

Source:ExternalSutController.java Github

copy

Full Screen

...163 SimpleLogger.error("Failed to start external process", e);164 return null;165 }166 //this is not only needed for debugging, but also to check for when SUT is ready167 startExternalProcessPrinter();168 if (instrumentation && serverController != null) {169 boolean connected = serverController.waitForIncomingConnection();170 if (!connected) {171 SimpleLogger.error("Could not establish connection to retrieve code metrics");172 return null;173 }174 }175 //need to block until server is ready176 long timeout = getMaxAwaitForInitializationInSeconds();177 boolean completed;178 try {179 completed = latch.await(timeout, TimeUnit.SECONDS);180 } catch (InterruptedException e) {181 SimpleLogger.error("Interrupted controller");182 stopSut();183 return null;184 }185 if(! completed){186 SimpleLogger.error("SUT has not started properly within " + timeout + " seconds");187 if(errorBuffer != null) {188 SimpleLogger.error("SUT output:\n" + errorBuffer.toString());189 }190 stopSut();191 return null;192 }193 if (!isSutRunning()) {194 SimpleLogger.error("SUT started but then terminated. Likely a possible misconfiguration");195 if(errorBuffer != null) {196 SimpleLogger.error("SUT output:\n" + errorBuffer.toString());197 }198 //note: actual process might still be running due to Java Agent we started199 stopSut();200 return null;201 }202 if (!initialized) {203 //this could happen if SUT is hanging for some reason204 SimpleLogger.error("SUT is started but not initialized");205 if(errorBuffer != null) {206 SimpleLogger.error("SUT output:\n" + errorBuffer.toString());207 }208 //note: actual process might still be running due to Java Agent we started209 stopSut();210 return null;211 }212 postStart();213 return getBaseURL();214 }215 @Override216 public boolean isSutRunning() {217 return process != null && process.isAlive();218 }219 @Override220 public void stopSut() {221 SimpleLogger.info("Going to stop the SUT");222 preStop();223 if (serverController != null) {224 serverController.closeServer();225 }226 killProcess();227 initialized = false;228 postStop();229 }230 @Override231 public final boolean isInstrumentationActivated() {232 return instrumentation && serverController != null && serverController.isConnectionOn();233 }234 @Override235 public final void newSearch() {236 if (isInstrumentationActivated()) {237 serverController.resetForNewSearch();238 }239 }240 @Override241 public final void newTestSpecificHandler() {242 if (isInstrumentationActivated()) {243 serverController.resetForNewTest();244 }245 }246 @Override247 public final List<TargetInfo> getTargetInfos(Collection<Integer> ids) {248 checkInstrumentation();249 return serverController.getTargetsInfo(ids);250 }251 @Override252 public final List<AdditionalInfo> getAdditionalInfoList(){253 checkInstrumentation();254 return serverController.getAdditionalInfoList();255 }256 @Override257 public final void newActionSpecificHandler(ActionDto dto) {258 if (isInstrumentationActivated()) {259 serverController.setAction(new Action(dto.index, dto.inputVariables));260 }261 }262 @Override263 public final UnitsInfoDto getUnitsInfoDto(){264 if(!isInstrumentationActivated()){265 return null;266 }267 return getUnitsInfoDto(serverController.getUnitsInfoRecorder());268 }269 //-----------------------------------------270 private void checkInstrumentation() {271 if (!isInstrumentationActivated()) {272 throw new IllegalStateException("Instrumentation is not active");273 }274 }275 private void validateJarPath() {276 String path = getPathToExecutableJar();277 if (!path.endsWith(".jar")) {278 throw new IllegalStateException("Invalid jar path does not end with '.jar': " + path);279 }280 if (!Files.exists(Paths.get(path))) {281 throw new IllegalArgumentException("File does not exist: " + path);282 }283 }284 private void killProcess() {285 try {286 Runtime.getRuntime().removeShutdownHook(processKillHook);287 } catch (Exception e) {288 /* do nothing. this can happen if shutdown is in progress */289 }290 if (process != null) {291 try {292 //be sure streamers are closed, otherwise process might hang on Windows293 process.getOutputStream().close();294 process.getInputStream().close();295 process.getErrorStream().close();296 } catch (Exception t) {297 SimpleLogger.error("Failed to close process stream: " + t.toString());298 }299 process.destroy();300 process = null;301 }302 }303 protected void startExternalProcessPrinter() {304 if (outputPrinter == null || !outputPrinter.isAlive()) {305 outputPrinter = new Thread(() -> {306 try {307 boolean muted = Boolean.parseBoolean(System.getProperty(PROP_MUTE_SUT));308 if(muted){309 errorBuffer = new StringBuffer(4096);310 }311 Scanner scanner = new Scanner(new BufferedReader(312 new InputStreamReader(process.getInputStream())));313 while (scanner.hasNextLine()) {314 String line = scanner.nextLine();315 if(line.startsWith(P6SpyFormatter.PREFIX)){316 StandardOutputTracker.handleSqlLine(this, line);317 }...

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