Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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 @@ -87,6 +87,8 @@ public class ConfigurationWatcherConfigurationProperties {

private Integer actuatorPort = -1;

private ConfigurationWatcherHaProperties ha = new ConfigurationWatcherHaProperties();

public String getActuatorPath() {
return actuatorPath;
}
Expand Down Expand Up @@ -134,6 +136,14 @@ public void setRefreshStrategy(RefreshStrategy refreshStrategy) {
this.refreshStrategy = refreshStrategy;
}

public ConfigurationWatcherHaProperties getHa() {
return ha;
}

public void setHa(ConfigurationWatcherHaProperties ha) {
this.ha = ha;
}

public enum RefreshStrategy {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2013-present 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.cloud.kubernetes.configuration.watcher;

/**
* Properties for watcher HA state persisted in a Lease.
*
* @author wind57
*/
public class ConfigurationWatcherHaProperties {

private boolean enabled;

private String leaseName = "configuration-watcher-ha";

private String leaseNamespace;

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public String getLeaseName() {
return leaseName;
}

public void setLeaseName(String leaseName) {
this.leaseName = leaseName;
}

public String getLeaseNamespace() {
return leaseNamespace;
}

public void setLeaseNamespace(String leaseNamespace) {
this.leaseNamespace = leaseNamespace;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

import org.junit.jupiter.api.Test;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Configuration;

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

/**
Expand All @@ -34,4 +38,38 @@ void setActuatorPath() {
assertThat(properties.getActuatorPath()).isEqualTo("/foo/bar");
}

@Test
void testWithDefaults() {
new ApplicationContextRunner().withUserConfiguration(Config.class).run(context -> {
ConfigurationWatcherConfigurationProperties props = context
.getBean(ConfigurationWatcherConfigurationProperties.class);
assertThat(props).isNotNull();
assertThat(props.getHa().isEnabled()).isFalse();
assertThat(props.getHa().getLeaseName()).isEqualTo("configuration-watcher-ha");
assertThat(props.getHa().getLeaseNamespace()).isNull();
});
}

@Test
void testWithNonDefaults() {
new ApplicationContextRunner().withUserConfiguration(Config.class)
.withPropertyValues("spring.cloud.kubernetes.configuration.watcher.ha.enabled=true",
"spring.cloud.kubernetes.configuration.watcher.ha.lease-name=custom-lease",
"spring.cloud.kubernetes.configuration.watcher.ha.lease-namespace=watcher-namespace")
.run(context -> {
ConfigurationWatcherConfigurationProperties props = context
.getBean(ConfigurationWatcherConfigurationProperties.class);
assertThat(props).isNotNull();
assertThat(props.getHa().isEnabled()).isTrue();
assertThat(props.getHa().getLeaseName()).isEqualTo("custom-lease");
assertThat(props.getHa().getLeaseNamespace()).isEqualTo("watcher-namespace");
});
}

@Configuration
@EnableConfigurationProperties(ConfigurationWatcherConfigurationProperties.class)
static class Config {

}

}
Loading