Search in sources :

Example 1 with LettuceExtension

use of io.lettuce.test.LettuceExtension in project lettuce-core by lettuce-io.

the class EnabledOnCommandCondition method evaluateExecutionCondition.

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    Optional<EnabledOnCommand> optional = AnnotationUtils.findAnnotation(context.getElement(), EnabledOnCommand.class);
    if (optional.isPresent()) {
        String command = optional.get().value();
        StatefulRedisConnection connection = new LettuceExtension().resolve(context, StatefulRedisConnection.class);
        RedisConditions conditions = RedisConditions.of(connection);
        boolean hasCommand = conditions.hasCommand(command);
        return hasCommand ? enabled("Enabled on command " + command) : disabled("Disabled, command " + command + " not available on Redis version " + conditions.getRedisVersion());
    }
    return ENABLED_BY_DEFAULT;
}
Also used : LettuceExtension(io.lettuce.test.LettuceExtension) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection)

Aggregations

StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)1 LettuceExtension (io.lettuce.test.LettuceExtension)1