Skip to content

Commit 1e2a0f8

Browse files
DATAREDIS-576 - Polishing.
Update Javadoc, apply missing @nullable annotations, add tests and alter makefile to use Redis 4.0.2. Original Pull Request: #285
1 parent 5059887 commit 1e2a0f8

File tree

5 files changed

+44
-20
lines changed

5 files changed

+44
-20
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
REDIS_VERSION:=4.0.1
15+
REDIS_VERSION:=4.0.2
1616
SPRING_PROFILE?=ci
1717

1818
#######

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ public LettuceClientConfigurationBuilder clientOptions(ClientOptions clientOptio
193193
*
194194
* @param clientName must not be {@literal null} or empty.
195195
* @return {@literal this} builder.
196-
* @throws IllegalArgumentException if clientName is {@literal null}.
196+
* @throws IllegalArgumentException if clientName is {@literal null} or empty.
197+
* @since 2.1
197198
*/
198199
public LettuceClientConfigurationBuilder clientName(String clientName) {
199200

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ public void setDatabase(int index) {
589589
/**
590590
* Returns the client name.
591591
*
592-
* @return the client name.
592+
* @return the client name or {@literal null} if not set.
593593
* @since 2.1
594594
*/
595595
@Nullable
@@ -598,23 +598,24 @@ public String getClientName() {
598598
}
599599

600600
/**
601-
* Sets the client name used by this connection factory. Defaults to none which does not set a client name.
601+
* Sets the client name used by this connection factory.
602602
*
603-
* @param clientName the client name.
603+
* @param clientName the client name. Can be {@literal null}.
604604
* @since 2.1
605605
* @deprecated configure the client name using {@link LettuceClientConfiguration}.
606-
* @throws IllegalStateException if {@link JedisClientConfiguration} is immutable.
606+
* @throws IllegalStateException if {@link LettuceClientConfiguration} is immutable.
607607
*/
608608
@Deprecated
609-
public void setClientName(String clientName) {
609+
public void setClientName(@Nullable String clientName) {
610610
this.getMutableConfiguration().setClientName(clientName);
611611
}
612612

613613
/**
614614
* Returns the password used for authenticating with the Redis server.
615615
*
616-
* @return password for authentication.
616+
* @return password for authentication or {@literal null} if not set.
617617
*/
618+
@Nullable
618619
public String getPassword() {
619620
return getRedisPassword().map(String::new).orElse(null);
620621
}
@@ -916,6 +917,7 @@ private long getClientTimeout() {
916917
* Mutable implementation of {@link LettuceClientConfiguration}.
917918
*
918919
* @author Mark Paluch
920+
* @author Christoph Strobl
919921
*/
920922
static class MutableLettuceClientConfiguration implements LettuceClientConfiguration {
921923

@@ -927,7 +929,8 @@ static class MutableLettuceClientConfiguration implements LettuceClientConfigura
927929
private Duration timeout = Duration.ofSeconds(RedisURI.DEFAULT_TIMEOUT);
928930
private Duration shutdownTimeout = Duration.ofMillis(100);
929931

930-
/* (non-Javadoc)
932+
/*
933+
* (non-Javadoc)
931934
* @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#isUseSsl()
932935
*/
933936
@Override
@@ -939,7 +942,8 @@ void setUseSsl(boolean useSsl) {
939942
this.useSsl = useSsl;
940943
}
941944

942-
/* (non-Javadoc)
945+
/*
946+
* (non-Javadoc)
943947
* @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#isVerifyPeer()
944948
*/
945949
@Override
@@ -951,7 +955,8 @@ void setVerifyPeer(boolean verifyPeer) {
951955
this.verifyPeer = verifyPeer;
952956
}
953957

954-
/* (non-Javadoc)
958+
/*
959+
* (non-Javadoc)
955960
* @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#isStartTls()
956961
*/
957962
@Override
@@ -963,7 +968,8 @@ void setStartTls(boolean startTls) {
963968
this.startTls = startTls;
964969
}
965970

966-
/* (non-Javadoc)
971+
/*
972+
* (non-Javadoc)
967973
* @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#getClientResources()
968974
*/
969975
@Override
@@ -975,7 +981,8 @@ void setClientResources(ClientResources clientResources) {
975981
this.clientResources = clientResources;
976982
}
977983

978-
/* (non-Javadoc)
984+
/*
985+
* (non-Javadoc)
979986
* @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#getClientOptions()
980987
*/
981988
@Override
@@ -992,11 +999,16 @@ public Optional<String> getClientName() {
992999
return Optional.ofNullable(clientName);
9931000
}
9941001

995-
void setClientName(String clientName) {
1002+
/**
1003+
* @param clientName can be {@literal null}.
1004+
* @since 2.1
1005+
*/
1006+
void setClientName(@Nullable String clientName) {
9961007
this.clientName = clientName;
9971008
}
9981009

999-
/* (non-Javadoc)
1010+
/*
1011+
* (non-Javadoc)
10001012
* @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#getTimeout()
10011013
*/
10021014
@Override
@@ -1008,7 +1020,8 @@ void setTimeout(Duration timeout) {
10081020
this.timeout = timeout;
10091021
}
10101022

1011-
/* (non-Javadoc)
1023+
/*
1024+
* (non-Javadoc)
10121025
* @see org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration#getShutdownTimeout()
10131026
*/
10141027
@Override

src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfigurationUnitTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,14 @@ public void shouldConfigureAllProperties() {
7373
assertThat(configuration.getCommandTimeout()).isEqualTo(Duration.ofMinutes(5));
7474
assertThat(configuration.getShutdownTimeout()).isEqualTo(Duration.ofHours(2));
7575
}
76+
77+
@Test(expected = IllegalArgumentException.class) // DATAREDIS-576
78+
public void clientConfigurationThrowsExceptionForNullClientName() {
79+
LettuceClientConfiguration.builder().clientName(null);
80+
}
81+
82+
@Test(expected = IllegalArgumentException.class) // DATAREDIS-576
83+
public void clientConfigurationThrowsExceptionForEmptyClientName() {
84+
LettuceClientConfiguration.builder().clientName(" ");
85+
}
7686
}

src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,12 @@ public void connectionAppliesClientName() {
372372
factory.setShareNativeConnection(false);
373373
factory.afterPropertiesSet();
374374

375+
ConnectionFactoryTracker.add(factory);
376+
375377
RedisConnection connection = factory.getConnection();
376378

377379
assertThat(connection.getClientName(), is(equalTo("clientName")));
378380
connection.close();
379-
380-
factory.destroy();
381381
}
382382

383383
@Test // DATAREDIS-576
@@ -388,11 +388,11 @@ public void getClientNameShouldEqualWithFactorySetting() {
388388
factory.setClientName("clientName");
389389
factory.afterPropertiesSet();
390390

391+
ConnectionFactoryTracker.add(factory);
392+
391393
RedisConnection connection = factory.getConnection();
392394
assertThat(connection.getClientName(), equalTo("clientName"));
393395

394396
connection.close();
395-
396-
factory.destroy();
397397
}
398398
}

0 commit comments

Comments
 (0)