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

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

Source:ExternalSutController.java Github

copy

Full Screen

...179 }180 if (command.stream().noneMatch(s -> s.startsWith("-Xms"))) {181 command.add("-Xms1G");182 }183 if(isUsingJaCoCo()){184 //command.add("-javaagent:"+jaCoCoLocation+"=destfile="+jaCoCoOutputFile+",append=false,dumponexit=true");185 command.add("-javaagent:"+ jaCoCoAgentLocation +"=output=tcpserver,port="+jaCoCoPort+",append=false,dumponexit=true");186 //tcpserver187 }188 command.add("-jar");189 command.add(getPathToExecutableJar());190 for (String s : getInputParameters()) {191 if (s != null) {192 String token = s.trim();193 if (!token.isEmpty()) {194 command.add(token);195 }196 }197 }198 SimpleLogger.info("Going to start SUT with command:\n" + String.join(" ", command));199 // now start the process200 ProcessBuilder builder = new ProcessBuilder(command);201 builder.redirectErrorStream(true);202 try {203 process = builder.start();204 } catch (IOException e) {205 SimpleLogger.error("Failed to start external process", e);206 return null;207 }208 //this is not only needed for debugging, but also to check for when SUT is ready209 startExternalProcessPrinter();210 if (instrumentation && serverController != null) {211 boolean connected = serverController.waitForIncomingConnection(getWaitingSecondsForIncomingConnection());212 if (!connected) {213 SimpleLogger.error("Could not establish connection to retrieve code metrics");214 if(errorBuffer != null) {215 SimpleLogger.error("SUT output:\n" + errorBuffer.toString());216 }217 stopSut();218 return null;219 }220 }221 //need to block until server is ready222 long timeout = getMaxAwaitForInitializationInSeconds();223 boolean completed;224 try {225 completed = latch.await(timeout, TimeUnit.SECONDS);226 } catch (InterruptedException e) {227 SimpleLogger.error("Interrupted controller");228 stopSut();229 return null;230 }231 if(! completed){232 SimpleLogger.error("SUT has not started properly within " + timeout + " seconds");233 if(errorBuffer != null) {234 SimpleLogger.error("SUT output:\n" + errorBuffer.toString());235 }236 stopSut();237 return null;238 }239 if (!isSutRunning()) {240 SimpleLogger.error("SUT started but then terminated. Likely a possible misconfiguration");241 if(errorBuffer != null) {242 SimpleLogger.error("SUT output:\n" + errorBuffer.toString());243 }244 //note: actual process might still be running due to Java Agent we started245 stopSut();246 return null;247 }248 if (!initialized) {249 //this could happen if SUT is hanging for some reason250 SimpleLogger.error("SUT is started but not initialized");251 if(errorBuffer != null) {252 SimpleLogger.error("SUT output:\n" + errorBuffer.toString());253 }254 //note: actual process might still be running due to Java Agent we started255 stopSut();256 return null;257 }258 postStart();259 return getBaseURL();260 }261 @Override262 public final boolean isSutRunning() {263 return process != null && process.isAlive();264 }265 @Override266 public final void stopSut() {267 SimpleLogger.info("Going to stop the SUT");268 preStop();269 if (serverController != null) {270 serverController.closeServer();271 }272 killProcess();273 initialized = false;274 postStop();275 }276 @Override277 public final boolean isInstrumentationActivated() {278 return instrumentation && serverController != null && serverController.isConnectionOn();279 }280 @Override281 public final void newSearch() {282 if (isInstrumentationActivated()) {283 serverController.resetForNewSearch();284 }285 }286 @Override287 public final void newTestSpecificHandler() {288 if (isInstrumentationActivated()) {289 serverController.resetForNewTest();290 }291 }292 @Override293 public final List<TargetInfo> getTargetInfos(Collection<Integer> ids) {294 checkInstrumentation();295 return serverController.getTargetsInfo(ids);296 }297 @Override298 public final List<AdditionalInfo> getAdditionalInfoList(){299 checkInstrumentation();300 return serverController.getAdditionalInfoList();301 }302 @Override303 public BootTimeInfoDto getBootTimeInfoDto() {304 if(!isInstrumentationActivated()){305 return null;306 }307 return getBootTimeInfoDto(serverController.handleBootTimeObjectiveInfo());308 }309 @Override310 public final void newActionSpecificHandler(ActionDto dto) {311 if (isInstrumentationActivated()) {312 serverController.setAction(new Action(dto.index, dto.inputVariables, dto.externalServiceMapping));313 }314 }315 @Override316 public final UnitsInfoDto getUnitsInfoDto(){317 if(!isInstrumentationActivated()){318 return null;319 }320 return getUnitsInfoDto(serverController.getUnitsInfoRecorder());321 }322 @Override323 public final void setKillSwitch(boolean b) {324 checkInstrumentation();325 serverController.setKillSwitch(b);326 ExecutionTracer.setKillSwitch(b);// store info locally as well, to avoid needing to do call to fetch current value327 }328 @Override329 public final void setExecutingInitSql(boolean executingInitSql) {330 checkInstrumentation();331 serverController.setExecutingInitSql(executingInitSql);332 // sync executingInitSql on the local ExecutionTracer333 ExecutionTracer.setExecutingInitSql(executingInitSql);334 }335 @Override336 public final void setExecutingAction(boolean executingAction){337 checkInstrumentation();338 serverController.setExecutingAction(executingAction);339 // sync executingAction on the local ExecutionTracer340 ExecutionTracer.setExecutingAction(executingAction);341 }342 @Override343 public final String getExecutableFullPath(){344 validateJarPath();345 //this might be relative346 String path = getPathToExecutableJar();347 return Paths.get(path).toAbsolutePath().toString();348 }349 //-----------------------------------------350 private boolean isUsingJaCoCo(){351 return !jaCoCoAgentLocation.isEmpty() && !jaCoCoOutputFile.isEmpty() && !jaCoCoCliLocation.isEmpty();352 }353 private void checkInstrumentation() {354 if (!isInstrumentationActivated()) {355 throw new IllegalStateException("Instrumentation is not active");356 }357 }358 private void validateJarPath() {359 String path = getPathToExecutableJar();360 if (!path.endsWith(".jar")) {361 throw new IllegalStateException("Invalid jar path does not end with '.jar': " + path);362 }363 if (!Files.exists(Paths.get(path))) {364 throw new IllegalArgumentException("File does not exist: " + path);365 }366 }367 private void killProcess() {368 try {369 Runtime.getRuntime().removeShutdownHook(processKillHook);370 } catch (Exception e) {371 /* do nothing. this can happen if shutdown is in progress */372 }373 if (process != null) {374 if(isUsingJaCoCo()){375 dumpJaCoCo();376 //attemptGracefulShutdown(process);377 }378 process.destroy();379 try {380 //be sure streamers are closed, otherwise process might hang on Windows381 process.getOutputStream().close();382 process.getInputStream().close();383 process.getErrorStream().close();384 } catch (Exception t) {385 SimpleLogger.error("Failed to close process stream: " + t.toString());386 }387 process = null;388 }...

Full Screen

Full Screen

isUsingJaCoCo

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.ExternalSutController;2import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto;3import org.evomaster.client.java.controller.api.dto.database.operations.InsertionDto;4import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;5import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;6import org.evomaster.client.java.controller.api.dto.database.schema.TableDto;7import org.evomaster.client.java.controller.api.dto.database.schema.TableIndexDto;8import org.evomaster.client.java.controller.api.dto.database.schema.TableIndexType;9import org.evomaster.client.java.controller.api.dto.database.schema.TableSchemaDto;10import org.evomaster.client.java.controller.api.dto.database.schema.ViewDto;11import org.evomaster.client.java.controller.api.dto.database.schema.ViewSchemaDto;12import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto;13import org.evomaster.client.java.controller.api.dto.database.operations.InsertionDto;14import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;15import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;16import org.evomaster.client.java.controller.api.dto.database.schema.TableDto;17import org.evomaster.client.java.controller.api.dto.database.schema.TableIndexDto;18import org.evomaster.client.java.controller.api.dto.database.schema.TableIndexType;19import org.evomaster.client.java.controller.api.dto.database.schema.TableSchemaDto;20import org.evomaster.client.java.controller.api.dto.database.schema.ViewDto;21import org.evomaster.client.java.controller.api.dto.database.schema.ViewSchemaDto;22import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto;23import org.evomaster.client.java.controller.api.dto.database.operations.InsertionDto;24import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;25import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;26import org.evomaster.client.java.controller.api.dto.database.schema.TableDto;27import org.evomaster.client.java.controller.api.dto.database.schema.TableIndexDto;28import org.evomaster.client.java.controller.api.dto.database.schema.TableIndexType;29import org.evomaster.client.java.controller.api.dto.database.schema.TableSchemaDto;30import org.evomaster.client.java.controller.api.dto.database.schema.ViewDto;

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