|
1 | 1 | package em.embedded.org.signal.registration; |
2 | 2 |
|
3 | | -public class EmbeddedEvoMasterController { |
| 3 | +import io.grpc.ManagedChannel; |
| 4 | +import io.grpc.ManagedChannelBuilder; |
| 5 | +import io.micronaut.context.ApplicationContext; |
| 6 | +import io.micronaut.core.util.CollectionUtils; |
| 7 | +import io.micronaut.runtime.server.EmbeddedServer; |
| 8 | +import org.evomaster.client.java.controller.EmbeddedSutController; |
| 9 | +import org.evomaster.client.java.controller.InstrumentedSutStarter; |
| 10 | +import org.evomaster.client.java.controller.api.dto.AuthenticationDto; |
| 11 | +import org.evomaster.client.java.controller.api.dto.SutInfoDto; |
| 12 | +import org.evomaster.client.java.controller.api.dto.problem.rpc.RPCType; |
| 13 | +import org.evomaster.client.java.controller.internal.db.DbSpecification; |
| 14 | +import org.evomaster.client.java.controller.problem.ProblemInfo; |
| 15 | +import org.evomaster.client.java.controller.problem.RPCProblem; |
| 16 | +import org.signal.registration.rpc.RegistrationServiceGrpc; |
| 17 | +import java.util.List; |
4 | 18 |
|
5 | | - //TODO |
| 19 | +public class EmbeddedEvoMasterController extends EmbeddedSutController { |
| 20 | + |
| 21 | + public static void main(String[] args) { |
| 22 | + |
| 23 | + int port = 40100; |
| 24 | + if (args.length > 0) { |
| 25 | + port = Integer.parseInt(args[0]); |
| 26 | + } |
| 27 | + |
| 28 | + EmbeddedEvoMasterController controller = new EmbeddedEvoMasterController(port); |
| 29 | + InstrumentedSutStarter starter = new InstrumentedSutStarter(controller); |
| 30 | + |
| 31 | + starter.start(); |
| 32 | + } |
| 33 | + |
| 34 | + public EmbeddedEvoMasterController() { |
| 35 | + this(40100); |
| 36 | + } |
| 37 | + |
| 38 | + public EmbeddedEvoMasterController(int port) { |
| 39 | + setControllerPort(port); |
| 40 | + } |
| 41 | + |
| 42 | + protected ManagedChannel channel; |
| 43 | + private RegistrationServiceGrpc.RegistrationServiceBlockingStub stub; |
| 44 | + |
| 45 | + private EmbeddedServer server; |
| 46 | + private ApplicationContext ctx; |
| 47 | + |
| 48 | + @Override |
| 49 | + public boolean isSutRunning() { |
| 50 | + return ctx != null && ctx.isRunning(); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public String getPackagePrefixesToCover() { |
| 55 | + return "org.signal.registration."; |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public List<AuthenticationDto> getInfoForAuthentication() { |
| 60 | + return null; |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public ProblemInfo getProblemInfo() { |
| 65 | + return new RPCProblem(RegistrationServiceGrpc.RegistrationServiceBlockingStub.class, stub, RPCType.gRPC); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public SutInfoDto.OutputFormat getPreferredOutputFormat() { |
| 70 | + return SutInfoDto.OutputFormat.JAVA_JUNIT_4; |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public String startSut() { |
| 75 | + |
| 76 | + try { |
| 77 | + server = ApplicationContext.run(EmbeddedServer.class,CollectionUtils.mapOf( |
| 78 | + "micronaut.environments","dev", |
| 79 | + "grpc.server.port", "${random.port}" |
| 80 | + ), "dev"); |
| 81 | + ctx = server.getApplicationContext(); |
| 82 | + |
| 83 | + startClient(); |
| 84 | + return "http://localhost:"+server.getPort(); |
| 85 | + |
| 86 | + } catch (Exception e) { |
| 87 | + throw new RuntimeException(e); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + private String startClient() { |
| 92 | + channel = ManagedChannelBuilder.forAddress("localhost", getSutPort()).usePlaintext().build(); |
| 93 | + stub = RegistrationServiceGrpc.newBlockingStub(channel); |
| 94 | + |
| 95 | + |
| 96 | + return "started:"+!(channel.isShutdown() || channel.isTerminated()); |
| 97 | + } |
| 98 | + |
| 99 | + protected int getSutPort() { |
| 100 | + return server.getPort(); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public void stopSut() { |
| 105 | + server.stop(); |
| 106 | + ctx.stop(); |
| 107 | + } |
| 108 | + |
| 109 | + @Override |
| 110 | + public void resetStateOfSUT() { |
| 111 | + |
| 112 | + } |
| 113 | + |
| 114 | + @Override |
| 115 | + public List<DbSpecification> getDbSpecifications() { |
| 116 | + return null; |
| 117 | + } |
6 | 118 | } |
0 commit comments