Skip to content

Commit e70cfe9

Browse files
authored
Merge 47c00aa into c33bdf7
2 parents c33bdf7 + 47c00aa commit e70cfe9

File tree

7 files changed

+90
-7
lines changed

7 files changed

+90
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ stop:
442442

443443
test: compile-module start
444444
sleep 2
445-
mvn -Dtest=${SKIP_SSL}${TEST} clean compile test
445+
mvn -Dredisversion=${REDIS_VERSION} -Dtest=${SKIP_SSL}${TEST} clean compile test
446446
make stop
447447

448448
package: start

pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,16 @@
7272
<artifactId>gson</artifactId>
7373
<version>2.10.1</version>
7474
</dependency>
75-
75+
<dependency>
76+
<groupId>org.junit.jupiter</groupId>
77+
<artifactId>junit-jupiter</artifactId>
78+
<version>5.9.2</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.junit.platform</groupId>
82+
<artifactId>junit-platform-launcher</artifactId>
83+
<version>1.9.2</version>
84+
</dependency>
7685
<dependency>
7786
<groupId>junit</groupId>
7887
<artifactId>junit</artifactId>

src/test/java/redis/clients/jedis/commands/jedis/JedisCommandsTestBase.java

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

3-
import org.junit.After;
4-
import org.junit.Before;
3+
import org.junit.jupiter.api.BeforeEach;
4+
import org.junit.jupiter.api.AfterEach;
55

66
import redis.clients.jedis.DefaultJedisClientConfig;
77
import redis.clients.jedis.HostAndPort;
@@ -19,15 +19,15 @@ public JedisCommandsTestBase() {
1919
super();
2020
}
2121

22-
@Before
22+
@BeforeEach
2323
public void setUp() throws Exception {
2424
// jedis = new Jedis(hnp, DefaultJedisClientConfig.builder().timeoutMillis(500).password("foobared").build());
2525
jedis = new Jedis(hnp, DefaultJedisClientConfig.builder()
2626
.protocol(RedisProtocolUtil.getRedisProtocol()).timeoutMillis(500).password("foobared").build());
2727
jedis.flushAll();
2828
}
2929

30-
@After
30+
@AfterEach
3131
public void tearDown() throws Exception {
3232
jedis.close();
3333
}

src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import java.util.List;
2020
import java.util.Set;
2121

22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
23+
import redis.clients.jedis.versiontag.EnabledOnRedis;
24+
import redis.clients.jedis.versiontag.RedisType;
2325

2426
import redis.clients.jedis.params.ScanParams;
2527
import redis.clients.jedis.resps.ScanResult;
@@ -283,6 +285,7 @@ public void sismember() {
283285
}
284286

285287
@Test
288+
@EnabledOnRedis({RedisType.REDIS_UNSTABLE, RedisType.REDIS_7})
286289
public void smismember() {
287290
jedis.sadd("foo", "a", "b");
288291

@@ -323,6 +326,7 @@ public void sinter() {
323326
}
324327

325328
@Test
329+
@EnabledOnRedis({RedisType.REDIS_UNSTABLE, RedisType.REDIS_7})
326330
public void sinterstore() {
327331
jedis.sadd("foo", "a");
328332
jedis.sadd("foo", "b");
@@ -356,6 +360,7 @@ public void sinterstore() {
356360
}
357361

358362
@Test
363+
@EnabledOnRedis({RedisType.REDIS_UNSTABLE, RedisType.REDIS_7})
359364
public void sintercard() {
360365
jedis.sadd("foo", "a");
361366
jedis.sadd("foo", "b");
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package redis.clients.jedis.versiontag;
2+
3+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
4+
import org.junit.jupiter.api.extension.ExecutionCondition;
5+
import org.junit.jupiter.api.extension.ExtensionContext;
6+
import org.junit.platform.commons.util.AnnotationUtils;
7+
8+
import java.util.Arrays;
9+
import java.util.List;
10+
import java.util.Optional;
11+
12+
import static java.lang.System.getenv;
13+
14+
public class CustomExecutionCondition implements ExecutionCondition {
15+
16+
@Override
17+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
18+
Optional<EnabledOnRedis> optional = AnnotationUtils.findAnnotation(context.getElement(),
19+
EnabledOnRedis.class);
20+
21+
if (optional.isPresent()) {
22+
List<RedisType> typeList = Arrays.asList(optional.get().value());
23+
String type = System.getProperty("redisversion");
24+
if (type == null || type.isEmpty()) type = "REDIS_UNSTABLE";
25+
26+
RedisType Redis_type = null;
27+
try {
28+
Redis_type = Enum.valueOf(RedisType.class, type.toUpperCase());
29+
} catch (IllegalArgumentException e) {
30+
System.out.println(e.getMessage());
31+
System.out.println("Supported engines are: ");
32+
for (RedisType et : RedisType.values()) {
33+
System.out.println(et.name());
34+
}
35+
System.exit(1);
36+
}
37+
38+
if (typeList.contains(Redis_type)) {
39+
return ConditionEvaluationResult.enabled("Test is enabled for engine " + Redis_type.name());
40+
} else {
41+
return ConditionEvaluationResult.disabled("Test is disabled for engine " + Redis_type.name());
42+
}
43+
}
44+
return ConditionEvaluationResult.enabled("@EnabledOnEngine is not present");
45+
}
46+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package redis.clients.jedis.versiontag;
2+
3+
import org.junit.jupiter.api.extension.ExtendWith;
4+
5+
import java.lang.annotation.*;
6+
7+
@Target({ ElementType.TYPE, ElementType.METHOD })
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Inherited
10+
@Documented
11+
@ExtendWith(CustomExecutionCondition.class)
12+
public @interface EnabledOnRedis {
13+
RedisType[] value();
14+
}
15+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package redis.clients.jedis.versiontag;
2+
3+
public enum RedisType {
4+
REDIS_6,
5+
REDIS_7,
6+
REDIS_UNSTABLE
7+
}
8+

0 commit comments

Comments
 (0)