Polish "Add option to disable Redis Cluster dynamic sources refresh"
See gh-22571
This commit is contained in:
@@ -131,16 +131,14 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
|
||||
if (getProperties().getCluster() != null) {
|
||||
ClusterClientOptions.Builder builder = ClusterClientOptions.builder();
|
||||
Refresh refreshProperties = getProperties().getLettuce().getCluster().getRefresh();
|
||||
Builder refreshBuilder = ClusterTopologyRefreshOptions.builder();
|
||||
Builder refreshBuilder = ClusterTopologyRefreshOptions.builder()
|
||||
.dynamicRefreshSources(refreshProperties.isDynamicRefreshSources());
|
||||
if (refreshProperties.getPeriod() != null) {
|
||||
refreshBuilder.enablePeriodicRefresh(refreshProperties.getPeriod());
|
||||
}
|
||||
if (refreshProperties.isAdaptive()) {
|
||||
refreshBuilder.enableAllAdaptiveRefreshTriggers();
|
||||
}
|
||||
if (refreshProperties.isDynamicSources() != null) {
|
||||
refreshBuilder.dynamicRefreshSources(refreshProperties.isDynamicSources());
|
||||
}
|
||||
return builder.topologyRefreshOptions(refreshBuilder.build());
|
||||
}
|
||||
return ClientOptions.builder();
|
||||
|
||||
@@ -399,6 +399,13 @@ public class RedisProperties {
|
||||
|
||||
public static class Refresh {
|
||||
|
||||
/**
|
||||
* Whether to discover and query all cluster nodes for obtaining the
|
||||
* cluster topology. When set to false, only the initial seed nodes are
|
||||
* used as sources for topology discovery.
|
||||
*/
|
||||
private boolean dynamicRefreshSources = true;
|
||||
|
||||
/**
|
||||
* Cluster topology refresh period.
|
||||
*/
|
||||
@@ -410,12 +417,13 @@ public class RedisProperties {
|
||||
*/
|
||||
private boolean adaptive;
|
||||
|
||||
/**
|
||||
* Whether discovered nodes should be used as the source for the cluster
|
||||
* topology. When set to false, only the initial seed nodes
|
||||
* will be used as sources for topology discovery.
|
||||
*/
|
||||
private Boolean dynamicSources;
|
||||
public boolean isDynamicRefreshSources() {
|
||||
return this.dynamicRefreshSources;
|
||||
}
|
||||
|
||||
public void setDynamicRefreshSources(boolean dynamicRefreshSources) {
|
||||
this.dynamicRefreshSources = dynamicRefreshSources;
|
||||
}
|
||||
|
||||
public Duration getPeriod() {
|
||||
return this.period;
|
||||
@@ -433,14 +441,6 @@ public class RedisProperties {
|
||||
this.adaptive = adaptive;
|
||||
}
|
||||
|
||||
public Boolean isDynamicSources() {
|
||||
return this.dynamicSources;
|
||||
}
|
||||
|
||||
public void setDynamicSources(Boolean dynamicSources) {
|
||||
this.dynamicSources = dynamicSources;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -314,20 +314,20 @@ class RedisAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRedisConfigurationWithClusterDynamicSourcesEnabled() {
|
||||
void testRedisConfigurationWithClusterDynamicRefreshSourcesEnabled() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.redis.cluster.nodes=127.0.0.1:27379,127.0.0.1:27380",
|
||||
"spring.redis.lettuce.cluster.refresh.dynamic-sources=true")
|
||||
"spring.redis.lettuce.cluster.refresh.dynamic-refresh-sources=true")
|
||||
.run(assertClientOptions(ClusterClientOptions.class,
|
||||
(options) -> assertThat(options.getTopologyRefreshOptions().useDynamicRefreshSources())
|
||||
.isTrue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRedisConfigurationWithClusterDynamicSourcesDisabled() {
|
||||
void testRedisConfigurationWithClusterDynamicRefreshSourcesDisabled() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.redis.cluster.nodes=127.0.0.1:27379,127.0.0.1:27380",
|
||||
"spring.redis.lettuce.cluster.refresh.dynamic-sources=false")
|
||||
"spring.redis.lettuce.cluster.refresh.dynamic-refresh-sources=false")
|
||||
.run(assertClientOptions(ClusterClientOptions.class,
|
||||
(options) -> assertThat(options.getTopologyRefreshOptions().useDynamicRefreshSources())
|
||||
.isFalse()));
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2012-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.boot.autoconfigure.data.redis;
|
||||
|
||||
import io.lettuce.core.cluster.ClusterTopologyRefreshOptions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties.Lettuce;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link RedisProperties}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class RedisPropertiesTests {
|
||||
|
||||
@Test
|
||||
void lettuceDefaultsAreConsistent() {
|
||||
Lettuce lettuce = new RedisProperties().getLettuce();
|
||||
ClusterTopologyRefreshOptions defaultClusterTopologyRefreshOptions = ClusterTopologyRefreshOptions.builder()
|
||||
.build();
|
||||
assertThat(lettuce.getCluster().getRefresh().isDynamicRefreshSources())
|
||||
.isEqualTo(defaultClusterTopologyRefreshOptions.useDynamicRefreshSources());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user