Skip to content

Commit

Permalink
Make configuration properties for Pulsar failover more concise
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Mar 22, 2024
1 parent 76bda4b commit 985918b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -903,13 +903,13 @@ public static class Failover {
/**
* 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
Expand All @@ -929,20 +929,20 @@ public static class Failover {
*/
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ private void customizeServiceUrlProviderBuilder(Consumer<String> serviceUrlConsu
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,7 @@
"defaultValue": "bolt://localhost:7687"
},
{
"name": "spring.pulsar.client.failover.failover-policy",
"name": "spring.pulsar.client.failover.policy",
"defaultValue": "order"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void whenHasUserDefinedFailoverPropertiesAddsToClient() {
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",
Expand All @@ -144,8 +144,7 @@ void whenHasUserDefinedFailoverPropertiesAddsToClient() {
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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ void customizeClientBuilderWhenHasFailover() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void bindAuthentication() {
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");
Expand All @@ -105,7 +105,7 @@ void bindFailover() {
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");
Expand Down

0 comments on commit 985918b

Please sign in to comment.