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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,15 +19,15 @@ 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()
.protocol(RedisProtocolUtil.getRedisProtocol()).timeoutMillis(500).password("foobared").build());
jedis.flushAll();
}

@After
@AfterEach
public void tearDown() throws Exception {
jedis.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -283,6 +285,7 @@ public void sismember() {
}

@Test
@EnabledOnRedis({RedisType.REDIS_UNSTABLE, RedisType.REDIS_7})
public void smismember() {
jedis.sadd("foo", "a", "b");

Expand Down Expand Up @@ -323,6 +326,7 @@ public void sinter() {
}

@Test
@EnabledOnRedis({RedisType.REDIS_UNSTABLE, RedisType.REDIS_7})
public void sinterstore() {
jedis.sadd("foo", "a");
jedis.sadd("foo", "b");
Expand Down Expand Up @@ -356,6 +360,7 @@ public void sinterstore() {
}

@Test
@EnabledOnRedis({RedisType.REDIS_UNSTABLE, RedisType.REDIS_7})
public void sintercard() {
jedis.sadd("foo", "a");
jedis.sadd("foo", "b");
Expand Down
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 == null || 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
}