Skip to content
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

A demo of redis version tag proposal #3473

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
A demo of redis version tag proposal
俞跃 committed Jun 20, 2023

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
commit 04b272782417b4412ed52743923a89191fea9833
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -72,7 +72,16 @@
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.2</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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<EnabledOnRedis> optional = AnnotationUtils.findAnnotation(context.getElement(),
EnabledOnRedis.class);

if (optional.isPresent()) {
List<RedisType> 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");
}
}
15 changes: 15 additions & 0 deletions src/test/java/redis/clients/jedis/versiontag/EnabledOnRedis.java
Original file line number Diff line number Diff line change
@@ -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();
}

8 changes: 8 additions & 0 deletions src/test/java/redis/clients/jedis/versiontag/RedisType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package redis.clients.jedis.versiontag;

public enum RedisType {
REDIS_6,
REDIS_7,
REDIS_UNSTABLE
}