Skip to content

Commit

Permalink
Cleanups #430
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Sep 29, 2018
1 parent 36ff55c commit 7e486d9
Show file tree
Hide file tree
Showing 27 changed files with 123 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
Expand All @@ -29,6 +30,7 @@

import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.async.RedisAsyncCommands;
import io.lettuce.test.Delay;
import io.lettuce.test.Futures;
import io.lettuce.test.LettuceExtension;

Expand Down Expand Up @@ -81,7 +83,7 @@ void watch() {
}

@Test
void futureListener() throws Exception {
void futureListener() {

final List<Object> run = new ArrayList<>();

Expand All @@ -106,7 +108,7 @@ void futureListener() throws Exception {
sort.thenRun(listener);

Futures.await(sort);
Thread.sleep(100);
Delay.delay(Duration.ofMillis(100));

assertThat(run).hasSize(1);

Expand Down
21 changes: 11 additions & 10 deletions src/test/java/io/lettuce/core/ClientIntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.lettuce.core.api.async.RedisAsyncCommands;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.resource.ClientResources;
import io.lettuce.test.Delay;
import io.lettuce.test.LettuceExtension;
import io.lettuce.test.Wait;
import io.lettuce.test.resource.FastShutdown;
Expand Down Expand Up @@ -90,18 +91,18 @@ void timeout() {
}

@Test
void reconnect() throws InterruptedException {
void reconnect() {

redis.set(key, value);

redis.quit();
Thread.sleep(100);
Delay.delay(Duration.ofMillis(100));
assertThat(redis.get(key)).isEqualTo(value);
redis.quit();
Thread.sleep(100);
Delay.delay(Duration.ofMillis(100));
assertThat(redis.get(key)).isEqualTo(value);
redis.quit();
Thread.sleep(100);
Delay.delay(Duration.ofMillis(100));
assertThat(redis.get(key)).isEqualTo(value);
}

Expand Down Expand Up @@ -168,7 +169,7 @@ void testExceptionWithCause() {
}

@Test
void reset() throws Exception {
void reset() {

StatefulRedisConnection<String, String> connection = client.connect();
RedisAsyncCommands<String, String> async = connection.async();
Expand All @@ -180,7 +181,7 @@ void reset() throws Exception {

RedisFuture<KeyValue<String, String>> eval = async.blpop(5, key);

Thread.sleep(500);
Delay.delay(Duration.ofMillis(500));

assertThat(eval.isDone()).isFalse();
assertThat(eval.isCancelled()).isFalse();
Expand All @@ -196,7 +197,7 @@ void reset() throws Exception {
}

@Test
void standaloneConnectionShouldSetClientName() throws Exception {
void standaloneConnectionShouldSetClientName() {

RedisURI redisURI = RedisURI.create(host, port);
redisURI.setClientName("my-client");
Expand All @@ -206,7 +207,7 @@ void standaloneConnectionShouldSetClientName() throws Exception {
assertThat(connection.sync().clientGetname()).isEqualTo(redisURI.getClientName());

connection.sync().quit();
Thread.sleep(100);
Delay.delay(Duration.ofMillis(100));
Wait.untilTrue(connection::isOpen).waitOrTimeout();

assertThat(connection.sync().clientGetname()).isEqualTo(redisURI.getClientName());
Expand All @@ -215,7 +216,7 @@ void standaloneConnectionShouldSetClientName() throws Exception {
}

@Test
void pubSubConnectionShouldSetClientName() throws Exception {
void pubSubConnectionShouldSetClientName() {

RedisURI redisURI = RedisURI.create(host, port);
redisURI.setClientName("my-client");
Expand All @@ -225,7 +226,7 @@ void pubSubConnectionShouldSetClientName() throws Exception {
assertThat(connection.sync().clientGetname()).isEqualTo(redisURI.getClientName());

connection.sync().quit();
Thread.sleep(100);
Delay.delay(Duration.ofMillis(100));
Wait.untilTrue(connection::isOpen).waitOrTimeout();

assertThat(connection.sync().clientGetname()).isEqualTo(redisURI.getClientName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void pingBeforeConnectTimeout() throws Exception {

try (ServerSocket serverSocket = new ServerSocket(0)) {

RedisURI redisURI = RedisURI.builder().redis(TestSettings.host(), serverSocket.getLocalPort())
RedisURI redisURI = RedisURI.Builder.redis(TestSettings.host(), serverSocket.getLocalPort())
.withTimeout(500, TimeUnit.MILLISECONDS).build();

try {
Expand Down Expand Up @@ -338,7 +338,7 @@ void pingBeforeConnectWithAuthenticationTimeout() {

try (ServerSocket serverSocket = new ServerSocket(0)) {

RedisURI redisURI = RedisURI.builder().redis(TestSettings.host(), serverSocket.getLocalPort())
RedisURI redisURI = RedisURI.Builder.redis(TestSettings.host(), serverSocket.getLocalPort())
.withPassword(passwd).withTimeout(Duration.ofMillis(500)).build();

try {
Expand Down Expand Up @@ -379,7 +379,7 @@ void pingBeforeConnectWithAuthenticationFails() {
WithPassword.run(client, () -> {

client.setOptions(ClientOptions.builder().pingBeforeActivateConnection(true).build());
RedisURI redisURI = RedisURI.builder().redis(host, port).build();
RedisURI redisURI = RedisURI.Builder.redis(host, port).build();

try {
client.connect(redisURI);
Expand All @@ -398,7 +398,7 @@ void pingBeforeConnectWithSslAndAuthenticationFails() {
() -> {

client.setOptions(ClientOptions.builder().pingBeforeActivateConnection(true).build());
RedisURI redisURI = RedisURI.builder().redis(host, 6443).withVerifyPeer(false).withSsl(true).build();
RedisURI redisURI = RedisURI.Builder.redis(host, 6443).withVerifyPeer(false).withSsl(true).build();

try {
client.connect(redisURI);
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/io/lettuce/core/ConnectionCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;

import java.time.Duration;

import javax.inject.Inject;

import org.junit.jupiter.api.Test;
Expand All @@ -28,6 +30,7 @@
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.async.RedisAsyncCommands;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.test.Delay;
import io.lettuce.test.LettuceExtension;
import io.lettuce.test.Wait;
import io.lettuce.test.WithPassword;
Expand Down Expand Up @@ -108,7 +111,7 @@ void authReconnect() {
assertThat(connection.set(key, value)).isEqualTo("OK");
connection.quit();

Thread.sleep(100);
Delay.delay(Duration.ofMillis(100));
assertThat(connection.get(key)).isEqualTo(value);

connection.getStatefulConnection().close();
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/io/lettuce/core/RedisURIBuilderUnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ void sentinel() {

@Test
void sentinelWithHostShouldFail() {
assertThatThrownBy(() -> RedisURI.builder().sentinel("localhost").withHost("localhost")).isInstanceOf(IllegalStateException. class);
assertThatThrownBy(() -> RedisURI.Builder.sentinel("localhost").withHost("localhost")).isInstanceOf(
IllegalStateException.class);
}

@Test
Expand Down
17 changes: 9 additions & 8 deletions src/test/java/io/lettuce/core/SslIntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.security.cert.CertificateException;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
Expand Down Expand Up @@ -96,7 +97,7 @@ class SslIntegrationTests extends TestSupport {
@BeforeAll
static void beforeClass() {

assumeTrue(Sockets.isOpen(host(), sslPort()), "Assume that stunnel runs on port 6443");
assumeTrue(CanConnect.to(host(), sslPort()), "Assume that stunnel runs on port 6443");
assertThat(TRUSTSTORE_FILE).exists();
}

Expand Down Expand Up @@ -217,11 +218,11 @@ void pingBeforeActivate() {
}

@Test
void regularSslWithReconnect() throws Exception {
void regularSslWithReconnect() {

RedisCommands<String, String> connection = redisClient.connect(URI_NO_VERIFY).sync();
connection.quit();
Thread.sleep(200);
Delay.delay(Duration.ofMillis(200));
assertThat(connection.ping()).isEqualTo("PONG");
connection.getStatefulConnection().close();
}
Expand Down Expand Up @@ -302,11 +303,11 @@ void masterSlavePingBeforeActivate() {
}

@Test
void masterSlaveSslWithReconnect() throws Exception {
void masterSlaveSslWithReconnect() {
RedisCommands<String, String> connection = MasterSlave.connect(redisClient, StringCodec.UTF8,
MASTER_SLAVE_URIS_NO_VERIFY).sync();
connection.quit();
Thread.sleep(200);
Delay.delay(Duration.ofMillis(200));
assertThat(connection.ping()).isEqualTo("PONG");
connection.getStatefulConnection().close();
}
Expand Down Expand Up @@ -343,18 +344,18 @@ void masterSlaveSslWithAllInvalidHostsWillFail() {
}

@Test
void pubSubSsl() throws Exception {
void pubSubSsl() {

RedisPubSubCommands<String, String> connection = redisClient.connectPubSub(URI_NO_VERIFY).sync();
connection.subscribe("c1");
connection.subscribe("c2");
Thread.sleep(200);
Delay.delay(Duration.ofMillis(200));

RedisPubSubCommands<String, String> connection2 = redisClient.connectPubSub(URI_NO_VERIFY).sync();

assertThat(connection2.pubsubChannels()).contains("c1", "c2");
connection.quit();
Thread.sleep(200);
Delay.delay(Duration.ofMillis(200));
Wait.untilTrue(connection::isOpen).waitOrTimeout();
Wait.untilEquals(2, () -> connection2.pubsubChannels().size()).waitOrTimeout();

Expand Down
8 changes: 2 additions & 6 deletions src/test/java/io/lettuce/core/TestSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
import java.util.List;
import java.util.Set;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import io.lettuce.core.internal.LettuceSets;
import io.lettuce.test.settings.TestSettings;

Expand All @@ -32,11 +29,10 @@ public abstract class TestSupport {

public static final String host = TestSettings.hostAddr();
public static final int port = TestSettings.port();
protected static final String passwd = TestSettings.password();
public static final String passwd = TestSettings.password();

protected Logger log = LogManager.getLogger(getClass());
public static final String key = "key";
protected static final String value = "value";
public static final String value = "value";

protected static List<String> list(String... args) {
return Arrays.asList(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @author Mark Paluch
*/
@ExtendWith(LettuceExtension.class)
class ByteCodecClusterTest extends TestSupport {
class ByteCodecClusterIntegrationTests extends TestSupport {

@Test
@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static io.lettuce.core.cluster.ClusterTestUtil.getNodeId;
import static org.assertj.core.api.Assertions.assertThat;

import java.time.Duration;
import java.util.List;

import javax.inject.Inject;
Expand All @@ -37,6 +38,7 @@
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import io.lettuce.core.cluster.models.slots.ClusterSlotRange;
import io.lettuce.core.cluster.models.slots.ClusterSlotsParser;
import io.lettuce.test.Delay;
import io.lettuce.test.Futures;
import io.lettuce.test.LettuceExtension;
import io.lettuce.test.Wait;
Expand Down Expand Up @@ -242,13 +244,13 @@ void clusterSlaves() {
assertThat(result.size()).isGreaterThan(0);
}

private void prepareReadonlyTest(String key) throws InterruptedException {
private void prepareReadonlyTest(String key) {

async.set(key, value);

String resultB = Futures.get(async.get(key));
assertThat(resultB).isEqualTo(value);
Thread.sleep(500); // give some time to replicate
Delay.delay(Duration.ofMillis(500)); // give some time to replicate
}

private static void waitUntilValueIsVisible(String key, RedisCommands<String, String> commands) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public abstract class ClusterTestSettings extends TestSupport {
public static final String KEY_B = "b";
public static final String KEY_D = "d";

/**
* Don't allow instances.
*/
private ClusterTestSettings() {
}

public static int[] createSlots(int from, int to) {
int[] result = new int[to - from];
int counter = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -32,6 +33,7 @@
import org.mockito.quality.Strictness;

import io.lettuce.core.resource.ClientResources;
import io.lettuce.test.Delay;
import io.netty.util.concurrent.EventExecutorGroup;

/**
Expand Down Expand Up @@ -202,7 +204,7 @@ void shouldNotTriggerRefreshOnFirstReconnect() {
}

@Test
void shouldRateLimitAdaptiveRequests() throws Exception {
void shouldRateLimitAdaptiveRequests() {

ClusterTopologyRefreshOptions adaptiveTimeout = ClusterTopologyRefreshOptions.builder().enablePeriodicRefresh(false)
.enableAllAdaptiveRefreshTriggers().adaptiveRefreshTriggersTimeout(50, TimeUnit.MILLISECONDS).build();
Expand All @@ -216,7 +218,7 @@ void shouldRateLimitAdaptiveRequests() throws Exception {
sut.onAskRedirection();
}

Thread.sleep(100);
Delay.delay(Duration.ofMillis(100));
sut.onAskRedirection();

verify(eventExecutors, times(2)).submit(any(Runnable.class));
Expand Down
Loading

0 comments on commit 7e486d9

Please sign in to comment.