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();
}
};
}
Aggregations