DATAREDIS-1046 - Polishing.
Guard tests to allow execution against single node instance for quick dev turnaround and replace usage of Optional with null and @Nullable annotations. Original Pull Request: #558
This commit is contained in:
@@ -16,31 +16,32 @@
|
||||
package org.springframework.data.redis.connection.jedis;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Assume;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||
import org.junit.rules.RuleChain;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConnection;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||
import org.springframework.data.redis.test.util.ServerAvailable;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
|
||||
/**
|
||||
* Integration tests for Redis 6 ACL.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@IfProfileValue(name = "redisVersion", value = "6.0+")
|
||||
public class JedisAclIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
assumeTrue(RedisTestProfileValueSource.atLeast("redisVersion", "6.0"));
|
||||
}
|
||||
@ClassRule public static RuleChain requirements = RuleChain.outerRule(ServerAvailable.runningAtLocalhost(6382))
|
||||
.around(new MinimumRedisVersionRule());
|
||||
|
||||
@Test
|
||||
public void shouldConnectWithDefaultAuthentication() {
|
||||
@@ -80,6 +81,9 @@ public class JedisAclIntegrationTests {
|
||||
@Test // DATAREDIS-1145
|
||||
public void shouldConnectSentinelWithAclAuthentication() throws IOException {
|
||||
|
||||
Assume.assumeTrue("Redis Sentinel at localhost:26382 did not answer.",
|
||||
ServerAvailable.runningAtLocalhost(26382).isAvailable());
|
||||
|
||||
// Note: As per https://github.com/redis/redis/issues/7708, Sentinel does not support ACL authentication yet.
|
||||
|
||||
RedisSentinelConfiguration sentinelConfiguration = new RedisSentinelConfiguration("mymaster",
|
||||
|
||||
@@ -22,7 +22,9 @@ import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.test.util.ServerAvailable;
|
||||
|
||||
/**
|
||||
* Integration test of {@link AuthenticatingRedisClient}.
|
||||
@@ -35,6 +37,8 @@ public class AuthenticatingRedisClientTests {
|
||||
|
||||
private RedisClient client;
|
||||
|
||||
@ClassRule public static ServerAvailable serverAvailable = ServerAvailable.runningAtLocalhost(6382);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
client = new AuthenticatingRedisClient("localhost", 6382, "foobared");
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import io.lettuce.core.ClientOptions;
|
||||
import io.lettuce.core.protocol.ProtocolVersion;
|
||||
@@ -24,28 +23,29 @@ import io.lettuce.core.protocol.ProtocolVersion;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Assume;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||
import org.junit.rules.RuleChain;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConnection;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisStaticMasterReplicaConfiguration;
|
||||
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||
import org.springframework.data.redis.test.util.ServerAvailable;
|
||||
|
||||
/**
|
||||
* Integration tests for Redis 6 ACL.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class LettuceAclIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
assumeTrue(RedisTestProfileValueSource.atLeast("redisVersion", "6.0"));
|
||||
}
|
||||
@ClassRule public static RuleChain requirements = RuleChain.outerRule(ServerAvailable.runningAtLocalhost(6382))
|
||||
.around(new MinimumRedisVersionRule());
|
||||
|
||||
@Test // DATAREDIS-1046
|
||||
public void shouldConnectWithDefaultAuthentication() {
|
||||
@@ -87,6 +87,9 @@ public class LettuceAclIntegrationTests {
|
||||
@Test // DATAREDIS-1145
|
||||
public void shouldConnectSentinelWithAuthentication() throws IOException {
|
||||
|
||||
Assume.assumeTrue("Redis Sentinel at localhost:26382 did not answer.",
|
||||
ServerAvailable.runningAtLocalhost(26382).isAvailable());
|
||||
|
||||
// Note: As per https://github.com/redis/redis/issues/7708, Sentinel does not support ACL authentication yet.
|
||||
|
||||
LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.test.util;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
import org.junit.AssumptionViolatedException;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class ServerAvailable implements TestRule {
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
|
||||
ServerAvailable(String host, int port) {
|
||||
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public static ServerAvailable runningAtLocalhost() {
|
||||
return runningAtLocalhost(6379);
|
||||
}
|
||||
|
||||
public static ServerAvailable runningAtLocalhost(int port) {
|
||||
return runningAt("localhost", port);
|
||||
}
|
||||
|
||||
public static ServerAvailable runningAt(String host, int port) {
|
||||
return new ServerAvailable(host, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
|
||||
if (!isAvailable()) {
|
||||
|
||||
throw new AssumptionViolatedException(
|
||||
String.format("Redis Server (%s:%s) did not answer. Is it up and running?", host, port));
|
||||
}
|
||||
|
||||
base.evaluate();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
|
||||
try (Socket socket = new Socket()) {
|
||||
socket.connect(new InetSocketAddress(host, port), 100);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user