Make configuration properties for Pulsar failover more concise
Closes gh-40077
This commit is contained in:
@@ -903,13 +903,13 @@ public class PulsarProperties {
|
||||
/**
|
||||
* Cluster failover policy.
|
||||
*/
|
||||
private FailoverPolicy failoverPolicy = FailoverPolicy.ORDER;
|
||||
private FailoverPolicy policy = FailoverPolicy.ORDER;
|
||||
|
||||
/**
|
||||
* Delay before the Pulsar client switches from the primary cluster to the backup
|
||||
* cluster.
|
||||
*/
|
||||
private Duration failoverDelay;
|
||||
private Duration delay;
|
||||
|
||||
/**
|
||||
* Delay before the Pulsar client switches from the backup cluster to the primary
|
||||
@@ -929,20 +929,20 @@ public class PulsarProperties {
|
||||
*/
|
||||
private List<BackupCluster> backupClusters = new ArrayList<>();
|
||||
|
||||
public FailoverPolicy getFailoverPolicy() {
|
||||
return this.failoverPolicy;
|
||||
public FailoverPolicy getPolicy() {
|
||||
return this.policy;
|
||||
}
|
||||
|
||||
public void setFailoverPolicy(FailoverPolicy failoverPolicy) {
|
||||
this.failoverPolicy = failoverPolicy;
|
||||
public void setPolicy(FailoverPolicy policy) {
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
public Duration getFailoverDelay() {
|
||||
return this.failoverDelay;
|
||||
public Duration getDelay() {
|
||||
return this.delay;
|
||||
}
|
||||
|
||||
public void setFailoverDelay(Duration failoverDelay) {
|
||||
this.failoverDelay = failoverDelay;
|
||||
public void setDelay(Duration delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public Duration getSwitchBackDelay() {
|
||||
|
||||
@@ -82,8 +82,8 @@ final class PulsarPropertiesMapper {
|
||||
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
||||
map.from(connectionDetails::getBrokerUrl).to(autoClusterFailoverBuilder::primary);
|
||||
map.from(secondaryAuths::keySet).as(ArrayList::new).to(autoClusterFailoverBuilder::secondary);
|
||||
map.from(failoverProperties::getFailoverPolicy).to(autoClusterFailoverBuilder::failoverPolicy);
|
||||
map.from(failoverProperties::getFailoverDelay).to(timeoutProperty(autoClusterFailoverBuilder::failoverDelay));
|
||||
map.from(failoverProperties::getPolicy).to(autoClusterFailoverBuilder::failoverPolicy);
|
||||
map.from(failoverProperties::getDelay).to(timeoutProperty(autoClusterFailoverBuilder::failoverDelay));
|
||||
map.from(failoverProperties::getSwitchBackDelay)
|
||||
.to(timeoutProperty(autoClusterFailoverBuilder::switchBackDelay));
|
||||
map.from(failoverProperties::getCheckInterval).to(timeoutProperty(autoClusterFailoverBuilder::checkInterval));
|
||||
|
||||
@@ -2077,7 +2077,7 @@
|
||||
"defaultValue": "bolt://localhost:7687"
|
||||
},
|
||||
{
|
||||
"name": "spring.pulsar.client.failover.failover-policy",
|
||||
"name": "spring.pulsar.client.failover.policy",
|
||||
"defaultValue": "order"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -128,7 +128,7 @@ class PulsarConfigurationTests {
|
||||
PulsarConfigurationTests.this.contextRunner.withBean(PulsarConnectionDetails.class, () -> connectionDetails)
|
||||
.withPropertyValues("spring.pulsar.client.service-url=properties",
|
||||
"spring.pulsar.client.failover.backup-clusters[0].service-url=backup-cluster-1",
|
||||
"spring.pulsar.client.failover.failover-delay=15s",
|
||||
"spring.pulsar.client.failover.delay=15s",
|
||||
"spring.pulsar.client.failover.switch-back-delay=30s",
|
||||
"spring.pulsar.client.failover.check-interval=5s",
|
||||
"spring.pulsar.client.failover.backup-clusters[1].service-url=backup-cluster-2",
|
||||
@@ -144,8 +144,7 @@ class PulsarConfigurationTests {
|
||||
customizeAction.accept(pulsarClientBuilderCustomizer, target);
|
||||
InOrder ordered = inOrder(target);
|
||||
ordered.verify(target).serviceUrlProvider(Mockito.any(AutoClusterFailover.class));
|
||||
assertThat(pulsarProperties.getClient().getFailover().getFailoverDelay())
|
||||
.isEqualTo(Duration.ofSeconds(15));
|
||||
assertThat(pulsarProperties.getClient().getFailover().getDelay()).isEqualTo(Duration.ofSeconds(15));
|
||||
assertThat(pulsarProperties.getClient().getFailover().getSwitchBackDelay())
|
||||
.isEqualTo(Duration.ofSeconds(30));
|
||||
assertThat(pulsarProperties.getClient().getFailover().getCheckInterval())
|
||||
|
||||
@@ -110,9 +110,9 @@ class PulsarPropertiesMapperTests {
|
||||
backupCluster2.setServiceUrl("backup-cluster-2");
|
||||
PulsarProperties properties = new PulsarProperties();
|
||||
properties.getClient().setServiceUrl("https://used.example.com");
|
||||
properties.getClient().getFailover().setFailoverPolicy(FailoverPolicy.ORDER);
|
||||
properties.getClient().getFailover().setPolicy(FailoverPolicy.ORDER);
|
||||
properties.getClient().getFailover().setCheckInterval(Duration.ofSeconds(5));
|
||||
properties.getClient().getFailover().setFailoverDelay(Duration.ofSeconds(30));
|
||||
properties.getClient().getFailover().setDelay(Duration.ofSeconds(30));
|
||||
properties.getClient().getFailover().setSwitchBackDelay(Duration.ofSeconds(30));
|
||||
properties.getClient().getFailover().setBackupClusters(List.of(backupCluster1, backupCluster2));
|
||||
PulsarConnectionDetails connectionDetails = mock(PulsarConnectionDetails.class);
|
||||
|
||||
@@ -90,7 +90,7 @@ class PulsarPropertiesTests {
|
||||
void bindFailover() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("spring.pulsar.client.service-url", "my-service-url");
|
||||
map.put("spring.pulsar.client.failover.failover-delay", "30s");
|
||||
map.put("spring.pulsar.client.failover.delay", "30s");
|
||||
map.put("spring.pulsar.client.failover.switch-back-delay", "15s");
|
||||
map.put("spring.pulsar.client.failover.check-interval", "1s");
|
||||
map.put("spring.pulsar.client.failover.backup-clusters[0].service-url", "backup-service-url-1");
|
||||
@@ -105,7 +105,7 @@ class PulsarPropertiesTests {
|
||||
Failover failoverProperties = properties.getFailover();
|
||||
List<BackupCluster> backupClusters = properties.getFailover().getBackupClusters();
|
||||
assertThat(properties.getServiceUrl()).isEqualTo("my-service-url");
|
||||
assertThat(failoverProperties.getFailoverDelay()).isEqualTo(Duration.ofMillis(30000));
|
||||
assertThat(failoverProperties.getDelay()).isEqualTo(Duration.ofMillis(30000));
|
||||
assertThat(failoverProperties.getSwitchBackDelay()).isEqualTo(Duration.ofMillis(15000));
|
||||
assertThat(failoverProperties.getCheckInterval()).isEqualTo(Duration.ofMillis(1000));
|
||||
assertThat(backupClusters.get(0).getServiceUrl()).isEqualTo("backup-service-url-1");
|
||||
|
||||
Reference in New Issue
Block a user