Skip to content

Commit b11dd93

Browse files
committed
updates
1 parent 803db8d commit b11dd93

5 files changed

Lines changed: 70 additions & 2 deletions

File tree

jdk_21_maven/cs/rest/redis-sample/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
<scope>test</scope>
8585
</dependency>
8686
<!-- MODIFIED-->
87-
<!-- EvoMaster needs an OpenAPI schema; the SUT had none. -->
8887
<dependency>
8988
<groupId>org.springdoc</groupId>
9089
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
@@ -116,7 +115,7 @@
116115
<artifactId>spring-boot-maven-plugin</artifactId>
117116
<configuration>
118117
<!-- MODIFIED-->
119-
<!-- EMB expects a single self-contained "redis-sample-sut.jar". The classifier keeps
118+
<!-- WFD expects a single self-contained "redis-sample-sut.jar". The classifier keeps
120119
the plain jar as the main artifact, which the embedded driver depends on. -->
121120
<finalName>redis-sample</finalName>
122121
<classifier>sut</classifier>

jdk_21_maven/em/embedded/rest/redis-sample/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
<artifactId>testcontainers</artifactId>
4242
<scope>compile</scope>
4343
</dependency>
44+
45+
<dependency>
46+
<groupId>io.lettuce</groupId>
47+
<artifactId>lettuce-core</artifactId>
48+
</dependency>
4449
</dependencies>
4550

4651
</project>

jdk_21_maven/em/embedded/rest/redis-sample/src/main/java/em/embedded/redis/sample/EmbeddedEvoMasterController.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.springframework.boot.SpringApplication;
1212
import org.springframework.context.ConfigurableApplicationContext;
1313
import org.testcontainers.containers.GenericContainer;
14+
import io.lettuce.core.RedisClient;
15+
import io.lettuce.core.api.StatefulRedisConnection;
1416

