Skip to content

Commit 56a774b

Browse files
committed
Dedicated profile for running Scenario tests
to run only scenario tests mvn -Pscenario-tests clean verify
1 parent 14356c4 commit 56a774b

File tree

7 files changed

+134
-88
lines changed

7 files changed

+134
-88
lines changed

pom.xml

Lines changed: 80 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
<JVM_OPTS></JVM_OPTS>
6565
<!-- Default excluded groups for tests - can be overridden from command line -->
6666
<excludedGroupsForUnitTests>integration,scenario</excludedGroupsForUnitTests>
67+
<skipUnitTests>false</skipUnitTests>
68+
<skipIntegrationTests>false</skipIntegrationTests>
69+
<skipScenarioTests>true</skipScenarioTests>
6770
</properties>
6871

6972
<dependencyManagement>
@@ -287,6 +290,17 @@
287290
<destFile>${project.build.directory}/jacoco-it-suffix.exec</destFile>
288291
</configuration>
289292
</execution>
293+
<!-- Collect coverage for scenario tests -->
294+
<execution>
295+
<id>prepare-agent-scenario</id>
296+
<goals>
297+
<goal>prepare-agent</goal>
298+
</goals>
299+
<configuration>
300+
<propertyName>failsafeScenarioArgLine</propertyName>
301+
<destFile>${project.build.directory}/jacoco-scenario.exec</destFile>
302+
</configuration>
303+
</execution>
290304
<!-- Merge all coverage data after all integration tests -->
291305
<execution>
292306
<id>merge-coverage</id>
@@ -302,6 +316,7 @@
302316
<include>jacoco-ut.exec</include>
303317
<include>jacoco-it-tagged.exec</include>
304318
<include>jacoco-it-suffix.exec</include>
319+
<include>jacoco-scenario.exec</include>
305320
</includes>
306321
</fileSet>
307322
</fileSets>
@@ -333,6 +348,7 @@
333348
<artifactId>maven-surefire-plugin</artifactId>
334349
<version>${maven.surefire.version}</version>
335350
<configuration>
351+
<skipTests>${skipUnitTests}</skipTests>
336352
<argLine>@{argLine} ${JVM_OPTS}</argLine>
337353
<systemPropertyVariables>
338354
<redis-hosts>${redis-hosts}</redis-hosts>
@@ -358,13 +374,13 @@
358374
</systemPropertyVariables>
359375
<summaryFile>${project.build.directory}/failsafe-summary.xml</summaryFile>
360376
<!-- Default includes used when invoking failsafe goals directly (e.g., mvn failsafe:integration-test) -->
377+
<excludedGroups>scenario</excludedGroups>
361378
<includes>
362379
<include>**/*IntegrationTest.java</include>
363380
<include>**/*IntegrationTests.java</include>
364381
</includes>
365382
<excludes>
366383
<exclude>**/examples/*.java</exclude>
367-
<exclude>**/scenario/*Test.java</exclude>
368384
<!-- Exclude unit tests -->
369385
<exclude>**/mocked/*.java</exclude>
370386
</excludes>
@@ -377,8 +393,10 @@
377393
<goal>integration-test</goal>
378394
</goals>
379395
<configuration>
396+
<skip>${skipIntegrationTests}</skip>
380397
<argLine>@{failsafeTaggedArgLine} ${JVM_OPTS}</argLine>
381398
<groups>integration</groups>
399+
<excludedGroups>scenario,unit</excludedGroups>
382400
<includes>
383401
<include>**/*Test.java</include>
384402
<include>**/*Tests.java</include>
@@ -392,14 +410,37 @@
392410
<goal>integration-test</goal>
393411
</goals>
394412
<configuration>
413+
<skip>${skipIntegrationTests}</skip>
395414
<argLine>@{failsafeSuffixArgLine} ${JVM_OPTS}</argLine>
396-
415+
<excludedGroups>scenario,unit</excludedGroups>
397416
<includes>
417+
<include>**/*IT.java</include>
418+
<include>**/*ITs.java</include>
398419
<include>**/*IntegrationTest.java</include>
399420
<include>**/*IntegrationTests.java</include>
400421
</includes>
401422
</configuration>
402423
</execution>
424+
<!-- Run all tests tagged with @Tag("scenario") regardless of file name -->
425+
<execution>
426+
<id>scenario-tests</id>
427+
<goals>
428+
<goal>integration-test</goal>
429+
</goals>
430+
<configuration>
431+
<skip>${skipScenarioTests}</skip>
432+
<argLine>@{failsafeScenarioArgLine} ${JVM_OPTS}</argLine>
433+
<groups>scenario</groups>
434+
<excludedGroups>integration,unit</excludedGroups>
435+
<includes>
436+
<include>**/*IT.java</include>
437+
<include>**/*ITs.java</include>
438+
</includes>
439+
<excludes>
440+
<!-- ensure plugin level excludes are overridden -->
441+
</excludes>
442+
</configuration>
443+
</execution>
403444
<!-- Verify phase should run once after both IT executions -->
404445
<execution>
405446
<id>it-verify</id>
@@ -574,35 +615,43 @@
574615
</plugins>
575616
</build>
576617
</profile>
577-
<profile>
578-
<id>tests-with-params</id>
579-
<activation>
580-
<property>
581-
<name>with-param-names</name>
582-
<value>true</value>
583-
</property>
584-
</activation>
585-
<build>
586-
<plugins>
587-
<plugin>
588-
<artifactId>maven-compiler-plugin</artifactId>
589-
<version>3.14.0</version>
590-
<configuration>
591-
<source>1.8</source>
592-
<target>1.8</target>
593-
<parameters>true</parameters>
594-
</configuration>
595-
</plugin>
596-
<plugin>
597-
<artifactId>maven-surefire-plugin</artifactId>
598-
<version>${maven.surefire.version}</version>
599-
<configuration>
600-
<argLine>@{argLine} ${JVM_OPTS}</argLine>
601-
</configuration>
602-
</plugin>
603-
</plugins>
604-
</build>
605-
</profile>
618+
<profile>
619+
<id>tests-with-params</id>
620+
<activation>
621+
<property>
622+
<name>with-param-names</name>
623+
<value>true</value>
624+
</property>
625+
</activation>
626+
<build>
627+
<plugins>
628+
<plugin>
629+
<artifactId>maven-compiler-plugin</artifactId>
630+
<version>3.14.0</version>
631+
<configuration>
632+
<source>1.8</source>
633+
<target>1.8</target>
634+
<parameters>true</parameters>
635+
</configuration>
636+
</plugin>
637+
<plugin>
638+
<artifactId>maven-surefire-plugin</artifactId>
639+
<version>${maven.surefire.version}</version>
640+
<configuration>
641+
<argLine>@{argLine} ${JVM_OPTS}</argLine>
642+
</configuration>
643+
</plugin>
644+
</plugins>
645+
</build>
646+
</profile>
647+
<profile>
648+
<id>scenario-tests</id>
649+
<properties>
650+
<skipUnitTests>true</skipUnitTests>
651+
<skipIntegrationTests>true</skipIntegrationTests>
652+
<skipScenarioTests>false</skipScenarioTests>
653+
</properties>
654+
</profile>
606655

607656
</profiles>
608657
</project>

src/test/java/redis/clients/jedis/mcf/ActiveActiveLocalFailoverTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import eu.rekawek.toxiproxy.model.Toxic;
1818
import redis.clients.jedis.*;
1919
import redis.clients.jedis.MultiDbConfig.DatabaseConfig;
20-
import redis.clients.jedis.scenario.ActiveActiveFailoverTest;
2120
import redis.clients.jedis.scenario.MultiThreadedFakeApp;
2221
import redis.clients.jedis.scenario.RecommendedSettings;
2322
import redis.clients.jedis.scenario.FaultInjectionClient.TriggerActionResponse;
@@ -41,7 +40,7 @@
4140

4241
@Tags({ @Tag("failover"), @Tag("integration") })
4342
public class ActiveActiveLocalFailoverTest {
44-
private static final Logger log = LoggerFactory.getLogger(ActiveActiveFailoverTest.class);
43+
private static final Logger log = LoggerFactory.getLogger(ActiveActiveLocalFailoverTest.class);
4544

4645
private static final EndpointConfig endpoint1 = HostAndPorts.getRedisEndpoint("redis-failover-1");
4746
private static final EndpointConfig endpoint2 = HostAndPorts.getRedisEndpoint("redis-failover-2");

src/test/java/redis/clients/jedis/mcf/RedisRestAPIIntegrationTest.java renamed to src/test/java/redis/clients/jedis/mcf/RedisRestAPIIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import redis.clients.jedis.scenario.RestEndpointUtil;
3131

3232
@Tags({ @Tag("failover"), @Tag("scenario") })
33-
public class RedisRestAPIIntegrationTest {
33+
public class RedisRestAPIIT {
3434
public static class SSLBypass {
3535
private static SSLSocketFactory originalSSLSocketFactory;
3636
private static HostnameVerifier originalHostnameVerifier;
@@ -79,7 +79,7 @@ public static void restoreSSLVerification() {
7979
private static EndpointConfig endpointConfig;
8080
private static Endpoint restAPIEndpoint;
8181
private static Supplier<RedisCredentials> credentialsSupplier;
82-
private static final Logger log = LoggerFactory.getLogger(RedisRestAPIIntegrationTest.class);
82+
private static final Logger log = LoggerFactory.getLogger(RedisRestAPIIT.class);
8383

8484
@BeforeAll
8585
public static void beforeClass() {

src/test/java/redis/clients/jedis/scenario/ActiveActiveFailoverTest.java renamed to src/test/java/redis/clients/jedis/scenario/ActiveActiveFailoverIT.java

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package redis.clients.jedis.scenario;
22

3-
import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig;
4-
53
import org.junit.jupiter.api.BeforeAll;
64
import org.junit.jupiter.api.Tag;
75
import org.junit.jupiter.api.Tags;
@@ -34,8 +32,8 @@
3432
import static redis.clients.jedis.Protocol.DEFAULT_TIMEOUT;
3533

3634
@Tags({ @Tag("failover"), @Tag("scenario") })
37-
public class ActiveActiveFailoverTest {
38-
private static final Logger log = LoggerFactory.getLogger(ActiveActiveFailoverTest.class);
35+
public class ActiveActiveFailoverIT {
36+
private static final Logger log = LoggerFactory.getLogger(ActiveActiveFailoverIT.class);
3937
private static final int NUM_OF_THREADS = 18;
4038
private static final int SOCKET_TIMEOUT_MS = DEFAULT_TIMEOUT;
4139
private static final int CONNECTION_TIMEOUT_MS = DEFAULT_TIMEOUT;
@@ -48,7 +46,7 @@ public class ActiveActiveFailoverTest {
4846
@BeforeAll
4947
public static void beforeClass() {
5048
try {
51-
ActiveActiveFailoverTest.endpoint = HostAndPorts.getRedisEndpoint("re-active-active");
49+
ActiveActiveFailoverIT.endpoint = HostAndPorts.getRedisEndpoint("re-active-active");
5250
} catch (IllegalArgumentException e) {
5351
log.warn("Skipping test because no Redis endpoint is configured");
5452
assumeTrue(false);
@@ -59,29 +57,22 @@ public static void beforeClass() {
5957
public void testFailover() {
6058

6159
JedisClientConfig config = endpoint.getClientConfigBuilder()
62-
.socketTimeoutMillis(SOCKET_TIMEOUT_MS)
63-
.connectionTimeoutMillis(CONNECTION_TIMEOUT_MS).build();
60+
.socketTimeoutMillis(SOCKET_TIMEOUT_MS).connectionTimeoutMillis(CONNECTION_TIMEOUT_MS)
61+
.build();
6462

6563
DatabaseConfig primary = DatabaseConfig.builder(endpoint.getHostAndPort(0), config)
66-
.connectionPoolConfig(RecommendedSettings.poolConfig).weight(1.0f).build();
64+
.connectionPoolConfig(RecommendedSettings.poolConfig).weight(1.0f).build();
6765

6866
DatabaseConfig secondary = DatabaseConfig.builder(endpoint.getHostAndPort(1), config)
69-
.connectionPoolConfig(RecommendedSettings.poolConfig).weight(0.5f).build();
70-
71-
MultiDbConfig multiConfig = MultiDbConfig.builder()
72-
.endpoint(primary)
73-
.endpoint(secondary)
74-
.circuitBreakerSlidingWindowSize(1) // SLIDING WINDOW SIZE IN SECONDS
75-
.circuitBreakerFailureRateThreshold(10.0f) // percentage of failures to trigger circuit breaker
76-
.failbackSupported(true)
77-
.failbackCheckInterval(1000)
78-
.gracePeriod(2000)
79-
.retryWaitDuration(10)
80-
.retryMaxAttempts(1)
81-
.retryWaitDurationExponentialBackoffMultiplier(1)
82-
.fastFailover(true)
83-
.retryOnFailover(false)
84-
.build();
67+
.connectionPoolConfig(RecommendedSettings.poolConfig).weight(0.5f).build();
68+
69+
MultiDbConfig multiConfig = MultiDbConfig.builder().endpoint(primary).endpoint(secondary)
70+
.circuitBreakerSlidingWindowSize(1) // SLIDING WINDOW SIZE IN SECONDS
71+
.circuitBreakerFailureRateThreshold(10.0f) // percentage of failures to trigger circuit
72+
// breaker
73+
.failbackSupported(true).failbackCheckInterval(1000).gracePeriod(2000).retryWaitDuration(10)
74+
.retryMaxAttempts(1).retryWaitDurationExponentialBackoffMultiplier(1).fastFailover(true)
75+
.retryOnFailover(false).build();
8576
class FailoverReporter implements Consumer<DatabaseSwitchEvent> {
8677

8778
String currentClusterName = "not set";
@@ -101,7 +92,8 @@ public String getCurrentClusterName() {
10192
@Override
10293
public void accept(DatabaseSwitchEvent e) {
10394
this.currentClusterName = e.getDatabaseName();
104-
log.info("\n\n====FailoverEvent=== \nJedis failover to cluster: {}\n====FailoverEvent===\n\n",
95+
log.info(
96+
"\n\n====FailoverEvent=== \nJedis failover to cluster: {}\n====FailoverEvent===\n\n",
10597
e.getDatabaseName());
10698

10799
if (failoverHappened) {
@@ -116,10 +108,8 @@ public void accept(DatabaseSwitchEvent e) {
116108

117109
FailoverReporter reporter = new FailoverReporter();
118110

119-
MultiDbClient client = MultiDbClient.builder()
120-
.multiDbConfig(multiConfig)
121-
.databaseSwitchListener(reporter)
122-
.build();
111+
MultiDbClient client = MultiDbClient.builder().multiDbConfig(multiConfig)
112+
.databaseSwitchListener(reporter).build();
123113

124114
AtomicLong executedCommands = new AtomicLong(0);
125115
AtomicLong retryingThreadsCounter = new AtomicLong(0);
@@ -160,7 +150,8 @@ public void accept(DatabaseSwitchEvent e) {
160150

161151
if (attempt == 0) {
162152
long failedThreads = retryingThreadsCounter.incrementAndGet();
163-
log.warn("Thread {} failed to execute command. Failed threads: {}", threadId, failedThreads);
153+
log.warn("Thread {} failed to execute command. Failed threads: {}", threadId,
154+
failedThreads);
164155
}
165156
try {
166157
Thread.sleep(retryingDelay);
@@ -215,8 +206,10 @@ public void accept(DatabaseSwitchEvent e) {
215206
await().atMost(Duration.ofSeconds(1)).until(() -> pool1.getNumActive() == 0);
216207
await().atMost(Duration.ofSeconds(1)).until(() -> pool2.getNumActive() == 0);
217208

218-
log.info("Connection pool {}: active: {}, idle: {}", endpoint.getHostAndPort(0), pool1.getNumActive(), pool1.getNumIdle());
219-
log.info("Connection pool {}: active: {}, idle: {}", endpoint.getHostAndPort(1), pool2.getNumActive(), pool2.getNumIdle());
209+
log.info("Connection pool {}: active: {}, idle: {}", endpoint.getHostAndPort(0),
210+
pool1.getNumActive(), pool1.getNumIdle());
211+
log.info("Connection pool {}: active: {}, idle: {}", endpoint.getHostAndPort(1),
212+
pool2.getNumActive(), pool2.getNumIdle());
220213
log.info("Failover happened at: {}", reporter.failoverAt);
221214
log.info("Failback happened at: {}", reporter.failbackAt);
222215
log.info("Last failed command at: {}", lastFailedCommandAt.get());
@@ -228,7 +221,8 @@ public void accept(DatabaseSwitchEvent e) {
228221
assertTrue(fakeApp.capturedExceptions().isEmpty());
229222
assertTrue(reporter.failoverHappened);
230223
assertTrue(reporter.failbackHappened);
231-
assertThat( Duration.between(reporter.failoverAt, reporter.failbackAt).getSeconds(), greaterThanOrEqualTo(NETWORK_FAILURE_INTERVAL));
224+
assertThat(Duration.between(reporter.failoverAt, reporter.failbackAt).getSeconds(),
225+
greaterThanOrEqualTo(NETWORK_FAILURE_INTERVAL));
232226

233227
client.close();
234228
}

src/test/java/redis/clients/jedis/scenario/ClusterTopologyRefreshTest.java renamed to src/test/java/redis/clients/jedis/scenario/ClusterTopologyRefreshIT.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package redis.clients.jedis.scenario;
22

33
import org.junit.jupiter.api.BeforeAll;
4+
import org.junit.jupiter.api.Tags;
45
import org.junit.jupiter.api.Test;
56
import org.junit.jupiter.api.Tag;
67
import org.slf4j.Logger;
@@ -20,10 +21,10 @@
2021
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2122
import static org.mockito.Mockito.*;
2223

23-
@Tag("scenario")
24-
public class ClusterTopologyRefreshTest {
24+
@Tags({ @Tag("scenario") })
25+
public class ClusterTopologyRefreshIT {
2526

26-
private static final Logger log = LoggerFactory.getLogger(ClusterTopologyRefreshTest.class);
27+
private static final Logger log = LoggerFactory.getLogger(ClusterTopologyRefreshIT.class);
2728

2829
private static EndpointConfig endpoint;
2930

@@ -32,7 +33,8 @@ public class ClusterTopologyRefreshTest {
3233
@BeforeAll
3334
public static void beforeClass() {
3435
try {
35-
ClusterTopologyRefreshTest.endpoint = HostAndPorts.getRedisEndpoint("re-single-shard-oss-cluster");
36+
ClusterTopologyRefreshIT.endpoint = HostAndPorts
37+
.getRedisEndpoint("re-single-shard-oss-cluster");
3638
} catch (IllegalArgumentException e) {
3739
log.warn("Skipping test because no Redis endpoint is configured");
3840
assumeTrue(false);
@@ -48,14 +50,14 @@ public void testWithPool() {
4850
.socketTimeoutMillis(RecommendedSettings.DEFAULT_TIMEOUT_MS)
4951
.connectionTimeoutMillis(RecommendedSettings.DEFAULT_TIMEOUT_MS).build();
5052

51-
52-
ClusterConnectionProvider provider = new ClusterConnectionProvider(jedisClusterNode, config, RecommendedSettings.poolConfig);
53+
ClusterConnectionProvider provider = new ClusterConnectionProvider(jedisClusterNode, config,
54+
RecommendedSettings.poolConfig);
5355
ClusterConnectionProvider spyProvider = spy(provider);
5456

55-
try (JedisCluster client = new JedisCluster(spyProvider,
56-
RecommendedSettings.MAX_RETRIES, RecommendedSettings.MAX_TOTAL_RETRIES_DURATION)) {
57-
assertEquals(1,
58-
client.getClusterNodes().size(),"Was this BDB used to run this test before?");
57+
try (JedisCluster client = new JedisCluster(spyProvider, RecommendedSettings.MAX_RETRIES,
58+
RecommendedSettings.MAX_TOTAL_RETRIES_DURATION)) {
59+
assertEquals(1, client.getClusterNodes().size(),
60+
"Was this BDB used to run this test before?");
5961

6062
AtomicLong commandsExecuted = new AtomicLong();
6163

0 commit comments

Comments
 (0)