Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ private ClientOptions.Builder initializeClientOptionsBuilder() {
if (refreshProperties.isAdaptive()) {
refreshBuilder.enableAllAdaptiveRefreshTriggers();
}
if (refreshProperties.isDynamicSources() != null) {
refreshBuilder.dynamicRefreshSources(refreshProperties.isDynamicSources());
}
return builder.topologyRefreshOptions(refreshBuilder.build());
}
return ClientOptions.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,13 @@ public static class Refresh {
*/
private boolean adaptive;

/**
* Whether discovered nodes should be used as the source for the cluster
* topology. When set to {@literal false}, only the initial seed nodes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't use Javadoc tag here as the annotation processor don't handle them.

* will be used as sources for topology discovery.
*/
private Boolean dynamicSources = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null initialization here is unnecessary. The AP will figure out the right default for a wrapper type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so but I noticed it explicitly specified in places like this. I will remove the redundant initialization.


public Duration getPeriod() {
return this.period;
}
Expand All @@ -426,6 +433,14 @@ public void setAdaptive(boolean adaptive) {
this.adaptive = adaptive;
}

public Boolean isDynamicSources() {
return this.dynamicSources;
}

public void setDynamicSources(Boolean dynamicSources) {
this.dynamicSources = dynamicSources;
}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import io.lettuce.core.ClientOptions;
import io.lettuce.core.cluster.ClusterClientOptions;
import io.lettuce.core.cluster.ClusterTopologyRefreshOptions;
import io.lettuce.core.cluster.ClusterTopologyRefreshOptions.RefreshTrigger;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -312,6 +313,36 @@ void testRedisConfigurationWithClusterRefreshPeriodHasNoEffectWithNonClusteredCo
ClientOptions.class, (options) -> assertThat(options.getClass()).isEqualTo(ClientOptions.class)));
}

@Test
void testRedisConfigurationWithClusterDynamicSourcesEnabled() {
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")
.run(assertClientOptions(ClusterClientOptions.class,
(options) -> assertThat(options.getTopologyRefreshOptions().useDynamicRefreshSources())
.isTrue()));
}

@Test
void testRedisConfigurationWithClusterDynamicSourcesDisabled() {
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")
.run(assertClientOptions(ClusterClientOptions.class,
(options) -> assertThat(options.getTopologyRefreshOptions().useDynamicRefreshSources())
.isFalse()));
}

@Test
void testRedisConfigurationWithClusterDynamicSourcesUnspecifiedUsesDefault() {
this.contextRunner
.withPropertyValues("spring.redis.cluster.nodes=127.0.0.1:27379,127.0.0.1:27380",
"spring.redis.lettuce.cluster.refresh.dynamic-sources=")
.run(assertClientOptions(ClusterClientOptions.class,
(options) -> assertThat(options.getTopologyRefreshOptions().useDynamicRefreshSources())
.isEqualTo(ClusterTopologyRefreshOptions.DEFAULT_DYNAMIC_REFRESH_SOURCES)));
}

private <T extends ClientOptions> ContextConsumer<AssertableApplicationContext> assertClientOptions(
Class<T> expectedType, Consumer<T> options) {
return (context) -> {
Expand Down