1517
import java.util.List;
1618
import java.util.Map;
@@ -33,6 +35,8 @@ public class EmbeddedEvoMasterController extends EmbeddedSutController {
3335

3436
private static final int RATING_STARS = 5;
3537

38+
private static final String CACHE_KEY_PATTERN = "id.my.hendisantika.springbootredissample.*Cache::*";
39+
3640
private static final GenericContainer redis = new GenericContainer("redis:" + REDIS_VERSION)
3741
.withCommand("redis-server", "--requirepass", REDIS_PASSWORD)
3842
.withExposedPorts(REDIS_PORT);
@@ -54,6 +58,10 @@ public static void main(String[] args) {
5458

5559
private ConfigurableApplicationContext ctx;
5660

61+
private RedisClient redisClient;
62+
63+
private StatefulRedisConnection<String, String> redisConnection;
64+
5765
public EmbeddedEvoMasterController() {
5866
this(0);
5967
}
@@ -67,6 +75,9 @@ public EmbeddedEvoMasterController(int port) {
6775
public String startSut() {
6876

6977
redis.start();
78+
redisClient = RedisClient.create("redis://:" + REDIS_PASSWORD + "@"
79+
+ redis.getHost() + ":" + redis.getMappedPort(REDIS_PORT));
80+
redisConnection = redisClient.connect();
7081

7182
ctx = SpringApplication.run(SpringBootRedisSampleApplication.class, new String[]{
7283
"--server.port=0",
@@ -102,6 +113,13 @@ public void stopSut() {
102113
ctx = null;
103114
}
104115

116+
if (redisConnection != null) {
117+
redisConnection.close();
118+
redisClient.shutdown();
119+
redisConnection = null;
120+
redisClient = null;
121+
}
122+
105123
redis.stop();
106124
}
107125

@@ -110,8 +128,19 @@ public String getPackagePrefixesToCover() {
110128
return "id.my.hendisantika.springbootredissample.";
111129
}
112130

131+
/*
132+
Only the Spring Cache entries accumulate: the API is read-only, and the seeded data is
133+
written once at startup by runners guarded on an empty repository, so it must survive.
134+
*/
113135
@Override
114136
public void resetStateOfSUT() {
137+
if (redisConnection == null) {
138+
return;
139+
}
140+
List<String> keys = redisConnection.sync().keys(CACHE_KEY_PATTERN);
141+
if (!keys.isEmpty()) {
142+
redisConnection.sync().del(keys.toArray(new String[0]));
143+
}
115144
}
116145

117146

jdk_21_maven/em/external/rest/redis-sample/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
<artifactId>testcontainers</artifactId>
2222
<scope>compile</scope>
2323
</dependency>
24+
25+
<dependency>
26+
<groupId>io.lettuce</groupId>
27+
<artifactId>lettuce-core</artifactId>
28+
<version>7.5.2.RELEASE</version>
29+
</dependency>
2430
</dependencies>
2531

2632

jdk_21_maven/em/external/rest/redis-sample/src/main/java/em/external/redis/sample/ExternalEvoMasterController.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.evomaster.client.java.controller.problem.ProblemInfo;
1010
import org.evomaster.client.java.controller.problem.RestProblem;
1111
import org.testcontainers.containers.GenericContainer;
12+
import io.lettuce.core.RedisClient;
13+
import io.lettuce.core.api.StatefulRedisConnection;
1214

1315
import java.util.List;
1416

@@ -31,6 +33,8 @@ public class ExternalEvoMasterController extends ExternalSutController {
3133

3234
private static final int RATING_STARS = 5;
3335

36+
private static final String CACHE_KEY_PATTERN = "id.my.hendisantika.springbootredissample.*Cache::*";
37+
3438
private static final GenericContainer redis = new GenericContainer("redis:" + REDIS_VERSION)
3539
.withCommand("redis-server", "--requirepass", REDIS_PASSWORD)
3640
.withExposedPorts(REDIS_PORT);
@@ -81,6 +85,10 @@ public static void main(String[] args) {
8185

8286
private String jarLocation;
8387

88+
private RedisClient redisClient;
89+
90+
private StatefulRedisConnection<String, String> redisConnection;
91+
8492
public ExternalEvoMasterController() {
8593
this(DEFAULT_CONTROLLER_PORT, "../target/redis-sample-sut.jar", DEFAULT_SUT_PORT, 120, "java");
8694
}
@@ -146,6 +154,9 @@ public long getMaxAwaitForInitializationInSeconds() {
146154
@Override
147155
public void preStart() {
148156
redis.start();
157+
redisClient = RedisClient.create("redis://:" + REDIS_PASSWORD + "@"
158+
+ redis.getHost() + ":" + redis.getMappedPort(REDIS_PORT));
159+
redisConnection = redisClient.connect();
149160
}
150161

151162
@Override
@@ -158,6 +169,13 @@ public void preStop() {
158169

159170
@Override
160171
public void postStop() {
172+
if (redisConnection != null) {
173+
redisConnection.close();
174+
redisClient.shutdown();
175+
redisConnection = null;
176+
redisClient = null;
177+
}
178+
161179
redis.stop();
162180
}
163181

@@ -184,8 +202,19 @@ public List<AuthenticationDto> getInfoForAuthentication() {
184202
return null;
185203
}
186204

205+
/*
206+
Only the Spring Cache entries accumulate: the API is read-only, and the seeded data is
207+
written once at startup by runners guarded on an empty repository, so it must survive.
208+
*/
187209
@Override
188210
public void resetStateOfSUT() {
211+
if (redisConnection == null) {
212+
return;
213+
}
214+
List<String> keys = redisConnection.sync().keys(CACHE_KEY_PATTERN);
215+
if (!keys.isEmpty()) {
216+
redisConnection.sync().del(keys.toArray(new String[0]));
217+
}
189218
}
190219

191220
@Override

0 commit comments

Comments
 (0)