Skip to content

Commit 097d6b0

Browse files
committed
Fix RedisAvailableRule
Prior to this commit, `RedisAvailableRule.apply()` threw an `AssumptionViolatedException` when Redis was unavailable. That caused the execution of the current test class and all pending test methods to be stopped immediately. Instead, it now returns a `Statement` that throws the exception in case Redis us unavailable which will only skip the current test. Resolves #2782.
1 parent 78199dc commit 097d6b0

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

spring-integration-redis/src/test/java/org/springframework/integration/redis/rules/RedisAvailableRule.java

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
3434
* @author Oleg Zhurakousky
3535
* @author Gunnar Hillert
3636
* @author Artem Bilan
37+
* @author Marc Philipp
3738
*/
3839
public final class RedisAvailableRule implements MethodRule {
3940

@@ -69,21 +70,24 @@ public static void cleanUpConnectionFactoryIfAny() {
6970

7071

7172
public Statement apply(final Statement base, final FrameworkMethod method, Object target) {
72-
RedisAvailable redisAvailable = method.getAnnotation(RedisAvailable.class);
73-
if (redisAvailable != null) {
74-
if (connectionFactory != null) {
75-
try {
76-
connectionFactory.getConnection();
77-
}
78-
catch (Exception e) {
79-
Assume.assumeTrue("Skipping test due to Redis not being available on port: " + REDIS_PORT + ": " + e, false);
80-
73+
return new Statement() {
74+
@Override
75+
public void evaluate() throws Throwable {
76+
RedisAvailable redisAvailable = method.getAnnotation(RedisAvailable.class);
77+
if (redisAvailable != null) {
78+
if (connectionFactory != null) {
79+
try {
80+
connectionFactory.getConnection();
81+
base.evaluate();
82+
}
83+
catch (Exception e) {
84+
Assume.assumeTrue("Skipping test due to Redis not being available on port: " + REDIS_PORT + ": " + e, false);
85+
86+
}
87+
}
8188
}
8289
}
83-
}
84-
85-
return base;
90+
};
8691
}
8792

8893
}
89-

0 commit comments

Comments
 (0)