-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/test/java/redis/clients/jedis/versiontag/CustomExecutionCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
src/test/java/redis/clients/jedis/versiontag/EnabledOnRedis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|