From 1e2a0f858f73b2a91e5dfb34f3f33e3988ac6a27 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Thu, 19 Oct 2017 10:13:14 +0200 Subject: [PATCH] DATAREDIS-576 - Polishing. Update Javadoc, apply missing @Nullable annotations, add tests and alter makefile to use Redis 4.0.2. Original Pull Request: #285 --- Makefile | 2 +- .../lettuce/LettuceClientConfiguration.java | 3 +- .../lettuce/LettuceConnectionFactory.java | 41 ++++++++++++------- .../LettuceClientConfigurationUnitTests.java | 10 +++++ .../LettuceConnectionFactoryTests.java | 8 ++-- 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 3375d487d..728ba1965 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -REDIS_VERSION:=4.0.1 +REDIS_VERSION:=4.0.2 SPRING_PROFILE?=ci ####### diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfiguration.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfiguration.java index c884518ed..12c12121f 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfiguration.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfiguration.java @@ -193,7 +193,8 @@ public interface LettuceClientConfiguration { * * @param clientName must not be {@literal null} or empty. * @return {@literal this} builder. - * @throws IllegalArgumentException if clientName is {@literal null}. + * @throws IllegalArgumentException if clientName is {@literal null} or empty. + * @since 2.1 */ public LettuceClientConfigurationBuilder clientName(String clientName) { diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java index 33a5900a4..ca4535202 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java @@ -589,7 +589,7 @@ public class LettuceConnectionFactory /** * Returns the client name. * - * @return the client name. + * @return the client name or {@literal null} if not set. * @since 2.1 */ @Nullable @@ -598,23 +598,24 @@ public class LettuceConnectionFactory } /** - * Sets the client name used by this connection factory. Defaults to none which does not set a client name. + * Sets the client name used by this connection factory. * - * @param clientName the client name. + * @param clientName the client name. Can be {@literal null}. * @since 2.1 * @deprecated configure the client name using {@link LettuceClientConfiguration}. - * @throws IllegalStateException if {@link JedisClientConfiguration} is immutable. + * @throws IllegalStateException if {@link LettuceClientConfiguration} is immutable. */ @Deprecated - public void setClientName(String clientName) { + public void setClientName(@Nullable String clientName) { this.getMutableConfiguration().setClientName(clientName); } /** * Returns the password used for authenticating with the Redis server. * - * @return password for authentication. + * @return password for authentication or {@literal null} if not set. */ + @Nullable public String getPassword() { return getRedisPassword().map(String::new).orElse(null); } @@ -916,6 +917,7 @@ public class LettuceConnectionFactory * Mutable implementation of {@link LettuceClientConfiguration}. * * @author Mark Paluch + * @author Christoph Strobl */ static class MutableLettuceClientConfiguration implements LettuceClientConfiguration { @@ -927,7 +929,8 @@ public class LettuceConnectionFactory private Duration timeout = Duration.ofSeconds(RedisURI.DEFAULT_TIMEOUT); private Duration shutdownTimeout = Duration.ofMillis(100); - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#isUseSsl() */ @Override @@ -939,7 +942,8 @@ public class LettuceConnectionFactory this.useSsl = useSsl; } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#isVerifyPeer() */ @Override @@ -951,7 +955,8 @@ public class LettuceConnectionFactory this.verifyPeer = verifyPeer; } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#isStartTls() */ @Override @@ -963,7 +968,8 @@ public class LettuceConnectionFactory this.startTls = startTls; } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#getClientResources() */ @Override @@ -975,7 +981,8 @@ public class LettuceConnectionFactory this.clientResources = clientResources; } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#getClientOptions() */ @Override @@ -992,11 +999,16 @@ public class LettuceConnectionFactory return Optional.ofNullable(clientName); } - void setClientName(String clientName) { + /** + * @param clientName can be {@literal null}. + * @since 2.1 + */ + void setClientName(@Nullable String clientName) { this.clientName = clientName; } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#getTimeout() */ @Override @@ -1008,7 +1020,8 @@ public class LettuceConnectionFactory this.timeout = timeout; } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#getShutdownTimeout() */ @Override diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfigurationUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfigurationUnitTests.java index 051a78de2..98e7f55a2 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfigurationUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfigurationUnitTests.java @@ -73,4 +73,14 @@ public class LettuceClientConfigurationUnitTests { assertThat(configuration.getCommandTimeout()).isEqualTo(Duration.ofMinutes(5)); assertThat(configuration.getShutdownTimeout()).isEqualTo(Duration.ofHours(2)); } + + @Test(expected = IllegalArgumentException.class) // DATAREDIS-576 + public void clientConfigurationThrowsExceptionForNullClientName() { + LettuceClientConfiguration.builder().clientName(null); + } + + @Test(expected = IllegalArgumentException.class) // DATAREDIS-576 + public void clientConfigurationThrowsExceptionForEmptyClientName() { + LettuceClientConfiguration.builder().clientName(" "); + } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java index 4215073ec..d0fe1b916 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java @@ -372,12 +372,12 @@ public class LettuceConnectionFactoryTests { factory.setShareNativeConnection(false); factory.afterPropertiesSet(); + ConnectionFactoryTracker.add(factory); + RedisConnection connection = factory.getConnection(); assertThat(connection.getClientName(), is(equalTo("clientName"))); connection.close(); - - factory.destroy(); } @Test // DATAREDIS-576 @@ -388,11 +388,11 @@ public class LettuceConnectionFactoryTests { factory.setClientName("clientName"); factory.afterPropertiesSet(); + ConnectionFactoryTracker.add(factory); + RedisConnection connection = factory.getConnection(); assertThat(connection.getClientName(), equalTo("clientName")); connection.close(); - - factory.destroy(); } }