Search in sources :

Example 1 with JedisClientConfiguration

use of org.springframework.data.redis.connection.jedis.JedisClientConfiguration in project spring-integration by spring-projects.

the class RedisAvailableRule method apply.

public Statement apply(final Statement base, final FrameworkMethod method, Object target) {
    RedisAvailable redisAvailable = method.getAnnotation(RedisAvailable.class);
    if (redisAvailable != null) {
        JedisConnectionFactory connectionFactory = null;
        try {
            RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
            redisStandaloneConfiguration.setPort(REDIS_PORT);
            JedisClientConfiguration clientConfiguration = JedisClientConfiguration.builder().connectTimeout(Duration.ofSeconds(20)).readTimeout(Duration.ofSeconds(20)).build();
            connectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration, clientConfiguration);
            connectionFactory.afterPropertiesSet();
            connectionFactory.getConnection();
            connectionFactoryResource.set(connectionFactory);
        } catch (Exception e) {
            if (connectionFactory != null) {
                connectionFactory.destroy();
            }
            return new Statement() {

                @Override
                public void evaluate() throws Throwable {
                    Assume.assumeTrue("Skipping test due to Redis not being available on port: " + REDIS_PORT, false);
                }
            };
        }
        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                try {
                    base.evaluate();
                } finally {
                    JedisConnectionFactory connectionFactory = connectionFactoryResource.get();
                    connectionFactoryResource.remove();
                    if (connectionFactory != null) {
                        connectionFactory.destroy();
                    }
                }
            }
        };
    }
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            base.evaluate();
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) RedisStandaloneConfiguration(org.springframework.data.redis.connection.RedisStandaloneConfiguration) JedisClientConfiguration(org.springframework.data.redis.connection.jedis.JedisClientConfiguration)

Aggregations

Statement (org.junit.runners.model.Statement)1 RedisStandaloneConfiguration (org.springframework.data.redis.connection.RedisStandaloneConfiguration)1 JedisClientConfiguration (org.springframework.data.redis.connection.jedis.JedisClientConfiguration)1 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)1