Adapt to the latest Spring Data Redis
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,11 +16,15 @@
|
|||||||
|
|
||||||
package org.springframework.integration.redis.rules;
|
package org.springframework.integration.redis.rules;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
import org.junit.rules.MethodRule;
|
import org.junit.rules.MethodRule;
|
||||||
import org.junit.runners.model.FrameworkMethod;
|
import org.junit.runners.model.FrameworkMethod;
|
||||||
import org.junit.runners.model.Statement;
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
|
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||||
|
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
|
||||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,9 +43,15 @@ public final class RedisAvailableRule implements MethodRule {
|
|||||||
if (redisAvailable != null) {
|
if (redisAvailable != null) {
|
||||||
JedisConnectionFactory connectionFactory = null;
|
JedisConnectionFactory connectionFactory = null;
|
||||||
try {
|
try {
|
||||||
connectionFactory = new JedisConnectionFactory();
|
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
|
||||||
connectionFactory.setPort(REDIS_PORT);
|
redisStandaloneConfiguration.setPort(REDIS_PORT);
|
||||||
connectionFactory.setTimeout(10000);
|
|
||||||
|
JedisClientConfiguration clientConfiguration = JedisClientConfiguration.builder()
|
||||||
|
.connectTimeout(Duration.ofSeconds(10))
|
||||||
|
.readTimeout(Duration.ofSeconds(10))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
connectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration, clientConfiguration);
|
||||||
connectionFactory.afterPropertiesSet();
|
connectionFactory.afterPropertiesSet();
|
||||||
connectionFactory.getConnection();
|
connectionFactory.getConnection();
|
||||||
connectionFactoryResource.set(connectionFactory);
|
connectionFactoryResource.set(connectionFactory);
|
||||||
@@ -51,14 +61,17 @@ public final class RedisAvailableRule implements MethodRule {
|
|||||||
connectionFactory.destroy();
|
connectionFactory.destroy();
|
||||||
}
|
}
|
||||||
return new Statement() {
|
return new Statement() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void evaluate() throws Throwable {
|
public void evaluate() throws Throwable {
|
||||||
Assume.assumeTrue("Skipping test due to Redis not being available on port: " + REDIS_PORT, false);
|
Assume.assumeTrue("Skipping test due to Redis not being available on port: " + REDIS_PORT, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Statement() {
|
return new Statement() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void evaluate() throws Throwable {
|
public void evaluate() throws Throwable {
|
||||||
try {
|
try {
|
||||||
@@ -72,14 +85,17 @@ public final class RedisAvailableRule implements MethodRule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Statement() {
|
return new Statement() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void evaluate() throws Throwable {
|
public void evaluate() throws Throwable {
|
||||||
base.evaluate();
|
base.evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user