-
Notifications
You must be signed in to change notification settings - Fork 28
redis-sample drivers #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
redis-sample drivers #177
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| FROM amazoncorretto:21-alpine-jdk | ||
|
|
||
| COPY ./dist/redis-sample-sut.jar . | ||
| COPY ./dist/jacocoagent.jar . | ||
|
|
||
|
|
||
|
|
||
| #ENV TOOL="undefined" | ||
| #ENV RUN="0" | ||
|
|
||
| ENTRYPOINT \ | ||
| java \ | ||
| # unfortunately dumponexit is completely unreliable in Docker :( | ||
| # -javaagent:jacocoagent.jar=destfile=./jacoco/redis-sample__${TOOL}__${RUN}__jacoco.exec,append=false,dumponexit=true \ | ||
| -javaagent:jacocoagent.jar=output=tcpserver,address=*,port=6300,append=false,dumponexit=false \ | ||
| -jar redis-sample-sut.jar \ | ||
| --server.port=8080 --spring.data.redis.host=db --spring.data.redis.port=6379 --spring.data.redis.password=53cret --spring.autoconfigure.exclude=org.springframework.boot.security.autoconfigure.web.servlet.ServletWebSecurityAutoConfiguration --app.numberOfRatings=5000 --app.ratingStars=5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| services: | ||
| mitmproxy: | ||
| image: mitmproxy/mitmproxy:10.2.4 | ||
| user: "0:0" | ||
| environment: | ||
| MITM_LOG_DIR: /custom-logs | ||
| MITM_LOG_FILE: ${MITM_LOG_FILE:-minlog.csv} | ||
| command: > | ||
| mitmdump | ||
| --mode reverse:http://sut-redis-sample:8080 | ||
| --listen-host 0.0.0.0 | ||
| --listen-port 8080 | ||
| --set keep_host_header=true | ||
| -s /addons/minlog.py | ||
| volumes: | ||
| - ${HOST_LOG_DIR:-./mitm-logs}:/custom-logs | ||
| - ./addons:/addons:ro | ||
| ports: | ||
| - "${HOST_PORT:-8080}:8080" | ||
| depends_on: | ||
| - sut-redis-sample | ||
| sut-redis-sample: | ||
| build: | ||
| dockerfile: ./dockerfiles/redis-sample.dockerfile | ||
| context: .. | ||
| environment: | ||
| AUTH_PORT: ${AUTH_PORT:-8081} | ||
| ports: | ||
| - "${JACOCO_PORT:-6300}:6300" | ||
| db: | ||
| image: redis:7.4-alpine | ||
| command: redis-server --requirepass 53cret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| <modules> | ||
| <module>person-controller</module> | ||
| <module>redis-sample</module> | ||
| </modules> | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
|
|
||
| <modules> | ||
| <module>person-controller</module> | ||
| <module>redis-sample</module> | ||
| </modules> | ||
|
|
||
| </project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>evomaster-benchmark-jdk21-em-embedded-rest-redis-sample</artifactId> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <parent> | ||
| <groupId>org.evomaster</groupId> | ||
| <artifactId>evomaster-benchmark-jdk21-em-embedded-rest</artifactId> | ||
| <version>4.3.1-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <!-- Embedded mode puts the SUT and the driver on one classpath, and the SUT's parent pom does | ||
| not apply here. Without this import, transitive dependencies win instead (eg testcontainers' | ||
| slf4j-api 1.7 replaces the 2.x Spring Boot 4 needs). --> | ||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-dependencies</artifactId> | ||
| <version>4.1.0</version> | ||
| <type>pom</type> | ||
| <scope>import</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
|
|
||
| <dependencies> | ||
| <!-- The SUT as a library --> | ||
| <dependency> | ||
| <groupId>id.my.hendisantika</groupId> | ||
| <artifactId>spring-boot-redis-sample</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>testcontainers</artifactId> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>io.lettuce</groupId> | ||
| <artifactId>lettuce-core</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| </project> |
171 changes: 171 additions & 0 deletions
171
...rest/redis-sample/src/main/java/em/embedded/redis/sample/EmbeddedEvoMasterController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| package em.embedded.redis.sample; | ||
|
|
||
| import id.my.hendisantika.springbootredissample.SpringBootRedisSampleApplication; | ||
| import org.evomaster.client.java.controller.EmbeddedSutController; | ||
| import org.evomaster.client.java.controller.InstrumentedSutStarter; | ||
| import org.evomaster.client.java.controller.api.dto.auth.AuthenticationDto; | ||
| import org.evomaster.client.java.controller.api.dto.SutInfoDto; | ||
| import org.evomaster.client.java.sql.DbSpecification; | ||
| import org.evomaster.client.java.controller.problem.ProblemInfo; | ||
| import org.evomaster.client.java.controller.problem.RestProblem; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.context.ConfigurableApplicationContext; | ||
| import org.testcontainers.containers.GenericContainer; | ||
| import io.lettuce.core.RedisClient; | ||
| import io.lettuce.core.api.StatefulRedisConnection; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Class used to start/stop the SUT. This will be controller by the EvoMaster process | ||
| */ | ||
| public class EmbeddedEvoMasterController extends EmbeddedSutController { | ||
|
|
||
| private static final String REDIS_VERSION = "7.4-alpine"; | ||
|
|
||
| private static final int REDIS_PORT = 6379; | ||
|
|
||
| private static final String REDIS_PASSWORD = "53cret"; | ||
|
|
||
| private static final String SECURITY_EXCLUDE = | ||
| "org.springframework.boot.security.autoconfigure.web.servlet.ServletWebSecurityAutoConfiguration"; | ||
|
|
||
| private static final int NUMBER_OF_RATINGS = 5000; | ||
|
|
||
| private static final int RATING_STARS = 5; | ||
|
|
||
| private static final String CACHE_KEY_PATTERN = "id.my.hendisantika.springbootredissample.*Cache::*"; | ||
|
|
||
| private static final GenericContainer redis = new GenericContainer("redis:" + REDIS_VERSION) | ||
| .withCommand("redis-server", "--requirepass", REDIS_PASSWORD) | ||
| .withExposedPorts(REDIS_PORT); | ||
|
|
||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| int port = 40100; | ||
| if (args.length > 0) { | ||
| port = Integer.parseInt(args[0]); | ||
| } | ||
|
|
||
| EmbeddedEvoMasterController controller = new EmbeddedEvoMasterController(port); | ||
| InstrumentedSutStarter starter = new InstrumentedSutStarter(controller); | ||
|
|
||
| starter.start(); | ||
| } | ||
|
|
||
|
|
||
| private ConfigurableApplicationContext ctx; | ||
|
|
||
| private RedisClient redisClient; | ||
|
|
||
| private StatefulRedisConnection<String, String> redisConnection; | ||
|
|
||
| public EmbeddedEvoMasterController() { | ||
| this(0); | ||
| } | ||
|
|
||
| public EmbeddedEvoMasterController(int port) { | ||
| setControllerPort(port); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public String startSut() { | ||
|
|
||
| redis.start(); | ||
| redisClient = RedisClient.create("redis://:" + REDIS_PASSWORD + "@" | ||
| + redis.getHost() + ":" + redis.getMappedPort(REDIS_PORT)); | ||
| redisConnection = redisClient.connect(); | ||
|
|
||
| ctx = SpringApplication.run(SpringBootRedisSampleApplication.class, new String[]{ | ||
| "--server.port=0", | ||
| "--spring.data.redis.host=" + redis.getHost(), | ||
| "--spring.data.redis.port=" + redis.getMappedPort(REDIS_PORT), | ||
| "--spring.data.redis.password=" + REDIS_PASSWORD, | ||
| "--spring.autoconfigure.exclude=" + SECURITY_EXCLUDE, | ||
| "--app.numberOfRatings=" + NUMBER_OF_RATINGS, | ||
| "--app.ratingStars=" + RATING_STARS | ||
| }); | ||
|
|
||
| return "http://localhost:" + getSutPort(); | ||
| } | ||
|
|
||
| protected int getSutPort() { | ||
| return (Integer) ((Map) ctx.getEnvironment() | ||
| .getPropertySources().get("server.ports").getSource()) | ||
| .get("local.server.port"); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public boolean isSutRunning() { | ||
| return ctx != null && ctx.isRunning(); | ||
| } | ||
|
|
||
| @Override | ||
| public void stopSut() { | ||
|
|
||
| if (ctx != null) { | ||
| ctx.stop(); | ||
| ctx.close(); | ||
| ctx = null; | ||
| } | ||
|
|
||
| if (redisConnection != null) { | ||
| redisConnection.close(); | ||
| redisClient.shutdown(); | ||
| redisConnection = null; | ||
| redisClient = null; | ||
| } | ||
|
|
||
| redis.stop(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPackagePrefixesToCover() { | ||
| return "id.my.hendisantika.springbootredissample."; | ||
| } | ||
|
|
||
| /* | ||
| Only the Spring Cache entries accumulate: the API is read-only, and the seeded data is | ||
| written once at startup by runners guarded on an empty repository, so it must survive. | ||
| */ | ||
| @Override | ||
| public void resetStateOfSUT() { | ||
| if (redisConnection == null) { | ||
| return; | ||
| } | ||
| List<String> keys = redisConnection.sync().keys(CACHE_KEY_PATTERN); | ||
| if (!keys.isEmpty()) { | ||
| redisConnection.sync().del(keys.toArray(new String[0])); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public List<DbSpecification> getDbSpecifications() { | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public List<AuthenticationDto> getInfoForAuthentication() { | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public ProblemInfo getProblemInfo() { | ||
| return new RestProblem( | ||
| "http://localhost:" + getSutPort() + "/v3/api-docs", | ||
| null | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public SutInfoDto.OutputFormat getPreferredOutputFormat() { | ||
| return SutInfoDto.OutputFormat.JAVA_JUNIT_5; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| <modules> | ||
| <module>person-controller</module> | ||
| <module>redis-sample</module> | ||
| </modules> | ||
|
|
||
| </project> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how are we resetting the state of Redis after each test execution? for SQL it is automated inside EvoMaster, but i don't think it is the case for any of the other DBs