Merge branch '2.2.x'

This commit is contained in:
spencergibb
2020-05-22 15:12:48 -04:00
4 changed files with 9 additions and 7 deletions

2
.gitignore vendored
View File

@@ -18,4 +18,4 @@ consul_*.zip
consul_*.zip.*
.vscode/
.flattened-pom.xml
.sdkmanrc

View File

@@ -23,6 +23,7 @@ import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import org.apache.commons.logging.Log;
import org.joda.time.Period;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DurationUnit;
@@ -52,9 +53,10 @@ public class HeartbeatProperties {
@DecimalMax("0.9")
private double intervalRatio = 2.0 / 3.0;
// TODO: did heartbeatInterval need to be a field?
protected Duration computeHearbeatInterval() {
/**
* @return the computed heartbeat interval
*/
protected Duration computeHeartbeatInterval() {
// heartbeat rate at ratio * ttl, but no later than ttl -1s and, (under lesser
// priority), no sooner than 1s from now
double interval = this.ttl.getSeconds() * this.intervalRatio;

View File

@@ -64,7 +64,7 @@ public class TtlScheduler {
public void add(String instanceId) {
ScheduledFuture task = this.scheduler.scheduleAtFixedRate(
new ConsulHeartbeatTask(instanceId),
this.configuration.computeHearbeatInterval().toMillis());
this.configuration.computeHeartbeatInterval().toMillis());
ScheduledFuture previousTask = this.serviceHeartbeats.put(instanceId, task);
if (previousTask != null) {
previousTask.cancel(true);

View File

@@ -31,7 +31,7 @@ public class HeartbeatPropertiesTests {
@Test
public void computeHeartbeatIntervalWorks() {
HeartbeatProperties properties = new HeartbeatProperties();
Duration period = properties.computeHearbeatInterval();
Duration period = properties.computeHeartbeatInterval();
assertThat(period).isNotNull();
assertThat(period.get(ChronoUnit.SECONDS)).isEqualTo(20);
@@ -41,7 +41,7 @@ public class HeartbeatPropertiesTests {
public void computeShortHeartbeat() {
HeartbeatProperties properties = new HeartbeatProperties();
properties.setTtl(Duration.ofSeconds(2));
Duration period = properties.computeHearbeatInterval();
Duration period = properties.computeHeartbeatInterval();
assertThat(period).isNotNull();
assertThat(period.get(ChronoUnit.SECONDS)).isEqualTo(1);