How to use noKillSwitchForceCheck method of org.evomaster.client.java.controller.internal.EMController class

Best EvoMaster code snippet using org.evomaster.client.java.controller.internal.EMController.noKillSwitchForceCheck

Source:EMController.java Github

copy

Full Screen

...102 ExecutionTracer.setKillSwitch(false);103 lambda.run();104 ExecutionTracer.setKillSwitch(previous);105 }106 private void noKillSwitchForceCheck(Runnable lambda){107 /*108 Note: bit tricky for External. the calls on ExecutionTracer would have109 no impact, only those on sutController. it is needed for when driver communicates110 with SUT as part of driver operations, eg reset/seed state via an API call, which is111 done for example in Proxyprint. But for all other cases, it can be just an unnecessary112 overhead.113 */114 boolean previous = ExecutionTracer.isKillSwitch();115 sutController.setKillSwitch(false);116 lambda.run();117 sutController.setKillSwitch(previous);118 }119 @Path(ControllerConstants.INFO_SUT_PATH)120 @GET121 public Response getSutInfo(@Context HttpServletRequest httpServletRequest) {122 String connectionHeader = httpServletRequest.getHeader("Connection");123 if( connectionHeader == null124 || !connectionHeader.equalsIgnoreCase("keep-alive")){125 return Response.status(400).entity(WrappedResponseDto126 .withError("Requests should always contain a 'Connection: keep-alive'")).build();127 }128 assert trackRequestSource(httpServletRequest);129 if(! noKillSwitch(() -> sutController.verifySqlConnection())){130 String msg = "SQL drivers are misconfigured. You must use a 'p6spy' wrapper when you " +131 "run the SUT. For example, a database connection URL like 'jdbc:h2:mem:testdb' " +132 "should be changed into 'jdbc:p6spy:h2:mem:testdb'. " +133 "See documentation on how to configure P6Spy.";134 SimpleLogger.error(msg);135 return Response.status(500).entity(WrappedResponseDto.withError(msg)).build();136 }137 SutInfoDto dto = new SutInfoDto();138 dto.isSutRunning = noKillSwitch(() -> sutController.isSutRunning());139 dto.baseUrlOfSUT = baseUrlOfSUT;140 dto.infoForAuthentication = noKillSwitch(() -> sutController.getInfoForAuthentication());141 dto.sqlSchemaDto = noKillSwitch(() -> sutController.getSqlDatabaseSchema());142 dto.defaultOutputFormat = noKillSwitch(() -> sutController.getPreferredOutputFormat());143 ProblemInfo info = noKillSwitch(() -> sutController.getProblemInfo());144 if (info == null) {145 String msg = "Undefined problem type in the EM Controller";146 SimpleLogger.error(msg);147 return Response.status(500).entity(WrappedResponseDto.withError(msg)).build();148 } else if (info instanceof RestProblem) {149 RestProblem rp = (RestProblem) info;150 dto.restProblem = new RestProblemDto();151 dto.restProblem.swaggerJsonUrl = rp.getSwaggerJsonUrl();152 dto.restProblem.endpointsToSkip = rp.getEndpointsToSkip();153 } else if( info instanceof GraphQlProblem){154 GraphQlProblem p = (GraphQlProblem) info;155 dto.graphQLProblem = new GraphQLProblemDto();156 dto.graphQLProblem.endpoint = p.getEndpoint();157 }else {158 String msg = "Unrecognized problem type: " + info.getClass().getName();159 SimpleLogger.error(msg);160 return Response.status(500).entity(WrappedResponseDto.withError(msg)).build();161 }162 dto.unitsInfoDto = noKillSwitch(() -> sutController.getUnitsInfoDto());163 if(dto.unitsInfoDto == null){164 String msg = "Failed to extract units info";165 SimpleLogger.error(msg);166 return Response.status(500).entity(WrappedResponseDto.withError(msg)).build();167 }168 return Response.status(200).entity(WrappedResponseDto.withData(dto)).build();169 }170 @Path(ControllerConstants.CONTROLLER_INFO)171 @GET172 public Response getControllerInfoDto(@Context HttpServletRequest httpServletRequest) {173 assert trackRequestSource(httpServletRequest);174 ControllerInfoDto dto = new ControllerInfoDto();175 dto.fullName = noKillSwitch(() -> sutController.getClass().getName());176 dto.isInstrumentationOn = noKillSwitch(() -> sutController.isInstrumentationActivated());177 return Response.status(200).entity(WrappedResponseDto.withData(dto)).build();178 }179 @Path(ControllerConstants.NEW_SEARCH)180 @POST181 public Response newSearch(@Context HttpServletRequest httpServletRequest) {182 assert trackRequestSource(httpServletRequest);183 lastSqlCommandId = null;184 noKillSwitch(() -> sutController.newSearch());185 return Response.status(201).entity(WrappedResponseDto.withNoData()).build();186 }187 @Path(ControllerConstants.RUN_SUT_PATH)188 @PUT189 @Consumes(Formats.JSON_V1)190 public Response runSut(SutRunDto dto, @Context HttpServletRequest httpServletRequest) {191 assert trackRequestSource(httpServletRequest);192 /*193 If start/stop the SUT, we want to disable the killSwitch.194 The reason is it might be on from previous run, and, in such case,195 until we run a first test it would crash the SUT... eg when retrieving196 OpenAPI/GraphQL schema.197 TODO: likely all the noKillSwitch calls here are redundant198 */199 ExecutionTracer.setKillSwitch(false);200 if(sutController.isSutRunning()) {201 sutController.setKillSwitch(false);202 }203 try {204 if (dto.run == null) {205 String msg = "Invalid JSON: 'run' field is required";206 SimpleLogger.warn(msg);207 return Response.status(400).entity(WrappedResponseDto.withError(msg)).build();208 }209 boolean sqlHeuristics = dto.calculateSqlHeuristics != null && dto.calculateSqlHeuristics;210 boolean sqlExecution = dto.extractSqlExecutionInfo != null && dto.extractSqlExecutionInfo;211 noKillSwitch(() -> sutController.enableComputeSqlHeuristicsOrExtractExecution(sqlHeuristics, sqlExecution));212 boolean doReset = dto.resetState != null && dto.resetState;213 synchronized (this) {214 if (!dto.run) {215 if (doReset) {216 String msg = "Invalid JSON: cannot reset state and stop service at same time";217 SimpleLogger.warn(msg);218 return Response.status(400).entity(WrappedResponseDto.withError(msg)).build();219 }220 //if on, we want to shut down the server221 if (noKillSwitch(() -> sutController.isSutRunning())) {222 noKillSwitch(() -> sutController.stopSut());223 baseUrlOfSUT = null;224 }225 } else {226 /*227 If SUT is not up and running, let's start it228 */229 if (!noKillSwitch(() -> sutController.isSutRunning())) {230 baseUrlOfSUT = noKillSwitch(() -> sutController.startSut());231 if (baseUrlOfSUT == null) {232 //there has been an internal failure in starting the SUT233 String msg = "Internal failure: cannot start SUT based on given configuration";234 SimpleLogger.warn(msg);235 return Response.status(500).entity(WrappedResponseDto.withError(msg)).build();236 }237 noKillSwitch(() -> sutController.initSqlHandler());238 } else {239 //TODO as starting should be blocking, need to check240 //if initialized, and wait if not241 }242 /*243 regardless of where it was running or not, need to reset state.244 this is controlled by a boolean, although most likely we ll always245 want to do it246 */247 if (dto.resetState != null && dto.resetState) {248 try{249 /*250 This should not fail... but, as it is user code, it might fail...251 When it does, it is a major issue, as it can leave the system in252 an inconsistent state for the following fitness evaluations.253 So, we always force a newTest, even when reset fails.254 TODO: a current problem is in Proxyprint, in which after REST calls255 it seems there are locks on the DB (this might happen if a transaction256 is started but then not committed). Ideally, in the reset of DBs we should257 force all lock releases, and possibly point any left lock as a potential bug258 */259 noKillSwitchForceCheck(() -> sutController.resetStateOfSUT());260 } finally {261 noKillSwitch(() -> sutController.newTest());262 }263 }264 /*265 Note: here even if we start the SUT, the starting of a "New Search"266 cannot be done here, as in this endpoint we also deal with the reset267 of state. When we reset state for a new test run, we do not want to268 reset all the other data regarding the whole search269 */270 }271 }272 } catch (RuntimeException e) {273 /*...

Full Screen

Full Screen

noKillSwitchForceCheck

Using AI Code Generation

copy

Full Screen

1package com.example.demo;2public class MathUtils {3 public int divide(int a, int b) {4 return a / b;5 }6}7package com.example.demo;8import com.foo.somedifferentpackage.examples.ExampleClass;9import com.foo.somedifferentpackage.examples.ExampleInterface;10import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl;11import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl2;12import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl3;13import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl4;14import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl5;15import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl6;16import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl7;17import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl8;18import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl9;19import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl10;20import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl11;21import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl12;22import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl13;23import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl14;24import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl15;25import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl16;26import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl17;27import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl18;28import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl19;29import com.foo.somedifferentpackage.examples.ExampleInterfaceImpl20;30import com.foo.somedifferentpackage.examples.Ex

Full Screen

Full Screen

noKillSwitchForceCheck

Using AI Code Generation

copy

Full Screen

1 EMController controller = new EMController();2 controller.noKillSwitchForceCheck();3 controller.newAction("org.evomaster.client.java.controller.problem.ProblemInfo", "getBaseURL");4 String baseURL = ProblemInfo.getBaseURL();5 controller.newAction("org.evomaster.client.java.controller.problem.ProblemInfo", "getSutControllerPackage");6 String controllerPackage = ProblemInfo.getSutControllerPackage();7 controller.newAction("org.evomaster.client.java.controller.problem.ProblemInfo", "getSutName");8 String sutName = ProblemInfo.getSutName();9 controller.newAction("org.evomaster.client.java.controller.problem.ProblemInfo", "getSutType");10 String sutType = ProblemInfo.getSutType();11 controller.newAction("org.evomaster.client.java.controller.problem.ProblemInfo", "getSutPort");12 int port = ProblemInfo.getSutPort();13 controller.newAction("org.evomaster.client.java.controller.problem.ProblemInfo", "getSutControllerPath");14 String controllerPath = ProblemInfo.getSutControllerPath();15 controller.newAction("org.evomaster.client.java.controller.problem.ProblemInfo", "getProblemInfo");16 ProblemInfo problemInfo = ProblemInfo.getProblemInfo();17 controller.newAction("org.evomaster.client.java.controller.problem.ProblemInfo", "getSwaggerJson");18 String swaggerJson = ProblemInfo.getSwaggerJson();19 controller.newAction("org.evomaster.client.java.controller.problem.ProblemInfo", "getSwaggerYaml");20 String swaggerYaml = ProblemInfo.getSwaggerYaml();21 controller.newAction("org.evomaster.client.java.controller.problem.ProblemInfo", "getSutControllerClazz");22 Class<?> clazz = ProblemInfo.getSutControllerClazz();23 controller.newAction("org.evomaster.client.java.controller.problem.ProblemInfo", "getSutControllerClazz");24 Class<?> clazz = ProblemInfo.getSutControllerClazz();25 controller.newAction("org.evomaster.client.java.controller.problem.ProblemInfo", "getSutControllerClazz");

Full Screen

Full Screen

noKillSwitchForceCheck

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.internal.EMController2def emController = new EMController()3emController.noKillSwitchForceCheck()4emController.killSwitchForceCheck()5import org.evomaster.client.java.controller.internal.EMController6def emController = new EMController()7emController.noKillSwitchForceCheck()8emController.killSwitchForceCheck()9import org.evomaster.client.java.controller.internal.EMController10def emController = new EMController()11emController.noKillSwitchForceCheck()12emController.killSwitchForceCheck()13import org.evomaster.client.java.controller.internal.EMController14def emController = new EMController()15emController.noKillSwitchForceCheck()16emController.killSwitchForceCheck()17import org.evomaster.client.java.controller.internal.EMController

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