From 04b272782417b4412ed52743923a89191fea9833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=9E=E8=B7=83?= Date: Tue, 20 Jun 2023 16:43:25 +0800 Subject: [PATCH 1/4] A demo of redis version tag proposal --- Makefile | 2 +- pom.xml | 11 ++++- .../jedis/commands/jedis/SetCommandsTest.java | 6 ++- .../versiontag/CustomExecutionCondition.java | 46 +++++++++++++++++++ .../jedis/versiontag/EnabledOnRedis.java | 15 ++++++ .../clients/jedis/versiontag/RedisType.java | 8 ++++ 6 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 src/test/java/redis/clients/jedis/versiontag/CustomExecutionCondition.java create mode 100644 src/test/java/redis/clients/jedis/versiontag/EnabledOnRedis.java create mode 100644 src/test/java/redis/clients/jedis/versiontag/RedisType.java diff --git a/Makefile b/Makefile index 2987ad80dd..9baef62196 100644 --- a/Makefile +++ b/Makefile @@ -442,7 +442,7 @@ stop: test: compile-module start sleep 2 - mvn -Dtest=${SKIP_SSL}${TEST} clean compile test + mvn -Dredisversion=${REDIS_VERSION} -Dtest=${SKIP_SSL}${TEST} clean compile test make stop package: start diff --git a/pom.xml b/pom.xml index f2995791da..85b7e8da15 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,16 @@ gson 2.10.1 - + + org.junit.jupiter + junit-jupiter + 5.9.2 + + + org.junit.platform + junit-platform-launcher + 1.9.2 + junit junit diff --git a/src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java index 4d29392fce..b64c55a568 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java @@ -19,7 +19,9 @@ import java.util.List; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import redis.clients.jedis.versiontag.EnabledOnRedis; +import redis.clients.jedis.versiontag.RedisType; import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.resps.ScanResult; @@ -323,6 +325,7 @@ public void sinter() { } @Test + @EnabledOnRedis({RedisType.REDIS_UNSTABLE, RedisType.REDIS_7}) public void sinterstore() { jedis.sadd("foo", "a"); jedis.sadd("foo", "b"); @@ -356,6 +359,7 @@ public void sinterstore() { } @Test + @EnabledOnRedis({RedisType.REDIS_UNSTABLE, RedisType.REDIS_7}) public void sintercard() { jedis.sadd("foo", "a"); jedis.sadd("foo", "b"); diff --git a/src/test/java/redis/clients/jedis/versiontag/CustomExecutionCondition.java b/src/test/java/redis/clients/jedis/versiontag/CustomExecutionCondition.java new file mode 100644 index 0000000000..e97746bad6 --- /dev/null +++ b/src/test/java/redis/clients/jedis/versiontag/CustomExecutionCondition.java @@ -0,0 +1,46 @@ +package redis.clients.jedis.versiontag; + +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.platform.commons.util.AnnotationUtils; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import static java.lang.System.getenv; + +public class CustomExecutionCondition implements ExecutionCondition { + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + Optional optional = AnnotationUtils.findAnnotation(context.getElement(), + EnabledOnRedis.class); + + if (optional.isPresent()) { + List typeList = Arrays.asList(optional.get().value()); + String type = System.getProperty("redisversion"); + if (type.isEmpty()) type = "REDIS_UNSTABLE"; + + RedisType Redis_type = null; + try { + Redis_type = Enum.valueOf(RedisType.class, type.toUpperCase()); + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + System.out.println("Supported engines are: "); + for (RedisType et : RedisType.values()) { + System.out.println(et.name()); + } + System.exit(1); + } + + if (typeList.contains(Redis_type)) { + return ConditionEvaluationResult.enabled("Test is enabled for engine " + Redis_type.name()); + } else { + return ConditionEvaluationResult.disabled("Test is disabled for engine " + Redis_type.name()); + } + } + return ConditionEvaluationResult.enabled("@EnabledOnEngine is not present"); + } +} diff --git a/src/test/java/redis/clients/jedis/versiontag/EnabledOnRedis.java b/src/test/java/redis/clients/jedis/versiontag/EnabledOnRedis.java new file mode 100644 index 0000000000..1d0689f5ee --- /dev/null +++ b/src/test/java/redis/clients/jedis/versiontag/EnabledOnRedis.java @@ -0,0 +1,15 @@ +package redis.clients.jedis.versiontag; + +import org.junit.jupiter.api.extension.ExtendWith; + +import java.lang.annotation.*; + +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +@Documented +@ExtendWith(CustomExecutionCondition.class) +public @interface EnabledOnRedis { + RedisType[] value(); +} + diff --git a/src/test/java/redis/clients/jedis/versiontag/RedisType.java b/src/test/java/redis/clients/jedis/versiontag/RedisType.java new file mode 100644 index 0000000000..a6b491c3cf --- /dev/null +++ b/src/test/java/redis/clients/jedis/versiontag/RedisType.java @@ -0,0 +1,8 @@ +package redis.clients.jedis.versiontag; + +public enum RedisType { + REDIS_6, + REDIS_7, + REDIS_UNSTABLE +} + From 5c48cd6e50fc4c5fa86fbe215853953770a24338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=9E=E8=B7=83?= Date: Tue, 20 Jun 2023 17:13:23 +0800 Subject: [PATCH 2/4] use junit5 in Test --- .../jedis/commands/jedis/JedisCommandsTestBase.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/redis/clients/jedis/commands/jedis/JedisCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/jedis/JedisCommandsTestBase.java index c69302d3c5..99b2728300 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/JedisCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/JedisCommandsTestBase.java @@ -1,7 +1,7 @@ package redis.clients.jedis.commands.jedis; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.HostAndPort; @@ -19,7 +19,7 @@ public JedisCommandsTestBase() { super(); } - @Before + @BeforeEach public void setUp() throws Exception { // jedis = new Jedis(hnp, DefaultJedisClientConfig.builder().timeoutMillis(500).password("foobared").build()); jedis = new Jedis(hnp, DefaultJedisClientConfig.builder() @@ -27,7 +27,7 @@ public void setUp() throws Exception { jedis.flushAll(); } - @After + @AfterEach public void tearDown() throws Exception { jedis.close(); } From e486fdbb45de71e8140d51ec91c02293aec0e7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=9E=E8=B7=83?= Date: Tue, 20 Jun 2023 17:21:07 +0800 Subject: [PATCH 3/4] A demo of redis version tag proposal --- .../java/redis/clients/jedis/commands/jedis/SetCommandsTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java index b64c55a568..a36f1d0847 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java @@ -285,6 +285,7 @@ public void sismember() { } @Test + @EnabledOnRedis({RedisType.REDIS_UNSTABLE, RedisType.REDIS_7}) public void smismember() { jedis.sadd("foo", "a", "b"); From 47c00aa3dbbb2490a42aba70b57e7360c8b20684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=9E=E8=B7=83?= Date: Tue, 20 Jun 2023 17:31:13 +0800 Subject: [PATCH 4/4] A demo of redis version tag proposal --- .../clients/jedis/versiontag/CustomExecutionCondition.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/redis/clients/jedis/versiontag/CustomExecutionCondition.java b/src/test/java/redis/clients/jedis/versiontag/CustomExecutionCondition.java index e97746bad6..b3b69c8cb4 100644 --- a/src/test/java/redis/clients/jedis/versiontag/CustomExecutionCondition.java +++ b/src/test/java/redis/clients/jedis/versiontag/CustomExecutionCondition.java @@ -21,7 +21,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con if (optional.isPresent()) { List typeList = Arrays.asList(optional.get().value()); String type = System.getProperty("redisversion"); - if (type.isEmpty()) type = "REDIS_UNSTABLE"; + if (type == null || type.isEmpty()) type = "REDIS_UNSTABLE"; RedisType Redis_type = null; try {